summaryrefslogtreecommitdiff
path: root/pecan
diff options
context:
space:
mode:
authorRyan Petrello <lists@ryanpetrello.com>2014-09-24 13:54:23 -0400
committerRyan Petrello <lists@ryanpetrello.com>2014-09-24 13:56:39 -0400
commit548ac35e3bc85ce8a872c4ec9adf4e39557187ce (patch)
treed5c9f4d85dc81e7a75a07e621acd67dc70fdf75a /pecan
parentd4c230a2c5f9074bec40df372db18e38529c3dd2 (diff)
downloadpecan-548ac35e3bc85ce8a872c4ec9adf4e39557187ce.tar.gz
When path arguments are incorrect for RestController, return HTTP 404, not 400.
When RestController encounters a mismatch between function signatures and positional URL chunks (e.g., /authors/books vs /authors/1/books), it shouldn't raise an HTTP 400; the issue is a nonexistant URL path, not the structure of the request/body itself. Change-Id: I6637f88b7da4f09497f905ebafa7bf1e3788151a
Diffstat (limited to 'pecan')
-rw-r--r--pecan/rest.py5
-rw-r--r--pecan/tests/test_rest.py17
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):