Refs #30512 -- Used subTest() in MailTests.test_sanitize_address.

This commit is contained in:
Joachim Jablon 2019-04-29 18:48:20 +02:00 committed by Mariusz Felisiak
parent 661e6cc2c9
commit f841a776fe
1 changed files with 21 additions and 26 deletions

View File

@ -705,32 +705,27 @@ class MailTests(HeadersCheckMixin, SimpleTestCase):
self.assertEqual(message.get_payload(), encoding.body_encode(body)) self.assertEqual(message.get_payload(), encoding.body_encode(body))
def test_sanitize_address(self): def test_sanitize_address(self):
""" """Email addresses are properly sanitized."""
Email addresses are properly sanitized. for email_address, encoding, expected_result in (
""" # ASCII addresses.
# Simple ASCII address - string form ('to@example.com', 'ascii', 'to@example.com'),
self.assertEqual(sanitize_address('to@example.com', 'ascii'), 'to@example.com') ('to@example.com', 'utf-8', 'to@example.com'),
self.assertEqual(sanitize_address('to@example.com', 'utf-8'), 'to@example.com') (('A name', 'to@example.com'), 'ascii', 'A name <to@example.com>'),
(
# Simple ASCII address - tuple form ('A name', 'to@example.com'),
self.assertEqual( 'utf-8',
sanitize_address(('A name', 'to@example.com'), 'ascii'), '=?utf-8?q?A_name?= <to@example.com>',
'A name <to@example.com>' ),
) # Unicode addresses (supported per RFC-6532).
self.assertEqual( ('tó@example.com', 'utf-8', '=?utf-8?b?dMOz?=@example.com'),
sanitize_address(('A name', 'to@example.com'), 'utf-8'), (
'=?utf-8?q?A_name?= <to@example.com>' ('Tó Example', 'tó@example.com'),
) 'utf-8',
'=?utf-8?q?T=C3=B3_Example?= <=?utf-8?b?dMOz?=@example.com>',
# Unicode characters are are supported in RFC-6532. ),
self.assertEqual( ):
sanitize_address('tó@example.com', 'utf-8'), with self.subTest(email_address=email_address, encoding=encoding):
'=?utf-8?b?dMOz?=@example.com' self.assertEqual(sanitize_address(email_address, encoding), expected_result)
)
self.assertEqual(
sanitize_address(('Tó Example', 'tó@example.com'), 'utf-8'),
'=?utf-8?q?T=C3=B3_Example?= <=?utf-8?b?dMOz?=@example.com>'
)
@requires_tz_support @requires_tz_support