Merge branch 'master' of github.com:pecan/pecan

This commit is contained in:
Mark McClain
2011-09-30 15:02:32 -04:00
2 changed files with 26 additions and 1 deletions

View File

@@ -360,7 +360,7 @@ class Pecan(object):
raise ValidationException()
if json:
params = dict(data=params)
return params
return params or {}
def handle_request(self):
'''

View File

@@ -78,6 +78,31 @@ class TestValidation(object):
)), [('content-type', 'application/json')])
assert r.status_int == 200
assert r.body == 'Success!'
def test_validation_with_none_type(self):
"""
formencode schemas can be configured to return NoneType in some
circumstances. We use the output of formencode's validate() to
determine wildcard arguments, so we should protect ourselves
from this scenario.
"""
class RegistrationSchema(Schema):
if_empty = None
first_name = validators.String(not_empty=True)
last_name = validators.String(not_empty=True)
class RootController(object):
@expose(schema=RegistrationSchema())
def index(self, **kw):
assert 'first_name' not in kw
assert 'last_name' not in kw
return 'Success!'
# test form submissions
app = TestApp(make_app(RootController()))
r = app.post('/', dict())
assert r.status_int == 200
assert r.body == 'Success!'
def test_simple_failure(self):
class RegistrationSchema(Schema):