Exemple #1
0
    def test_get_clasified_answered_and_questions_num(self):
        ranking_view = RankingMixin()
        ranking_view.candidate_queryset = self.election.candidates.all()

        clasified = ranking_view.get_clasified()

        self.assertEquals(clasified[0]['id'], self.candidate1.id)
        self.assertEquals(clasified[0]['name'], self.candidate1.name)
        self.assertEquals(clasified[0]['candidate'], self.candidate1)
        self.assertEquals(clasified[0]['possible_answers'], 4)

        self.assertEquals(clasified[1]['name'], self.candidate2.name)
        self.assertEquals(clasified[1]['id'], self.candidate2.id)
        self.assertEquals(clasified[1]['candidate'], self.candidate2)
        self.assertEquals(clasified[1]['possible_answers'], 4)

        self.assertEquals(clasified[2]['name'], self.candidate3.name)
        self.assertEquals(clasified[2]['id'], self.candidate3.id)
        self.assertEquals(clasified[2]['candidate'], self.candidate3)
        self.assertEquals(clasified[2]['possible_answers'], 4)

        self.assertEquals(clasified[3]['name'], self.candidate4.name)
        self.assertEquals(clasified[3]['id'], self.candidate4.id)
        self.assertEquals(clasified[3]['candidate'], self.candidate4)
        self.assertEquals(clasified[3]['possible_answers'], 3)

        self.assertEquals(clasified[0]['actual_answers'], 3)
        self.assertEquals(clasified[1]['actual_answers'], 2)
        self.assertEquals(clasified[2]['actual_answers'], 0)
        self.assertEquals(clasified[3]['actual_answers'], 1)
Exemple #2
0
    def test_clasified_points(self):
        ranking_view = RankingMixin()
        ranking_view.candidate_queryset = self.election.candidates.all()

        clasified = ranking_view.get_clasified()

        success_index = ranking_view.success_index()

        possible_answers = clasified[0]["possible_answers"]
        actual_answers = clasified[0]["actual_answers"]
        expected_points1 = (success_index*actual_answers -
                            (possible_answers-actual_answers))*possible_answers

        self.assertEquals(clasified[0]['points'], expected_points1)

        possible_answers = clasified[1]["possible_answers"]
        actual_answers = clasified[1]["actual_answers"]
        expected_points1 = (success_index*actual_answers -
                            (possible_answers-actual_answers))*possible_answers

        self.assertEquals(clasified[1]['points'], expected_points1)

        possible_answers = clasified[2]["possible_answers"]
        actual_answers = clasified[2]["actual_answers"]
        expected_points1 = (success_index*actual_answers -
                            (possible_answers-actual_answers))*possible_answers

        self.assertEquals(clasified[2]['points'], expected_points1)

        possible_answers = clasified[3]["possible_answers"]
        actual_answers = clasified[3]["actual_answers"]
        expected_points1 = (success_index*actual_answers -
                            (possible_answers-actual_answers))*possible_answers

        self.assertEquals(clasified[3]['points'], expected_points1)
Exemple #3
0
    def test_get_ordered_clasified(self):
        ranking_view = RankingMixin()
        ranking_view.candidate_queryset = self.election.candidates.all()

        ordered = ranking_view.get_ordered()

        self.assertEquals(ordered[0]['candidate'], self.candidate1)
        self.assertEquals(ordered[3]['candidate'], self.candidate3)
Exemple #4
0
    def test_get_bad_ones(self):
        ranking_view = RankingMixin()
        ranking_view.candidate_queryset = self.election.candidates.all()

        bad = ranking_view.get_bad()
        self.assertEquals(len(bad), 2)
        self.assertEquals(bad[0]['candidate'], self.candidate3)
        is_candidate2_or_4 = bad[1]['candidate'] == self.candidate2 \
            or bad[1]['candidate'] == self.candidate4
        self.assertTrue(is_candidate2_or_4)
Exemple #5
0
    def test_get_good_ones(self):
        ranking_view = RankingMixin()
        ranking_view.candidate_queryset = self.election.candidates.all()

        good = ranking_view.get_good()
        self.assertEquals(len(good), 2)
        self.assertEquals(good[0]['candidate'], self.candidate1)
        is_candidate2_or_4 = good[1]['candidate'] == self.candidate2 \
            or good[1]['candidate'] == self.candidate4
        self.assertTrue(is_candidate2_or_4)
Exemple #6
0
    def test_get_all_messages(self):
        ranking_view = RankingMixin()
        ranking_view.candidate_queryset = self.election.candidates.all()

        self.assertEquals(ranking_view.all_messages().count(), 4)
        self.assertIn(self.message, ranking_view.all_messages())
        self.assertIn(self.message2, ranking_view.all_messages())
        self.assertIn(self.message3, ranking_view.all_messages())
        self.assertIn(self.message4, ranking_view.all_messages())
Exemple #7
0
 def test_get_index(self):
     ranking_view = RankingMixin()
     ranking_view.candidate_queryset = Candidate.objects.all()
     expected_index = float(15)/float(6)
     self.assertEquals(ranking_view.success_index(), expected_index)
Exemple #8
0
    def test_get_actual_answered_questions(self):
        ranking_view = RankingMixin()
        ranking_view.candidate_queryset = self.election.candidates.all()

        self.assertEquals(ranking_view.actual_answers(), 6)
Exemple #9
0
 def test_get_all_possible_answers(self):
         ranking_view = RankingMixin()
         ranking_view.candidate_queryset = self.election.candidates.all()
         self.assertEquals(ranking_view.all_possible_answers(), 15)
Exemple #10
0
    def test_mixin(self):
        ranking_view = RankingMixin()
        ranking_view.candidate_queryset = self.election.candidates.all()

        ranking = ranking_view.get_ranking()
        self.assertEquals(len(ranking), 4)