diff options
author | Jenkins <jenkins@review.openstack.org> | 2014-02-19 17:36:31 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2014-02-19 17:36:31 +0000 |
commit | af5db46902721a14bc37d7ff6684fb88fe1dc073 (patch) | |
tree | 110d7991e699dd8dfcaf8544e0e121162a72795b | |
parent | f5ee2e5bb56f1e67b06ed752087d92a3a66b070c (diff) | |
parent | 0e18b1f7d490695f4988d92c83bf239cf2937bf6 (diff) | |
download | pecan-af5db46902721a14bc37d7ff6684fb88fe1dc073.tar.gz |
Merge "Fix a trailing slash bug for `RestController`s that have a `_lookup` method."
-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): |