Handle edge cases occuring in tests
This commit is contained in:
parent
71024cea70
commit
8fdceeaafb
@ -103,7 +103,7 @@ class TestComments(unittest.TestCase):
|
|||||||
self.assertEqual(r.status_code, 200)
|
self.assertEqual(r.status_code, 200)
|
||||||
|
|
||||||
rv = loads(r.data)
|
rv = loads(r.data)
|
||||||
self.assertEqual(len(rv), 20)
|
self.assertEqual(len(rv['replies']), 20)
|
||||||
|
|
||||||
def testCreateInvalidParent(self):
|
def testCreateInvalidParent(self):
|
||||||
|
|
||||||
|
@ -348,6 +348,8 @@ class API(object):
|
|||||||
root_list = [i for i in full_list if i['parent'] == root_id]
|
root_list = [i for i in full_list if i['parent'] == root_id]
|
||||||
if not root_list:
|
if not root_list:
|
||||||
raise NotFound
|
raise NotFound
|
||||||
|
if root_id not in reply_counts:
|
||||||
|
reply_counts[root_id] = 0
|
||||||
|
|
||||||
rv = {
|
rv = {
|
||||||
'id' : root_id,
|
'id' : root_id,
|
||||||
@ -360,7 +362,10 @@ class API(object):
|
|||||||
for comment in rv['replies']:
|
for comment in rv['replies']:
|
||||||
replies = [i for i in full_list if i['parent'] == comment['id']]
|
replies = [i for i in full_list if i['parent'] == comment['id']]
|
||||||
comment['passed_replies'] = len(replies)
|
comment['passed_replies'] = len(replies)
|
||||||
|
if comment['id'] in reply_counts:
|
||||||
comment['total_replies'] = reply_counts[comment['id']]
|
comment['total_replies'] = reply_counts[comment['id']]
|
||||||
|
else:
|
||||||
|
comment['total_replies'] = 0
|
||||||
comment['replies'] = self.process_fetched_list(replies, plain)
|
comment['replies'] = self.process_fetched_list(replies, plain)
|
||||||
|
|
||||||
return JSON(rv, 200)
|
return JSON(rv, 200)
|
||||||
|
Loading…
Reference in New Issue
Block a user