diff options
author | markmcclain <mark.mcclain@dreamhost.com> | 2013-08-08 17:11:46 -0700 |
---|---|---|
committer | markmcclain <mark.mcclain@dreamhost.com> | 2013-08-08 17:11:46 -0700 |
commit | bf2a663f211e9392ffe97fb7026946513bbd8133 (patch) | |
tree | 9a9b1a5e5b1a4154dfd5f0ec7865a54ee3c64f38 /pecan | |
parent | 7c8bca787ef870f562d6d05a87ca74564d7676ef (diff) | |
parent | 90721a163f4b4d0f03607bc37fc2155fa60f3865 (diff) | |
download | pecan-bf2a663f211e9392ffe97fb7026946513bbd8133.tar.gz |
Merge pull request #227 from ryanpetrello/routing_lookup_bug
Fix a routing bug for certain _lookup controller configurations.
Diffstat (limited to 'pecan')
-rw-r--r-- | pecan/routing.py | 7 | ||||
-rw-r--r-- | pecan/tests/test_base.py | 29 |
2 files changed, 36 insertions, 0 deletions
diff --git a/pecan/routing.py b/pecan/routing.py index 31cbf92..fc1a7d4 100644 --- a/pecan/routing.py +++ b/pecan/routing.py @@ -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 diff --git a/pecan/tests/test_base.py b/pecan/tests/test_base.py index 37751b7..e5ec6af 100644 --- a/pecan/tests/test_base.py +++ b/pecan/tests/test_base.py @@ -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 |