From 11c5995ff803850d41eb93e5bfe7488722b11892 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Thu, 29 Nov 2018 20:05:57 +0100 Subject: Let python decode the message transfer encoding. --- tests/db/test_utils.py | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) (limited to 'tests') diff --git a/tests/db/test_utils.py b/tests/db/test_utils.py index 98a8247c..5622ff4b 100644 --- a/tests/db/test_utils.py +++ b/tests/db/test_utils.py @@ -732,35 +732,21 @@ class TestRemoveCte(unittest.TestCase): with open('tests/static/mail/broken-utf8.eml') as fp: mail = email.message_from_file(fp) # This should not raise an UnicodeDecodeError. - with self.assertLogs(level='DEBUG') as cm: # keep logs - utils.remove_cte(mail, as_string=True) - # We expect no Exceptions but a complaint in the log - logmsg = 'DEBUG:root:Decoding failure: \'utf-8\' codec can\'t decode '\ - 'byte 0xa1 in position 14: invalid start byte' - self.assertIn(logmsg, cm.output) + payload = utils.remove_cte(mail, as_string=True) + expected = '¡This works!\n\\xa1This doesn\'t!\n' + self.assertEqual(payload, expected) def test_malformed_cte_value(self): with open('tests/static/mail/malformed-header-CTE.eml') as fp: mail = email.message_from_file(fp) - with self.assertLogs(level='INFO') as cm: # keep logs - utils.remove_cte(mail, as_string=True) - - # We expect no Exceptions but a complaint in the log - logmsg = 'INFO:root:Unknown Content-Transfer-Encoding: "7bit;"' - self.assertEqual(cm.output, [logmsg]) + payload = utils.remove_cte(mail, as_string=True) def test_unknown_cte_value(self): with open('tests/static/mail/malformed-header-CTE-2.eml') as fp: mail = email.message_from_file(fp) - with self.assertLogs(level='DEBUG') as cm: # keep logs - utils.remove_cte(mail, as_string=True) - - # We expect no Exceptions but a complaint in the log - logmsg = 'DEBUG:root:failed to interpret Content-Transfer-Encoding: '\ - '"normal"' - self.assertIn(logmsg, cm.output) + payload = utils.remove_cte(mail, as_string=True) class Test_ensure_unique_address(unittest.TestCase): -- cgit v1.2.3