From 90721a163f4b4d0f03607bc37fc2155fa60f3865 Mon Sep 17 00:00:00 2001 From: Ryan Petrello Date: Thu, 8 Aug 2013 16:12:36 -0400 Subject: [PATCH] Fix a routing bug for certain _lookup controller configurations. --- pecan/routing.py | 7 +++++++ pecan/tests/test_base.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) 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