--- a/.hgignore Mon Jan 30 21:40:46 2012 +0100
+++ b/.hgignore Mon Jan 30 22:15:21 2012 +0100
@@ -4,6 +4,7 @@
*.conf
.*.swp
.*.swo
+.coverage
*orig
*.log
MyIro
--- a/iro/validate.py Mon Jan 30 21:40:46 2012 +0100
+++ b/iro/validate.py Mon Jan 30 22:15:21 2012 +0100
@@ -65,6 +65,7 @@
raise InvalidMail(v,field)
if local == "":
+ ret.append(v)
continue
if local.startswith(".") or local.endswith("."):
raise InvalidMail(v,field)
@@ -82,7 +83,7 @@
unquote = not unquote
c+=1
elif part == '' or part[-1] != "\\":
- if unquote and part != "": #quoted parts must be seperated by a dot
+ if unquote and part != "": #quoted parts must be seperated by a dot
if part[0] != ".":
raise InvalidMail(v,field)
if i < len(parts)-1 and part[-1] != '.':
--- /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;g<h>i[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)
--- a/tests/xmlrpc.py Mon Jan 30 21:40:46 2012 +0100
+++ b/tests/xmlrpc.py Mon Jan 30 22:15:21 2012 +0100
@@ -182,47 +182,22 @@
self.__rpc2().telnumber(['01234']+invalid)
exc = fault.exception
self.failUnlessEqual(exc.faultCode, 701)
- self.failUnlessEqual(exc.faultString, "No valid telnumber: '%s'"%invalid[0])
+ self.failUnlessEqual(exc.faultString, "No valid telnumber: '%s'" % invalid[0])
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',
- '"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(self.__rpc2().email([num]),True)
+ validmails=["niceandsimple@example.com"]
+ self.failUnlessEqual(self.__rpc2().email(validmails),True)
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;g<h>i[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)
- ]
-
- for number in invalid:
- with self.assertRaises(Fault) as fault:
- self.__rpc2().email([number])
- exc = fault.exception
- self.failUnlessEqual(exc.faultCode, 702)
- self.failUnlessEqual(exc.faultString, "No valid email: '%s'"%number)
+ invalid=["Abc.example.com",]
+ with self.assertRaises(Fault) as fault:
+ self.__rpc2().email(invalid)
+ exc = fault.exception
+ self.failUnlessEqual(exc.faultCode, 702)
+ self.failUnlessEqual(exc.faultString, "No valid email: '%s'" % invalid[0])
def testBill(self):
'''test bill function'''