diff options
-rw-r--r-- | pecan/core.py | 1 | ||||
-rw-r--r-- | pecan/rest.py | 4 | ||||
-rw-r--r-- | pecan/tests/test_base.py | 2 | ||||
-rw-r--r-- | pecan/tests/test_rest.py | 39 |
4 files changed, 45 insertions, 1 deletions
diff --git a/pecan/core.py b/pecan/core.py index 4037a32..b9c88a1 100644 --- a/pecan/core.py +++ b/pecan/core.py @@ -598,3 +598,4 @@ class Pecan(object): del state.request del state.response del state.controller + del state.app diff --git a/pecan/rest.py b/pecan/rest.py index 9fc18ab..4058bd6 100644 --- a/pecan/rest.py +++ b/pecan/rest.py @@ -1,6 +1,7 @@ from inspect import getargspec, ismethod from webob import exc +import six from .core import abort, request from .decorators import expose @@ -63,6 +64,9 @@ 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 diff --git a/pecan/tests/test_base.py b/pecan/tests/test_base.py index 95c09d1..5319013 100644 --- a/pecan/tests/test_base.py +++ b/pecan/tests/test_base.py @@ -972,7 +972,7 @@ class TestThreadLocalState(PecanTestCase): assert r.status_int == 200 assert r.body == b_('/') - assert list(state.__dict__.keys()) == ['app'] + assert state.__dict__ == {} class TestFileTypeExtensions(PecanTestCase): diff --git a/pecan/tests/test_rest.py b/pecan/tests/test_rest.py index 6975fc2..2f5aefa 100644 --- a/pecan/tests/test_rest.py +++ b/pecan/tests/test_rest.py @@ -289,6 +289,45 @@ class TestRestController(PecanTestCase): assert r.status_int == 200 assert r.body == b_(dumps(dict(items=ThingsController.data))) + def test_getall_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): + + data = ['zero', 'one', 'two', 'three'] + + @expose() + def _lookup(self, _id, *remainder): + return LookupController(_id), remainder + + @expose('json') + def get_all(self): + return dict(items=self.data) + + class RootController(object): + things = ThingsController() + + # create the app + app = TestApp(make_app(RootController())) + + # test get_all + for path in ('/things', '/things/'): + r = app.get(path) + assert r.status_int == 200 + assert r.body == b_(dumps(dict(items=ThingsController.data))) + + r = app.get('/things/foo') + assert r.status_int == 200 + assert r.body == b_('ID: foo') + def test_simple_nested_rest(self): class BarController(RestController): |