|
1 import unittest |
|
2 |
|
3 from iro.validate import vEmail |
|
4 from iro.error import InvalidMail |
|
5 |
|
6 |
|
7 class testEmail(unittest.TestCase): |
|
8 """tests for email adresses""" |
|
9 |
|
10 def testVaildEmail(self): |
|
11 '''test vaild email adresses (got from wikipedia)''' |
|
12 validmails=["niceandsimple@example.com", |
|
13 "simplewith+symbol@example.com", |
|
14 'a.little.unusual@example.com', |
|
15 'a.little.more.unusual@dept.example.com', |
|
16 '@[10.10.10.10]', |
|
17 '@[1.1.1.1]', |
|
18 '@[200.100.100.100]', |
|
19 'user@[2001:db8:1ff::a0b:dbd0]', |
|
20 '"much.more\ unusual"@example.com', |
|
21 't."test".t@example.com', |
|
22 '"very.unusual.@.unusual.com"@example.com', |
|
23 '"very.(),:;<>[]\\".VERY.\\"very@\\\ \\"very\\".unusual"@strange.example.com', |
|
24 "!#$%&'*+-/=?^_`{}|~@example.org", |
|
25 '"()<>[]:;@,\\\"!#$%&\'*+-/=?^_`{}| ~ ? ^_`{}|~."@example.org', |
|
26 '""@example.org'] |
|
27 |
|
28 for num in validmails: |
|
29 self.failUnlessEqual(vEmail([num],None),[num]) |
|
30 |
|
31 def testInvaildEmail(self): |
|
32 '''test invaild email adresses (got from wikipedia)''' |
|
33 invalid=["Abc.example.com", # (an @ character must separate the local and domain parts) |
|
34 "Abc.@example.com", # (character dot(.) is last in local part) |
|
35 "Abc..123@example.com", # (character dot(.) is double) |
|
36 "A@b@c@example.com", # (only one @ is allowed outside quotation marks) |
|
37 'a"b(c)d,e:f;g<h>i[j\k]l@example.com', # (none of the special characters in this local part is allowed outside quotation marks) |
|
38 'just"not"right@example.com', # (quoted strings must be dot separated, or the only element making up the local-part) |
|
39 'thisis."notallowed@example.com', # (spaces, quotes, and backslashes may only exist when within quoted strings and preceded by a slash) |
|
40 'this\\ still\\"not\\allowed@example.com', # (even if escaped (preceded by a backslash), spaces, quotes, and backslashes must still be contained by quotes) |
|
41 't."test".t"test".t@example.com', |
|
42 't."test"t."test".t@example.com', |
|
43 ] |
|
44 |
|
45 for number in invalid: |
|
46 with self.assertRaises(InvalidMail) as e: |
|
47 vEmail([number],None) |
|
48 self.failUnlessEqual(e.exception.number, number) |
|
49 |
|
50 def testInvalidDomain(self): |
|
51 '''invalid Domainname''' |
|
52 with self.assertRaises(InvalidMail) as e: |
|
53 vEmail(['x@&.de'],None) |