class TestEmailAddressParser(unittest.TestCase): def setUp(self, *args, **kwargs): self.parser = EmailAddressParser() def test_as_unicode(self): emails = u""" 'Foo Bar' <*****@*****.**> "Foo Baz" <*****@*****.**> """ pairs = self.parser.parse(emails, True) first_pair, second_pair = pairs[0], pairs[1] self.failIf(first_pair.name != u"Foo Bar") self.failIf(first_pair.email != u"*****@*****.**") self.failIf(second_pair.name != u"Foo Baz") self.failIf(second_pair.email != u"*****@*****.**") def test_common_cases(self): emails = """\"Bar, Foo\" <*****@*****.**>, Foo Bar <*****@*****.**>, \"Foo B.\" <*****@*****.**> [email protected], <*****@*****.**>, \"\"[email protected], \"\"<*****@*****.**>""" pairs = self.parser.parse(emails) self.failIf(len(pairs) != 7) for pair in pairs: self.failIf(pair.email != "*****@*****.**") self.failIf(pairs[0].name != "Bar, Foo") self.failIf(pairs[1].name != "Foo Bar") self.failIf(pairs[2].name != "Foo B.") self.failIf(pairs[3].name != "") def test_edge_cases(self): emails = '"Foo Bar"<*****@*****.**>,"Bar Baz"<*****@*****.**>,"Bar Baz"<*****@*****.**>' pairs = self.parser.parse(emails) self.failIf(pairs[0].name != "Foo Bar") self.failIf(pairs[0].email != "*****@*****.**") self.failIf(pairs[1].name != "Bar Baz") self.failIf(pairs[1].email != "*****@*****.**") self.failIf(pairs[2].name != "Bar Baz") self.failIf(pairs[2].email != "*****@*****.**")
def setUp(self, *args, **kwargs): self.parser = EmailAddressParser()