diff options
author | Michael J Gruber <github@grubix.eu> | 2019-09-06 10:52:49 +0200 |
---|---|---|
committer | Patrick Totzke <patricktotzke@gmail.com> | 2019-09-06 19:10:42 +0100 |
commit | 1ce0d130d0a042c8d8c4971efcd7848b35b0148d (patch) | |
tree | e3ad8b89efd322097cca514b38087a56f99358f8 /tests | |
parent | d68617a69c9d8601b919c2db145799d1f5d7edd0 (diff) |
tests: test prefer_text with HTML-only mails
Diffstat (limited to 'tests')
-rw-r--r-- | tests/db/test_utils.py | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/tests/db/test_utils.py b/tests/db/test_utils.py index ac6555c0..59a46435 100644 --- a/tests/db/test_utils.py +++ b/tests/db/test_utils.py @@ -641,7 +641,6 @@ class TestExtractBody(unittest.TestCase): self.assertEqual(actual, expected) def _make_mixed_plain_html(self): - mail = EmailMessage() self._set_basic_headers(mail) mail.set_content('This is an email') @@ -651,7 +650,7 @@ class TestExtractBody(unittest.TestCase): return mail @mock.patch('alot.db.utils.settings.get', mock.Mock(return_value=True)) - def test_prefer_plaintext(self): + def test_prefer_plaintext_mixed(self): expected = 'This is an email\n' mail = self._make_mixed_plain_html() actual = utils.extract_body(mail) @@ -663,19 +662,51 @@ class TestExtractBody(unittest.TestCase): @mock.patch('alot.db.utils.settings.get', mock.Mock(return_value=False)) @mock.patch('alot.db.utils.settings.mailcap_find_match', mock.Mock(return_value=(None, {'view': 'cat'}))) - def test_prefer_html(self): + def test_prefer_html_mixed(self): expected = '<!DOCTYPE html><html><body>This is an html email</body></html>\n' mail = self._make_mixed_plain_html() actual = utils.extract_body(mail) self.assertEqual(actual, expected) + def _make_html_only(self): + mail = EmailMessage() + self._set_basic_headers(mail) + mail.set_content( + '<!DOCTYPE html><html><body>This is an html email</body></html>', + subtype='html') + return mail + + @unittest.expectedFailure + @mock.patch('alot.db.utils.settings.get', mock.Mock(return_value=True)) + @mock.patch('alot.db.utils.settings.mailcap_find_match', + mock.Mock(return_value=(None, {'view': 'cat'}))) + def test_prefer_plaintext_only(self): + expected = '<!DOCTYPE html><html><body>This is an html email</body></html>\n' + mail = self._make_html_only() + actual = utils.extract_body(mail) + + self.assertEqual(actual, expected) + + # Mock the handler to cat, so that no transformations of the html are made + # making the result non-deterministic + @mock.patch('alot.db.utils.settings.get', mock.Mock(return_value=False)) + @mock.patch('alot.db.utils.settings.mailcap_find_match', + mock.Mock(return_value=(None, {'view': 'cat'}))) + def test_prefer_html_only(self): + expected = '<!DOCTYPE html><html><body>This is an html email</body></html>\n' + mail = self._make_html_only() + actual = utils.extract_body(mail) + + self.assertEqual(actual, expected) + def test_simple_utf8_file(self): mail = email.message_from_binary_file( open('tests/static/mail/utf8.eml', 'rb'), _class=email.message.EmailMessage) actual = utils.extract_body(mail) expected = "Liebe Grüße!\n" + self.assertEqual(actual, expected) class TestMessageFromString(unittest.TestCase): |