adds failing tests for json in subcontrollers
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from pecan import make_app, expose, request, response
|
||||
from pecan import make_app, expose, request, response, redirect
|
||||
from webtest import TestApp
|
||||
|
||||
from formencode import validators, Schema
|
||||
@@ -25,6 +25,7 @@ class TestValidation(object):
|
||||
validators.FieldsMatch('password', 'password_confirm')
|
||||
]
|
||||
|
||||
|
||||
class RootController(object):
|
||||
@expose(schema=RegistrationSchema())
|
||||
def index(self, first_name,
|
||||
@@ -44,6 +45,7 @@ class TestValidation(object):
|
||||
assert isinstance(data['age'], int)
|
||||
return 'Success!'
|
||||
|
||||
|
||||
# test form submissions
|
||||
app = TestApp(make_app(RootController()))
|
||||
r = app.post('/', dict(
|
||||
@@ -84,7 +86,28 @@ class TestValidation(object):
|
||||
validators.FieldsMatch('password', 'password_confirm')
|
||||
]
|
||||
|
||||
|
||||
class SubSubRootController(object):
|
||||
@expose('json')
|
||||
def index(self):
|
||||
redirect('/sub/deeper/not_empty', internal=True)
|
||||
|
||||
@expose('json')
|
||||
def not_empty(self, data):
|
||||
return data
|
||||
|
||||
|
||||
class SubRootController(object):
|
||||
@expose('json')
|
||||
def index(self):
|
||||
return '/sub'
|
||||
|
||||
deeper = SubSubRootController()
|
||||
|
||||
class RootController(object):
|
||||
|
||||
sub = SubRootController()
|
||||
|
||||
@expose()
|
||||
def errors(self, *args, **kwargs):
|
||||
assert request.validation_error is not None
|
||||
@@ -122,6 +145,12 @@ class TestValidation(object):
|
||||
assert request.validation_error is not None
|
||||
return 'Success!'
|
||||
|
||||
# post some JSON to a sub controller and fail
|
||||
app = TestApp(make_app(RootController()))
|
||||
resp = app.post('/sub/deeper', dumps({'name':'foobar'}))
|
||||
assert resp.body != {}
|
||||
|
||||
|
||||
|
||||
# test without error handler
|
||||
app = TestApp(make_app(RootController()))
|
||||
@@ -175,4 +204,4 @@ class TestValidation(object):
|
||||
age='31'
|
||||
)), [('content-type', 'application/json')])
|
||||
assert r.status_int == 200
|
||||
assert r.body == 'There was an error!'
|
||||
assert r.body == 'There was an error!'
|
||||
|
||||
Reference in New Issue
Block a user