Permalink
Browse files

safe_validate didn't work with formencode validators

  • Loading branch information...
amol- committed Oct 1, 2015
1 parent 285cb9f commit 3fa88ace7d2028612d37b854a52d40ff9a654b17
Showing with 17 additions and 6 deletions.
  1. +11 −0 tests/test_validation.py
  2. +6 −6 tw2/core/validation.py
@@ -74,6 +74,17 @@ def test_safe_validate_invalid():
r = safe_validate(v, 'x')
assert(r is twc.Invalid)
def test_safe_validate_invalid_formencode():
if not formencode:
if HAS_SKIP:
self.skipTest('formencode is not available')
else:
return # Just pretend like we passed.
v = formencode.validators.Int()
r = safe_validate(v, 'x')
assert(r is twc.Invalid)
def test_unflatten_params_multi_dict():
params = unflatten_params(MultiDict((('asdf:f1', 's1'), ('asdf:f2', 's2'))))
eq_(params, {'asdf': {'f1': 's1', 'f2': 's2'}})
@@ -87,18 +87,18 @@ def message(self):
return self.msg
catch = ValidationError
if formencode:
catch = (catch, formencode.Invalid)
def safe_validate(validator, value, state=None):
try:
return validator.to_python(value, state=state)
except ValidationError:
except catch:
return Invalid
catch = ValidationError
if formencode:
catch = (catch, formencode.Invalid)
def catch_errors(fn):
@functools.wraps(fn)
def wrapper(self, *args, **kw):

0 comments on commit 3fa88ac

Please sign in to comment.