Fixing a RESTController routing bug.

This commit is contained in:
Ryan Petrello
2012-03-11 16:46:57 -07:00
parent 07f49576ec
commit 097e38d55e
2 changed files with 23 additions and 2 deletions

View File

@@ -109,14 +109,14 @@ class RestController(object):
def _handle_get(self, method, remainder):
# route to a get_all or get if no additional parts are available
if not remainder:
if not remainder or remainder == ['']:
controller = self._find_controller('get_all', 'get')
if controller:
return controller, []
abort(404)
# check for new/edit/delete GET requests
method_name = remainder[-1]
# check for new/edit/delete GET requests
if method_name in ('new', 'edit', 'delete'):
if method_name == 'delete':
method_name = 'get_delete'

View File

@@ -260,6 +260,27 @@ class TestRestController(TestCase):
assert r.status_int == 200
assert r.body == 'test'
def test_getall_with_trailing_slash(self):
class ThingsController(RestController):
data = ['zero', 'one', 'two', 'three']
@expose('json')
def get_all(self):
return dict(items=self.data)
class RootController(object):
things = ThingsController()
# create the app
app = TestApp(make_app(RootController()))
# test get_all
r = app.get('/things/')
assert r.status_int == 200
assert r.body == dumps(dict(items=ThingsController.data))
def test_nested_rest(self):
class BarsController(RestController):