From 27007547bb46740747b428d4a40df2632ad19def Mon Sep 17 00:00:00 2001 From: posativ Date: Tue, 16 Oct 2012 22:56:21 +0200 Subject: [PATCH] return 404 if none found --- isso/comment.py | 2 ++ isso/db.py | 3 +++ specs/test_comment.py | 6 ++++++ 3 files changed, 11 insertions(+) diff --git a/isso/comment.py b/isso/comment.py index 200fa33..8ea47d9 100644 --- a/isso/comment.py +++ b/isso/comment.py @@ -18,4 +18,6 @@ def create(app, environ, request, path): def get(app, environ, request, path, id=None): rv = list(app.db.retrieve(path)) if id is None else app.db.get(path, id) + if not rv: + abort(404) return Response(json.dumps(rv), 200, content_type='application/json') diff --git a/isso/db.py b/isso/db.py index dcbabe2..5c3b432 100644 --- a/isso/db.py +++ b/isso/db.py @@ -71,6 +71,9 @@ class SQLite(Abstract): return def query2comment(self, query): + if query is None: + return None + return Comment( text=query[4], author=query[5], email=query[6], website=query[7], parent=query[8], mode=query[9], id=query[0], created=query[2], modified=query[3] diff --git a/specs/test_comment.py b/specs/test_comment.py index 713b51b..07b9b39 100644 --- a/specs/test_comment.py +++ b/specs/test_comment.py @@ -57,3 +57,9 @@ class TestComments(unittest.TestCase): rv = json.loads(r.data) assert len(rv) == 20 + + def testGetInvalid(self): + + assert self.get('/comment/path/123').status_code == 404 + assert self.get('/comment/path/spam').status_code == 404 + assert self.get('/comment/foo/').status_code == 404