def test_count_vote(self): """test counting votes for a post also test""" u1, u2 = self.test_create_users() p = self.test_create_post() choices = Choice.get_choices_by_post_id(p.post_id) c1, c2 = [choice.choice_id for choice in choices][0], [choice.choice_id for choice in choices][1] v1 = Vote.create(user_id=u1.user_id, choice_id=c1) v2 = Vote.create(user_id=u2.user_id, choice_id=c2) vote_dict, total_votes, doughnut_chart_dict = p.count_votes() self.assertEqual(total_votes, 2) self.assertEqual({c1:1, c2:1}, vote_dict)
def test_create_vote(self): """test the creation of votes and check if it's correctly linked to post""" u1, u2 = self.test_create_users() p = self.test_create_post() choices = Choice.get_choices_by_post_id(p.post_id) c1, c2 = [choice.choice_id for choice in choices][0], [choice.choice_id for choice in choices][1] v1 = Vote.create(user_id=u1.user_id, choice_id=c1) v2 = Vote.create(user_id=u2.user_id, choice_id=c2) self.assertEqual(v1.user_id, u1.user_id) self.assertEqual(v2.choice_id, c2) self.assertIn(u1, p.get_voters()) self.assertIn(u2, p.get_voters()) self.assertEqual([u1, u2], p.get_voters()) self.assertEqual(Vote.get_vote_by_post_and_user_id(p.post_id, u1.user_id), c1) self.assertNotEqual(Vote.get_vote_by_post_and_user_id(p.post_id, u1.user_id), c2)