diff options
author | Ryan Petrello <lists@ryanpetrello.com> | 2013-03-12 14:34:46 -0400 |
---|---|---|
committer | Ryan Petrello <lists@ryanpetrello.com> | 2013-03-12 14:34:46 -0400 |
commit | 1b92443d5c422e344e9bb6b98d9b07da139365f8 (patch) | |
tree | d32cc56b94abbb83cf102fdcbc9d4399afab711b | |
parent | 2c58651b043eb7261487be6bfa40e9d90d896a01 (diff) | |
download | pecan-1b92443d5c422e344e9bb6b98d9b07da139365f8.tar.gz |
Fix a bug in DELETE methods in two (or more) nested RestControllers.
-rw-r--r-- | pecan/decorators.py | 4 | ||||
-rw-r--r-- | pecan/rest.py | 8 | ||||
-rw-r--r-- | pecan/tests/test_hooks.py | 6 | ||||
-rw-r--r-- | pecan/tests/test_rest.py | 56 |
4 files changed, 67 insertions, 7 deletions
diff --git a/pecan/decorators.py b/pecan/decorators.py index 4f73ce5..be27df8 100644 --- a/pecan/decorators.py +++ b/pecan/decorators.py @@ -117,7 +117,7 @@ def after_commit(action): :param action: The callable to call after the commit is successfully issued. ''' - return after_action('commit', action) + return after_action('commit', action) def after_rollback(action): @@ -129,7 +129,7 @@ def after_rollback(action): :param action: The callable to call after the rollback is successfully issued. ''' - return after_action('rollback', action) + return after_action('rollback', action) def accept_noncanonical(func): diff --git a/pecan/rest.py b/pecan/rest.py index 2fda2a3..08b5efb 100644 --- a/pecan/rest.py +++ b/pecan/rest.py @@ -170,6 +170,11 @@ class RestController(object): ''' Routes ``DELETE`` actions to the appropriate controller. ''' + if remainder: + controller = getattr(self, remainder[0], None) + if controller and not ismethod(controller): + return lookup_controller(controller, remainder[1:]) + # check for post_delete/delete requests first controller = self._find_controller('post_delete', 'delete') if controller: @@ -211,7 +216,8 @@ class RestController(object): abort(404) - _handle_put = _handle_post + def _handle_put(self, method, remainder): + return self._handle_post(method, remainder) def _set_routing_args(self, args): ''' diff --git a/pecan/tests/test_hooks.py b/pecan/tests/test_hooks.py index ab0faea..080b802 100644 --- a/pecan/tests/test_hooks.py +++ b/pecan/tests/test_hooks.py @@ -1082,7 +1082,7 @@ class TestRequestViewerHook(TestCase): RootController(), hooks=[ RequestViewerHook( - config={'items':['path']}, writer=_stdout + config={'items': ['path']}, writer=_stdout ) ] ) @@ -1117,7 +1117,7 @@ class TestRequestViewerHook(TestCase): RootController(), hooks=[ RequestViewerHook( - config={'blacklist':['/']}, writer=_stdout + config={'blacklist': ['/']}, writer=_stdout ) ] ) @@ -1144,7 +1144,7 @@ class TestRequestViewerHook(TestCase): RootController(), hooks=[ RequestViewerHook( - config={'items':['date']}, writer=_stdout + config={'items': ['date']}, writer=_stdout ) ] ) diff --git a/pecan/tests/test_rest.py b/pecan/tests/test_rest.py index 4935c00..ec3099e 100644 --- a/pecan/tests/test_rest.py +++ b/pecan/tests/test_rest.py @@ -286,7 +286,61 @@ class TestRestController(TestCase): assert r.status_int == 200 assert r.body == dumps(dict(items=ThingsController.data)) - def test_nested_rest(self): + def test_simple_nested_rest(self): + + class BarController(RestController): + + @expose() + def post(self): + return "BAR-POST" + + @expose() + def delete(self, id_): + return "BAR-%s" % id_ + + @expose() + def post(self): + return "BAR-POST" + + @expose() + def delete(self, id_): + return "BAR-%s" % id_ + + class FooController(RestController): + + bar = BarController() + + @expose() + def post(self): + return "FOO-POST" + + @expose() + def delete(self, id_): + return "FOO-%s" % id_ + + class RootController(object): + foo = FooController() + + # create the app + app = TestApp(make_app(RootController())) + + r = app.post('/foo') + assert r.status_int == 200 + assert r.body == "FOO-POST" + + r = app.delete('/foo/1') + assert r.status_int == 200 + assert r.body == "FOO-1" + + r = app.post('/foo/bar') + assert r.status_int == 200 + assert r.body == "BAR-POST" + + r = app.delete('/foo/bar/2') + assert r.status_int == 200 + assert r.body == "BAR-2" + + def test_complicated_nested_rest(self): class BarsController(RestController): |