diff options
-rw-r--r-- | pecan/rest.py | 5 | ||||
-rw-r--r-- | pecan/tests/test_rest.py | 17 |
2 files changed, 12 insertions, 10 deletions
diff --git a/pecan/rest.py b/pecan/rest.py index a6feae2..48ca1f2 100644 --- a/pecan/rest.py +++ b/pecan/rest.py @@ -54,7 +54,10 @@ class RestController(object): request.pecan.get('routing_args', []) ) if len(remainder) < fixed_args: - abort(400) + # For controllers that are missing intermediate IDs + # (e.g., /authors/books vs /authors/1/books), return a 404 for an + # invalid path. + abort(404) @expose() def _route(self, args, request=None): diff --git a/pecan/tests/test_rest.py b/pecan/tests/test_rest.py index e63c5e7..d839084 100644 --- a/pecan/tests/test_rest.py +++ b/pecan/tests/test_rest.py @@ -727,11 +727,11 @@ class TestRestController(PecanTestCase): assert r.status_int == 200 assert r.body == b_('4') - r = app.get('/foos/bars/', status=400) - assert r.status_int == 400 + r = app.get('/foos/bars/', status=404) + assert r.status_int == 404 - r = app.get('/foos/bars/1', status=400) - assert r.status_int == 400 + r = app.get('/foos/bars/1', status=404) + assert r.status_int == 404 def test_nested_get_all_with_lookup(self): @@ -783,10 +783,9 @@ class TestRestController(PecanTestCase): assert r.status_int == 200 assert r.body == b_('4') - r = app.get('/foos/bars/', status=400) - assert r.status_int == 400 - - r = app.get('/foos/bars/', status=400) + r = app.get('/foos/bars/') + assert r.status_int == 302 + assert r.headers['Location'].endswith('/lookup-hit/') r = app.get('/foos/bars/1') assert r.status_int == 302 @@ -893,7 +892,7 @@ class TestRestController(PecanTestCase): self.assertEqual(r.body, b_(dumps(dict(items=BarsController.data[1])))) r = app.get('/foos/bars', expect_errors=True) - self.assertEqual(r.status_int, 400) + self.assertEqual(r.status_int, 404) def test_custom_with_trailing_slash(self): |