From d916b5e42ffd6b5128333321d68365744ca08b1d Mon Sep 17 00:00:00 2001 From: Patrick Totzke Date: Mon, 27 May 2019 19:06:26 +0100 Subject: tests: db.utils.formataddr --- tests/db/test_utils.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'tests') diff --git a/tests/db/test_utils.py b/tests/db/test_utils.py index 6ddc8843..71671e32 100644 --- a/tests/db/test_utils.py +++ b/tests/db/test_utils.py @@ -9,6 +9,7 @@ import email import email.header import email.mime.application import email.policy +import email.utils import io import os import os.path @@ -856,3 +857,27 @@ class TestClearMyAddress(unittest.TestCase): self.assertListEqual(actual, expected) +class TestFormataddr(unittest.TestCase): + + address = u'me@example.com' + umlauts_and_comma = '"Ö, Ä" ' + + def test_is_inverse(self): + self.assertEqual( + utils.formataddr(email.utils.parseaddr(self.umlauts_and_comma)), + self.umlauts_and_comma + ) + + def test_address_only(self): + self.assertEqual(utils.formataddr(("", self.address)), self.address) + + def test_name_and_address_no_comma(self): + self.assertEqual( + utils.formataddr(("Me", self.address)), + "Me " + ) + def test_name_and_address_with_comma(self): + self.assertEqual( + utils.formataddr(("Last, Name", self.address)), + "\"Last, Name\" " + ) -- cgit v1.2.3