Resolve a bug in _default handlers used in RestController.

Fixes-bug: 1233258
Change-Id: I5494cf4fc607cdc6833733dc1bf4022daa4c262e
This commit is contained in:
Ryan Petrello
2013-09-30 16:23:18 -04:00
parent 55075fb8cf
commit 8287f6a81b
2 changed files with 18 additions and 1 deletions

View File

@@ -36,7 +36,7 @@ def lookup_controller(obj, remainder):
obj, remainder = find_object(obj, remainder, notfound_handlers)
handle_security(obj)
return obj, remainder
except PecanNotFound:
except (exc.HTTPNotFound, PecanNotFound):
while notfound_handlers:
name, obj, remainder = notfound_handlers.pop()
if name == '_default':

View File

@@ -1057,6 +1057,23 @@ class TestRestController(PecanTestCase):
assert r.status_int == 200
assert r.body == b_('POST-2')
def test_nested_rest_with_default(self):
class FooController(RestController):
@expose()
def _default(self, *remainder):
return "DEFAULT %s" % remainder
class RootController(RestController):
foo = FooController()
app = TestApp(make_app(RootController()))
r = app.get('/foo/missing')
assert r.status_int == 200
assert r.body == b_("DEFAULT missing")
def test_dynamic_rest_lookup(self):
class BarController(RestController):
@expose()