summaryrefslogtreecommitdiff
path: root/pecan
diff options
context:
space:
mode:
authorRyan Petrello <lists@ryanpetrello.com>2014-02-13 17:00:52 -0500
committerRyan Petrello <lists@ryanpetrello.com>2014-02-13 17:51:03 -0500
commit573846e01209327030db146909de03e97cd8a858 (patch)
treeee04ba85dcf47f6a51745108fdbf4b30ddb26e6b /pecan
parent1335f2c19dbfff0bd586d4ea6071cedf69b5c36f (diff)
downloadpecan-573846e01209327030db146909de03e97cd8a858.tar.gz
Fix a trailing slash bug for `RestController`s that have a `_lookup` method.
Change-Id: Ibd025fc52d37f58644de23cf283afd8d4d55e2d1 Closes-Bug: #1280003
Diffstat (limited to 'pecan')
-rw-r--r--pecan/rest.py4
-rw-r--r--pecan/tests/test_rest.py39
2 files changed, 43 insertions, 0 deletions
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_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):