Skip to content

Commit

Permalink
Return 200 with empty array when there are no comments isso-comments#301
Browse files Browse the repository at this point in the history
 (isso-comments#565)

* Return 200 with empty array when there are no comments isso-comments#301
{"id": null, "total_replies": 0, "hidden_replies": 0, "replies": []}
  • Loading branch information
tdro authored and jelmer committed Sep 30, 2019
1 parent 1f77ecc commit f4b0376
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
29 changes: 23 additions & 6 deletions isso/tests/test_comments.py
Expand Up @@ -159,10 +159,18 @@ def verify(comment):

def testGetInvalid(self):

self.assertEqual(self.get('/?uri=%2Fpath%2F&id=123').status_code, 404)
self.assertEqual(self.get('/?uri=%2Fpath%2F&id=123').status_code, 200)
data = loads(self.get('/?uri=%2Fpath%2F&id=123').data)
self.assertEqual(len(data['replies']), 0)

self.assertEqual(
self.get('/?uri=%2Fpath%2Fspam%2F&id=123').status_code, 404)
self.assertEqual(self.get('/?uri=?uri=%foo%2F').status_code, 404)
self.get('/?uri=%2Fpath%2Fspam%2F&id=123').status_code, 200)
data = loads(self.get('/?uri=%2Fpath%2Fspam%2F&id=123').data)
self.assertEqual(len(data['replies']), 0)

self.assertEqual(self.get('/?uri=?uri=%foo%2F').status_code, 200)
data = loads(self.get('/?uri=?uri=%foo%2F').data)
self.assertEqual(len(data['replies']), 0)

def testGetLimited(self):

Expand Down Expand Up @@ -244,9 +252,12 @@ def testDeleteWithReference(self):
self.assertEqual(self.get('/?uri=%2Fpath%2F&id=2').status_code, 200)

r = client.delete('/id/2')
self.assertEqual(self.get('/?uri=%2Fpath%2F').status_code, 404)
self.assertEqual(self.get('/?uri=%2Fpath%2F').status_code, 200)
self.assertNotIn('/path/', self.app.db.threads)

data = loads(client.get('/?uri=%2Fpath%2F').data)
self.assertEqual(len(data['replies']), 0)

def testDeleteWithMultipleReferences(self):
"""
[ comment 1 ]
Expand All @@ -272,7 +283,10 @@ def testDeleteWithMultipleReferences(self):
client.delete('/id/3')
self.assertEqual(self.get('/?uri=%2Fpath%2F').status_code, 200)
client.delete('/id/4')
self.assertEqual(self.get('/?uri=%2Fpath%2F').status_code, 404)
self.assertEqual(self.get('/?uri=%2Fpath%2F').status_code, 200)

data = loads(client.get('/?uri=%2Fpath%2F').data)
self.assertEqual(len(data['replies']), 0)

def testPathVariations(self):

Expand Down Expand Up @@ -465,7 +479,10 @@ def testAddComment(self):
self.assertEqual(rv.status_code, 202)

self.assertEqual(self.client.get('/id/1').status_code, 200)
self.assertEqual(self.client.get('/?uri=test').status_code, 404)
self.assertEqual(self.client.get('/?uri=test').status_code, 200)

data = loads(self.client.get('/?uri=test').data)
self.assertEqual(len(data['replies']), 0)

self.app.db.comments.activate(1)
self.assertEqual(self.client.get('/?uri=test').status_code, 200)
Expand Down
2 changes: 0 additions & 2 deletions isso/views/comments.py
Expand Up @@ -769,8 +769,6 @@ def fetch(self, environ, request, uri):
root_list = []
else:
root_list = list(self.comments.fetch(**args))
if not root_list:
raise NotFound

if root_id not in reply_counts:
reply_counts[root_id] = 0
Expand Down

0 comments on commit f4b0376

Please sign in to comment.