Changeset 8638 for main/waeup.kofa/trunk/src/waeup
- Timestamp:
- 6 Jun 2012, 13:58:49 (13 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/interfaces.py
r8486 r8638 113 113 __doc__ = u"Invalid email address" 114 114 115 #: Regular expression to check email-address formats. As these can 116 #: become rather complex (nearly everything is allowed by RFCs), we only 117 #: forbid whitespaces, commas and dots following onto each other. 115 118 check_email = re.compile( 116 r" [a-zA-Z0-9._%\-']+@([a-zA-Z0-9-]+.)*[a-zA-Z]{2,4}").match119 r"^[^@\s,]+@[^@\.\s,]+(\.[^@\.\s,]+)*$").match 117 120 118 121 def validate_email(value): -
main/waeup.kofa/trunk/src/waeup/kofa/tests/test_interfaces.py
r7819 r8638 1 # -*- coding: utf-8 -*- 1 2 ## $Id$ 2 3 ## … … 20 21 import grok 21 22 import unittest 22 from waeup.kofa.interfaces import DuplicationError, RoleSource 23 from waeup.kofa.interfaces import DuplicationError, RoleSource, check_email 23 24 from waeup.kofa.testing import FunctionalLayer, FunctionalTestCase 25 26 class RegExTests(unittest.TestCase): 27 # Let's test regular expressions here 28 29 def check(self, expression, string): 30 if expression.match(string) is not None: 31 return True 32 return False 33 34 def test_check_email_allowed(self): 35 # the RE check_email does moderate format checks, allowing 36 # also strange looking but valid email addresses 37 self.assertTrue(check_email('manfred@domain.com') is not None) 38 self.assertTrue(check_email('bob@localhost') is not None) 39 self.assertTrue(check_email('bob@h5.waeup.org') is not None) 40 self.assertTrue(check_email('bob@idn_with_ümlaut.com') is not None) 41 # also unicodes with umlauts work 42 self.assertTrue(check_email(u'bob@idn_with_ümlaut.com') is not None) 43 self.assertTrue( 44 check_email('bob_the-complex+mbox@my.place') is not None) 45 return 46 47 def test_check_email_forbidden(self): 48 # the RE check_email does moderate format checks, but doesn't 49 # accept everything. 50 # no domain at all 51 self.assertTrue(check_email('bob') is None) 52 self.assertTrue(check_email('bob@') is None) 53 # each domain part must contain at least something 54 self.assertTrue(check_email('bob@h5.waeup.') is None) 55 # whitespaces in addresses 56 self.assertTrue(check_email('spacey @domain.com') is None) 57 self.assertTrue(check_email('tabby\t@domain.com') is None) 58 # two dots next to each other in domain (empty domain part) 59 self.assertTrue(check_email('bob@some..domain') is None) 60 # commas are forbidden 61 self.assertTrue(check_email('bob@foo,alice@bar') is None) 62 return 24 63 25 64 class DuplicationErrorTests(unittest.TestCase):
Note: See TracChangeset for help on using the changeset viewer.