Merge pull request #22 from ryanpetrello/master
Adding some code to protect from unanticipated formencode output.
This commit is contained in:
@@ -356,7 +356,7 @@ class Pecan(object):
|
|||||||
raise ValidationException()
|
raise ValidationException()
|
||||||
if json:
|
if json:
|
||||||
params = dict(data=params)
|
params = dict(data=params)
|
||||||
return params
|
return params or {}
|
||||||
|
|
||||||
def handle_request(self):
|
def handle_request(self):
|
||||||
'''
|
'''
|
||||||
|
|||||||
@@ -78,6 +78,31 @@ class TestValidation(object):
|
|||||||
)), [('content-type', 'application/json')])
|
)), [('content-type', 'application/json')])
|
||||||
assert r.status_int == 200
|
assert r.status_int == 200
|
||||||
assert r.body == 'Success!'
|
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):
|
def test_simple_failure(self):
|
||||||
class RegistrationSchema(Schema):
|
class RegistrationSchema(Schema):
|
||||||
|
|||||||
Reference in New Issue
Block a user