diff --git a/isso/tests/test_comments.py b/isso/tests/test_comments.py index 5124743..6ba8ec5 100644 --- a/isso/tests/test_comments.py +++ b/isso/tests/test_comments.py @@ -103,7 +103,7 @@ class TestComments(unittest.TestCase): self.assertEqual(r.status_code, 200) rv = loads(r.data) - self.assertEqual(len(rv), 20) + self.assertEqual(len(rv['replies']), 20) def testCreateInvalidParent(self): diff --git a/isso/views/comments.py b/isso/views/comments.py index 40958d1..608b436 100644 --- a/isso/views/comments.py +++ b/isso/views/comments.py @@ -348,6 +348,8 @@ class API(object): root_list = [i for i in full_list if i['parent'] == root_id] if not root_list: raise NotFound + if root_id not in reply_counts: + reply_counts[root_id] = 0 rv = { 'id' : root_id, @@ -360,8 +362,11 @@ class API(object): for comment in rv['replies']: replies = [i for i in full_list if i['parent'] == comment['id']] comment['passed_replies'] = len(replies) - comment['total_replies'] = reply_counts[comment['id']] - comment['replies'] = self.process_fetched_list(replies, plain) + if comment['id'] in reply_counts: + comment['total_replies'] = reply_counts[comment['id']] + else: + comment['total_replies'] = 0 + comment['replies'] = self.process_fetched_list(replies, plain) return JSON(rv, 200)