Merge pull request #190 from ryanpetrello/bug-nested-delete

Fix a bug in DELETE methods in two (or more) nested RestControllers.
This commit is contained in:
Jonathan LaCour
2013-03-19 10:59:15 -07:00
2 changed files with 62 additions and 2 deletions

View File

@@ -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):
'''

View File

@@ -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):