summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Petrello <lists@ryanpetrello.com>2014-02-19 10:33:24 -0500
committerRyan Petrello <lists@ryanpetrello.com>2014-02-19 10:35:15 -0500
commit0e18b1f7d490695f4988d92c83bf239cf2937bf6 (patch)
tree46010e9b0230cf1d1009a1fbc0c14d698976f3e3
parente8b2ce56a07fae8c1a83de1457c7e70bd975f41f (diff)
downloadpecan-0e18b1f7d490695f4988d92c83bf239cf2937bf6.tar.gz
Fix a trailing slash bug for `RestController`s that have a `_lookup` method.
Change-Id: Ibefa6742d0411b8cb8ae1592c8b1ca077088c5e6
-rw-r--r--pecan/rest.py6
-rw-r--r--pecan/tests/test_rest.py32
2 files changed, 35 insertions, 3 deletions
diff --git a/pecan/rest.py b/pecan/rest.py
index 4058bd6..881de79 100644
--- a/pecan/rest.py
+++ b/pecan/rest.py
@@ -64,9 +64,6 @@ class RestController(object):
try:
result = handler(method, args)
- # filter empty strings from the arg list
- args = list(six.moves.filter(bool, args))
-
#
# If the signature of the handler does not match the number
# of remaining positional arguments, attempt to handle
@@ -92,6 +89,9 @@ class RestController(object):
return result
def _handle_lookup(self, args):
+ # filter empty strings from the arg list
+ args = list(six.moves.filter(bool, args))
+
# check for lookup controllers
lookup = getattr(self, '_lookup', None)
if args and iscontroller(lookup):
diff --git a/pecan/tests/test_rest.py b/pecan/tests/test_rest.py
index 2f5aefa..ab088f2 100644
--- a/pecan/tests/test_rest.py
+++ b/pecan/tests/test_rest.py
@@ -289,6 +289,38 @@ class TestRestController(PecanTestCase):
assert r.status_int == 200
assert r.body == b_(dumps(dict(items=ThingsController.data)))
+ def test_404_with_lookup(self):
+
+ class LookupController(RestController):
+
+ def __init__(self, _id):
+ self._id = _id
+
+ @expose()
+ def get_all(self):
+ return 'ID: %s' % self._id
+
+ class ThingsController(RestController):
+
+ @expose()
+ def _lookup(self, _id, *remainder):
+ return LookupController(_id), remainder
+
+ class RootController(object):
+ things = ThingsController()
+
+ # create the app
+ app = TestApp(make_app(RootController()))
+
+ # these should 404
+ for path in ('/things', '/things/'):
+ r = app.get(path, expect_errors=True)
+ assert r.status_int == 404
+
+ r = app.get('/things/foo')
+ assert r.status_int == 200
+ assert r.body == b_('ID: foo')
+
def test_getall_with_lookup(self):
class LookupController(RestController):