diff options
-rw-r--r-- | pecan/rest.py | 6 | ||||
-rw-r--r-- | pecan/tests/test_rest.py | 32 |
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): |