Fix a routing bug for certain _lookup controller configurations.
This commit is contained in:
@@ -46,6 +46,13 @@ def lookup_controller(obj, url_path):
|
||||
# traversal
|
||||
result = handle_lookup_traversal(obj, remainder)
|
||||
if result:
|
||||
# If no arguments are passed to the _lookup, yet the
|
||||
# argspec requires at least one, raise a 404
|
||||
if (
|
||||
remainder == ['']
|
||||
and len(obj._pecan['argspec'].args) > 1
|
||||
):
|
||||
raise
|
||||
return lookup_controller(*result)
|
||||
else:
|
||||
raise exc.HTTPNotFound
|
||||
|
||||
@@ -182,6 +182,35 @@ class TestLookups(PecanTestCase):
|
||||
assert r.status_int == 404
|
||||
|
||||
|
||||
class TestCanonicalLookups(PecanTestCase):
|
||||
|
||||
@property
|
||||
def app_(self):
|
||||
class LookupController(object):
|
||||
def __init__(self, someID):
|
||||
self.someID = someID
|
||||
|
||||
@expose()
|
||||
def index(self):
|
||||
return self.someID
|
||||
|
||||
class UserController(object):
|
||||
@expose()
|
||||
def _lookup(self, someID, *remainder):
|
||||
return LookupController(someID), remainder
|
||||
|
||||
class RootController(object):
|
||||
users = UserController()
|
||||
|
||||
return TestApp(Pecan(RootController()))
|
||||
|
||||
def test_canonical_lookup(self):
|
||||
assert self.app_.get('/users', expect_errors=404).status_int == 404
|
||||
assert self.app_.get('/users/', expect_errors=404).status_int == 404
|
||||
assert self.app_.get('/users/100').status_int == 302
|
||||
assert self.app_.get('/users/100/').body == b_('100')
|
||||
|
||||
|
||||
class TestControllerArguments(PecanTestCase):
|
||||
|
||||
@property
|
||||
|
||||
Reference in New Issue
Block a user