diff options
author | Jonathan LaCour <jonathan@cleverdevil.org> | 2013-03-19 10:59:15 -0700 |
---|---|---|
committer | Jonathan LaCour <jonathan@cleverdevil.org> | 2013-03-19 10:59:15 -0700 |
commit | a689f9ba435f1e662e0d12ca6743e95f490ca9ab (patch) | |
tree | cab01505a8eabaefff79f0e75497553eed2f7078 | |
parent | 7553f19f0af8bd6e41c2f5482945278dc12bc418 (diff) | |
parent | 1b92443d5c422e344e9bb6b98d9b07da139365f8 (diff) | |
download | pecan-a689f9ba435f1e662e0d12ca6743e95f490ca9ab.tar.gz |
Merge pull request #190 from ryanpetrello/bug-nested-delete
Fix a bug in DELETE methods in two (or more) nested RestControllers.
-rw-r--r-- | pecan/rest.py | 8 | ||||
-rw-r--r-- | pecan/tests/test_rest.py | 56 |
2 files changed, 62 insertions, 2 deletions
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_rest.py b/pecan/tests/test_rest.py index 4c84d5d..6cd7bba 100644 --- a/pecan/tests/test_rest.py +++ b/pecan/tests/test_rest.py @@ -287,7 +287,61 @@ class TestRestController(PecanTestCase): 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): |