return 404 if none found

This commit is contained in:
posativ 2012-10-16 22:56:21 +02:00
parent 5d23bff409
commit 27007547bb
3 changed files with 11 additions and 0 deletions

View File

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

View File

@ -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]

View File

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