]> ToastFreeware Gitweb - philipp/winterrodeln/wradmin.git/commitdiff
The AustrianPhoneNumber had a bug: It didn't match all phone numbers correctly.
authorphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Mon, 30 Mar 2009 21:46:37 +0000 (21:46 +0000)
committerphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Mon, 30 Mar 2009 21:46:37 +0000 (21:46 +0000)
git-svn-id: http://www.winterrodeln.org/svn/servermediawiki/trunk/wradmin@440 7aebc617-e5e2-0310-91dc-80fb5f6d2477

wradmin/wradmin/model/validators.py
wradmin/wradmin/tests/test_models.py

index af761646a7a7deb9a8d693c917994c5b4cb3439b..f3f8fa6ba72148c3bf896057966710e613070fb1 100644 (file)
@@ -136,7 +136,7 @@ class AustrianPhoneNumber(formencode.FancyValidator):
 
     def _to_python(self, value, state):
         self.assert_string(value, state)
-        m = re.match(u'(?:\+(\d+)/)?([\d/]+)(?:-(\d+))?', value)
+        m = re.match(u'^(?:\+(\d+)/)?([\d/]+)(?:-(\d+))?$', value)
         # This will separate 
         #     u'+43/512/1234567-89'  => (u'43', u'512/1234567', u'89')
         #     u'+43/512/1234/567-89' => (u'43', u'512/1234/567', u'89')
@@ -146,7 +146,7 @@ class AustrianPhoneNumber(formencode.FancyValidator):
         (country, phone, extension) = m.groups()
         
         # Phone
-        if phone.find(u'//') > -1: raise formencode.Invalid(self.message('phoneFormat', state) % {'value': value}, value, state)
+        if phone.find(u'//') > -1 or phone.count('/') == 0: raise formencode.Invalid(self.message('phoneFormat', state) % {'value': value}, value, state)
         
         # Country
         if country is None:
index d9ec59542574f8ea0b71fdff1d075d10f88cae17..127d89f1632d6afb5efcdcfeb2afab8f645fce40 100644 (file)
@@ -26,7 +26,7 @@ def test_GermanTristate_validator():
     assert v.to_python(None) == (None, None)
     try:
         v.to_python(u'Wrong')
-        assert True, u"The value 'Wrong' must not be accepted by the validator."
+        assert False, u"The value 'Wrong' must not be accepted by the validator."
     except formencode.Invalid: pass
 
     assert v.from_python((True, False)) == u'Ja'
@@ -54,8 +54,8 @@ def test_AustrianPhoneNumber():
     assert v.to_python(u'+43/512/12345678') == u'+43/512/12345678'
     assert v.to_python(u'0512/1234567-89') == u'+43/512/1234567-89'
     assert v.to_python(u'+43/512/1234567-89') == u'+43/512/1234567-89'
-    for n in [u'0512 / 12345678', u'0512-12345678']:
+    for n in [u'0512 / 12345678', u'0512-12345678', u'0049(0)8386/8113']:
         try:
             v.to_python(n) # has to throw an exception
-            assert True, u"The telephone number '%s' should throw an exception." % v
+            assert False, u"The telephone number '%s' should throw an exception." % n
         except formencode.Invalid: pass