More test coverage for validators.py
Fixed a bug in IS_EMAIL throwing exceptions when asked to validate anything other than a string which was problematic for ANY_OF Fixed a bug in ANY_OF.formatter where it was trying to format with a validator that didn't validate
This commit is contained in:
+7
-2
@@ -1200,7 +1200,12 @@ class IS_EMAIL(Validator):
|
||||
self.error_message = error_message
|
||||
|
||||
def __call__(self, value):
|
||||
match = self.regex.match(value)
|
||||
try:
|
||||
match = self.regex.match(value)
|
||||
except TypeError:
|
||||
# Value may not be a string where we can look for matches.
|
||||
# Example: we're calling ANY_OF formatter and IS_EMAIL is asked to validate a date.
|
||||
match = None
|
||||
if match:
|
||||
domain = value.split('@')[1]
|
||||
if (not self.banned or not self.banned.match(domain)) \
|
||||
@@ -2608,7 +2613,7 @@ class ANY_OF(Validator):
|
||||
# Use the formatter of the first subvalidator
|
||||
# that validates the value and has a formatter
|
||||
for validator in self.subs:
|
||||
if hasattr(validator, 'formatter') and validator(value)[1] != None:
|
||||
if hasattr(validator, 'formatter') and validator(value)[1] is None:
|
||||
return validator.formatter(value)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user