Handle edge cases occuring in tests

pull/83/head
Srijan Choudhary 10 years ago
parent 71024cea70
commit 8fdceeaafb

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

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

Loading…
Cancel
Save