diff -r d6704178a18f -r 05e599aa83c3 tests/email.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/email.py Mon Jan 30 22:15:21 2012 +0100 @@ -0,0 +1,53 @@ +import unittest + +from iro.validate import vEmail +from iro.error import InvalidMail + + +class testEmail(unittest.TestCase): + """tests for email adresses""" + + def testVaildEmail(self): + '''test vaild email adresses (got from wikipedia)''' + validmails=["niceandsimple@example.com", + "simplewith+symbol@example.com", + 'a.little.unusual@example.com', + 'a.little.more.unusual@dept.example.com', + '@[10.10.10.10]', + '@[1.1.1.1]', + '@[200.100.100.100]', + 'user@[2001:db8:1ff::a0b:dbd0]', + '"much.more\ unusual"@example.com', + 't."test".t@example.com', + '"very.unusual.@.unusual.com"@example.com', + '"very.(),:;<>[]\\".VERY.\\"very@\\\ \\"very\\".unusual"@strange.example.com', + "!#$%&'*+-/=?^_`{}|~@example.org", + '"()<>[]:;@,\\\"!#$%&\'*+-/=?^_`{}| ~ ? ^_`{}|~."@example.org', + '""@example.org'] + + for num in validmails: + self.failUnlessEqual(vEmail([num],None),[num]) + + def testInvaildEmail(self): + '''test invaild email adresses (got from wikipedia)''' + invalid=["Abc.example.com", # (an @ character must separate the local and domain parts) + "Abc.@example.com", # (character dot(.) is last in local part) + "Abc..123@example.com", # (character dot(.) is double) + "A@b@c@example.com", # (only one @ is allowed outside quotation marks) + 'a"b(c)d,e:f;gi[j\k]l@example.com', # (none of the special characters in this local part is allowed outside quotation marks) + 'just"not"right@example.com', # (quoted strings must be dot separated, or the only element making up the local-part) + 'thisis."notallowed@example.com', # (spaces, quotes, and backslashes may only exist when within quoted strings and preceded by a slash) + 'this\\ still\\"not\\allowed@example.com', # (even if escaped (preceded by a backslash), spaces, quotes, and backslashes must still be contained by quotes) + 't."test".t"test".t@example.com', + 't."test"t."test".t@example.com', + ] + + for number in invalid: + with self.assertRaises(InvalidMail) as e: + vEmail([number],None) + self.failUnlessEqual(e.exception.number, number) + + def testInvalidDomain(self): + '''invalid Domainname''' + with self.assertRaises(InvalidMail) as e: + vEmail(['x@&.de'],None)