Ejemplo n.º 1
0
 def test_has_winners_multiple_winning_choices(self):
     """If the poll has many winners, has_winners returns all of them."""
     winner_1 = ChoiceFactory(poll = self.poll)
     winner_1.vote_me()
     winner_1.vote_me()
     winner_2 = ChoiceFactory(poll = self.poll)
     winner_2.vote_me()
     winner_2.vote_me()
     looser = ChoiceFactory(poll = self.poll)
     looser.vote_me()
     self.assertItemsEqual(self.poll.has_winners(), [winner_2, winner_1])
Ejemplo n.º 2
0
 def test_has_winners_only_one_winning_choice(self):
     """If the poll has a single winner, has_winners returns it."""
     c_max = ChoiceFactory(poll = self.poll, choice = "A winner choice")
     c_max.vote_me()
     c_max.vote_me()
     c_med = ChoiceFactory(poll = self.poll, choice = "A choice")
     c_med.vote_me()
     self.assertItemsEqual(self.poll.has_winners(), [c_max])
Ejemplo n.º 3
0
class ChoiceModelTesting(TestCase):
    def setUp(self):
        self.choice = ChoiceFactory()

    def test_vote_me_adds_1_vote(self):
        """The Choice.vote_me method adds exactly 1 to the votes of the instance."""
        assert(self.choice.votes == 0)
        self.choice.vote_me()
        self.assertEqual(self.choice.votes, 1)
        self.choice.delete()

    def test_vote_me_saves_results(self):
        """The Choice.vote_me method updates the DB (not only the object instance)"""
        assert(self.choice.votes == 0)
        self.choice.vote_me()
        pk = self.choice.pk
        del(self.choice) # Obj removed just to be extreme and show the votes value comes from the DB.
        self.assertEqual(Choice.objects.get(pk=pk).votes, 1)

    def test_vote_me_work_only_on_DB_saved_instances(self):
        """The Choice.vote_me method works only on saved objects."""
        c = Choice()
        self.assertRaises(IntegrityError, c.vote_me)
Ejemplo n.º 4
0
 def setUp(self):
     self.choice = ChoiceFactory()
Ejemplo n.º 5
0
    def test_get_max_votes_nominal(self):
        """get_max_votes returns the number of votes of the most voted choice."""
        c_max = ChoiceFactory(poll = self.poll, choice = "A winner choice")
        c_max.vote_me()
        c_max.vote_me()
        c_max.vote_me()

        c_med = ChoiceFactory(poll = self.poll, choice = "A choice")
        c_med.vote_me()
        c_med.vote_me()

        c_min = ChoiceFactory(poll = self.poll, choice = "A looser choice")
        c_min.vote_me()

        self.assertEqual(self.poll.get_max_votes(), 3)