def test_get_replies_pagination_sizes(self): """Ensure get_posts works with various pagination sizes""" user1 = create_account('user1', '*****@*****.**', 'Password') post1 = create_post(user1, 'user1', 'Test post') # Create loads of posts for i in xrange(100): create_post(user1, 'user1', 'Test post {}'.format(i), post1) REPLIES_ITEMS_PER_PAGE = app.config.get('REPLIES_ITEMS_PER_PAGE') self.assertEqual(len(get_replies(post1).items), REPLIES_ITEMS_PER_PAGE) self.assertEqual(len(get_replies(post1, per_page=25).items), 25) self.assertEqual(len(get_replies(post1, per_page=50).items), 50) self.assertEqual(len(get_replies(post1, per_page=100).items), 100)
def test_get_replies(self): """Test getting all replies for a post """ # Create two test users user1 = create_account('user1', '*****@*****.**', 'Password') user2 = create_account('user2', '*****@*****.**', 'Password') # Create a post for each user and a comment on each for both user post1 = create_post(user1, 'user1', 'Test post') post2 = create_post(user2, 'user2', 'Test post') # Ensure the comment lists are empty self.assertEqual(len(get_replies(post1).items), 0) self.assertEqual(len(get_replies(post2).items), 0) reply1 = create_post(user1, 'user1', 'Test comment', post1) reply2 = create_post(user1, 'user1', 'Test comment', post2) reply3 = create_post(user2, 'user2', 'Test comment', post1) reply4 = create_post(user2, 'user2', 'Test comment', post2) # Ensure each comment appears in each users list self.assertEqual(len(get_replies(post1).items), 2) self.assertEqual(len(get_replies(post2).items), 2) # Ensure the totals are correct self.assertEqual(get_replies(post1).total, 2) self.assertEqual(get_replies(post2).total, 2) # Ensure comments are in MongoDB comment_ids = \ [doc['_id'] for doc in m.db.posts.find({'reply_to': post1})] self.assertIn(reply1, comment_ids) self.assertIn(reply3, comment_ids) comment_ids = \ [doc['_id'] for doc in m.db.posts.find({'reply_to': post2})] self.assertIn(reply2, comment_ids) self.assertIn(reply4, comment_ids) # Delete 1 comment from post1 and ensure it does not exist delete_post(reply1) # Check that is has gone self.assertEqual(len(get_replies(post1).items), 1) self.assertEqual(get_replies(post1).total, 1)