diff test/test_multipart.py @ 5305:e20f472fde7d

issue2550799: provide basic support for handling html only emails Initial implementation and testing with the dehtml html converter done. The use of beautifulsoup 4 is not tested. My test system breaks when running dehtml.py using beautiful soup. I don't get the failures when running under the test harness, but the text output is significantly different (different line breaks, number of newlines etc.) The tests for dehtml need to be generated for beautiful soup and the expected output changed. Since I have a wonky install of beautiful soup, I don't trust my output as the standard to test against. Also since beautiful soup is optional, the test harness needs to skip the beautifulsoup tests if import bs4 fails. Again something outside of my expertise. I deleted the work I had done to implement that. I could not get it working and wanted to get this feature in in some form.
author John Rouillard <rouilj@ieee.org>
date Fri, 13 Oct 2017 21:46:59 -0400
parents 364c54991861
children 91354bf0b683
line wrap: on
line diff
--- a/test/test_multipart.py	Thu Oct 12 22:31:59 2017 -0400
+++ b/test/test_multipart.py	Fri Oct 13 21:46:59 2017 -0400
@@ -37,6 +37,7 @@
              'multipart/mixed': '    boundary="boundary-%(indent)s";\n',
              'multipart/alternative': '    boundary="boundary-%(indent)s";\n',
              'text/plain': '    name="foo.txt"\nfoo\n',
+             'text/html': '    name="bar.html"\n<html><body>bar</body></html>\n',
              'application/pgp-signature': '    name="foo.gpg"\nfoo\n',
              'application/pdf': '    name="foo.pdf"\nfoo\n',
              'message/rfc822': '\nSubject: foo\n\nfoo\n'}
@@ -160,10 +161,13 @@
         self.assert_(p is None)
 
     def TestExtraction(self, spec, expected):
-        self.assertEqual(ExampleMessage(spec).extract_content(), expected)
+        from roundup.dehtml import dehtml
+
+        self.assertEqual(ExampleMessage(spec).extract_content(
+            html2text=dehtml('dhtml').html2text), expected)
 
     def testTextPlain(self):
-        self.TestExtraction('text/plain', ('foo\n', []))
+        self.TestExtraction('text/plain', ('foo\n', [], False))
 
     def testAttachedTextPlain(self):
         self.TestExtraction("""
@@ -171,7 +175,7 @@
     text/plain
     text/plain""",
                   ('foo\n',
-                   [('foo.txt', 'text/plain', 'foo\n')]))
+                   [('foo.txt', 'text/plain', 'foo\n')], False))
 
     def testMultipartMixed(self):
         self.TestExtraction("""
@@ -179,14 +183,34 @@
     text/plain
     application/pdf""",
                   ('foo\n',
-                   [('foo.pdf', 'application/pdf', 'foo\n')]))
+                   [('foo.pdf', 'application/pdf', 'foo\n')], False))
+
+    def testMultipartMixedHtml(self):
+        self.TestExtraction("""
+multipart/mixed
+    text/html
+    application/pdf""",
+                  ('bar\n',
+                   [('bar.html', 'text/html',
+                      '<html><body>bar</body></html>\n'),
+                   ('foo.pdf', 'application/pdf', 'foo\n')], False))
 
     def testMultipartAlternative(self):
         self.TestExtraction("""
 multipart/alternative
     text/plain
     application/pdf
-""", ('foo\n', [('foo.pdf', 'application/pdf', 'foo\n')]))
+        """, ('foo\n', [('foo.pdf', 'application/pdf', 'foo\n')], False))
+
+    def testMultipartAlternativeHtml(self):
+        self.TestExtraction("""
+multipart/alternative
+    text/html
+    application/pdf""",
+                  ('bar\n',
+                   [('bar.html', 'text/html',
+                      '<html><body>bar</body></html>\n'),
+                   ('foo.pdf', 'application/pdf', 'foo\n')], False))
 
     def testDeepMultipartAlternative(self):
         self.TestExtraction("""
@@ -194,13 +218,13 @@
     multipart/alternative
         text/plain
         application/pdf
-""", ('foo\n', [('foo.pdf', 'application/pdf', 'foo\n')]))
+        """, ('foo\n', [('foo.pdf', 'application/pdf', 'foo\n')], False))
 
     def testSignedText(self):
         self.TestExtraction("""
 multipart/signed
     text/plain
-    application/pgp-signature""", ('foo\n', []))
+    application/pgp-signature""", ('foo\n', [], False))
 
     def testSignedAttachments(self):
         self.TestExtraction("""
@@ -210,7 +234,7 @@
         application/pdf
     application/pgp-signature""",
                   ('foo\n',
-                   [('foo.pdf', 'application/pdf', 'foo\n')]))
+                   [('foo.pdf', 'application/pdf', 'foo\n')], False))
 
     def testAttachedSignature(self):
         self.TestExtraction("""
@@ -218,13 +242,13 @@
     text/plain
     application/pgp-signature""",
                   ('foo\n',
-                   [('foo.gpg', 'application/pgp-signature', 'foo\n')]))
+                   [('foo.gpg', 'application/pgp-signature', 'foo\n')], False))
 
     def testMessageRfc822(self):
         self.TestExtraction("""
 multipart/mixed
     message/rfc822""",
                   (None,
-                   [('foo.eml', 'message/rfc822', 'Subject: foo\n\nfoo\n')]))
+                   [('foo.eml', 'message/rfc822', 'Subject: foo\n\nfoo\n')], False))
 
 # vim: set filetype=python ts=4 sw=4 et si

Roundup Issue Tracker: http://roundup-tracker.org/