A few minor tweaks:

* Only require simplejson if we need to.
 * Improve upon parameter validation.
 * Add a redirect utility function.
 * Remove some print statements.
This commit is contained in:
Jonathan LaCour
2010-10-11 08:54:51 -04:00
parent b5bfe60e3e
commit 1bc441876b
6 changed files with 87 additions and 23 deletions

View File

@@ -1,4 +1,4 @@
from pecan import Pecan, expose, request, response
from pecan import Pecan, expose, request, response, redirect
from webtest import TestApp
class TestBase(object):
@@ -160,4 +160,36 @@ class TestEngines(object):
r = app.get('/')
assert r.status_int == 200
result = dict(loads(r.body))
assert result == expected_result
assert result == expected_result
def test_controller_parameters(self):
class RootController(object):
@expose('json')
def index(self, argument=None):
assert argument == 'value'
# arguments should get passed appropriately
app = TestApp(Pecan(RootController()))
r = app.get('/?argument=value')
assert r.status_int == 200
# extra arguments get stripped off
r = app.get('/?argument=value&extra=not')
assert r.status_int == 200
def test_redirect(self):
class RootController(object):
@expose()
def index(self):
redirect('/testing')
@expose()
def testing(self):
return 'it worked!'
app = TestApp(Pecan(RootController()))
r = app.get('/')
assert r.status_int == 302
r = r.follow()
assert r.status_int == 200
assert r.body == 'it worked!'