Merge "Fix a trailing slash bug for RestControllers that have a _lookup method."

This commit is contained in:
Jenkins
2014-02-19 17:36:31 +00:00
committed by Gerrit Code Review
2 changed files with 35 additions and 3 deletions

View File

@@ -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):

View File

@@ -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):