コード例 #1
0
    def test_total_votes_poll(self):

        #creating a poll object
        p = Question(question_text='Can I vote?', pub_date=timezone.now())
        p.save()
        self.assertEquals(p.total_votes(), 0)

        #searching in database
        all_polls_in_database = Question.objects.all()
        self.assertEquals(all_polls_in_database.count(), 1)
コード例 #2
0
    def test_diferent_number_of_votes_in_question_and_choice(self):

        #creating a poll object
        p = Question(question_text='How are you?', pub_date=timezone.now())
        p.save()

        #creating first choice
        c1 = Choice(question=p, choice_text='Fine', votes=2)
        c1.save()

        #creating second choice
        c2 = Choice(question=p, choice_text='Cool', votes=4)
        c2.save()

        #correct number of choices in question
        number_of_votes = p.total_votes()

        self.assertEquals(number_of_votes, 6)