def test_top_users(self): user1 = User('user1', 'pw') user2 = User('user2', 'pw') user3 = User('user3', 'pw') community = Community('PL', None, user1, None, None) db.session.add_all([user1, user2, user3, community]) db.session.commit() community.users.append(user1) community.users.append(user2) community.users.append(user3) db.session.commit() #user3 will have 2 posts, user1 will have 1, and user2 will have 0 post1 = Posts('Title', 'Body', author=user3, community=community) post2 = Posts('Title', 'Body', author=user3, community=community) post3 = Posts('Title', 'Body', author=user1, community=community) db.session.add_all([post1, post2, post3]) db.session.commit() self.assertEqual(community.find_top_users(), [user3, user1, user2] )