From f841a776feb2b0522c7a919f7355002b8762731a Mon Sep 17 00:00:00 2001 From: Joachim Jablon Date: Mon, 29 Apr 2019 18:48:20 +0200 Subject: [PATCH] Refs #30512 -- Used subTest() in MailTests.test_sanitize_address. --- tests/mail/tests.py | 47 ++++++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/tests/mail/tests.py b/tests/mail/tests.py index 9d8d21c3e7..ed1af26953 100644 --- a/tests/mail/tests.py +++ b/tests/mail/tests.py @@ -705,32 +705,27 @@ class MailTests(HeadersCheckMixin, SimpleTestCase): self.assertEqual(message.get_payload(), encoding.body_encode(body)) def test_sanitize_address(self): - """ - Email addresses are properly sanitized. - """ - # Simple ASCII address - string form - self.assertEqual(sanitize_address('to@example.com', 'ascii'), 'to@example.com') - self.assertEqual(sanitize_address('to@example.com', 'utf-8'), 'to@example.com') - - # Simple ASCII address - tuple form - self.assertEqual( - sanitize_address(('A name', 'to@example.com'), 'ascii'), - 'A name ' - ) - self.assertEqual( - sanitize_address(('A name', 'to@example.com'), 'utf-8'), - '=?utf-8?q?A_name?= ' - ) - - # Unicode characters are are supported in RFC-6532. - self.assertEqual( - sanitize_address('tó@example.com', 'utf-8'), - '=?utf-8?b?dMOz?=@example.com' - ) - self.assertEqual( - sanitize_address(('Tó Example', 'tó@example.com'), 'utf-8'), - '=?utf-8?q?T=C3=B3_Example?= <=?utf-8?b?dMOz?=@example.com>' - ) + """Email addresses are properly sanitized.""" + for email_address, encoding, expected_result in ( + # ASCII addresses. + ('to@example.com', 'ascii', 'to@example.com'), + ('to@example.com', 'utf-8', 'to@example.com'), + (('A name', 'to@example.com'), 'ascii', 'A name '), + ( + ('A name', 'to@example.com'), + 'utf-8', + '=?utf-8?q?A_name?= ', + ), + # Unicode addresses (supported per RFC-6532). + ('tó@example.com', 'utf-8', '=?utf-8?b?dMOz?=@example.com'), + ( + ('Tó Example', 'tó@example.com'), + 'utf-8', + '=?utf-8?q?T=C3=B3_Example?= <=?utf-8?b?dMOz?=@example.com>', + ), + ): + with self.subTest(email_address=email_address, encoding=encoding): + self.assertEqual(sanitize_address(email_address, encoding), expected_result) @requires_tz_support