예제 #1
0
파일: views.py 프로젝트: sbnoemi/notorhot
    def test_get_leaders(self):
        cat1 = mixer.blend('notorhot.CandidateCategory')
        cat2 = mixer.blend('notorhot.CandidateCategory')
        
        (cand1, cand2, cand3, cand4) = generate_leaderboard_data(cat1, cat2)

        view = self.make_view('get', view_kwargs={ 'leaderboard_length': 3 },
            request_kwargs={ 'category_slug': cat1.slug, })
        
        leaders = view.get_leaders()
        self.assertEqual(list(leaders), [cand4, cand3, cand2,])
예제 #2
0
파일: models.py 프로젝트: sbnoemi/notorhot
 def test_manager_and_queryset_chaining(self):
     cat1 = mixer.blend('notorhot.CandidateCategory')
     cat2 = mixer.blend('notorhot.CandidateCategory')
     
     (cand1, cand2, cand3, cand4) = generate_leaderboard_data(cat1, cat2)
     
     in_order = Candidate.enabled.for_category(cat1).order_by_wins()
     # get win count for ordered candidates = should be 6, 7, 8, 9
     wins = [c.wins for c in in_order]
     self.assertEqual(wins, [6, 7, 8, 9])
     self.assertEqual(list(in_order), [cand4, cand3, cand2, cand1])
예제 #3
0
    def test_success(self):
        cat1 = mixer.blend('notorhot.CandidateCategory', slug='cat-slug')
        cat2 = mixer.blend('notorhot.CandidateCategory')        
        (cand1, cand2, cand3, cand4) = generate_leaderboard_data(cat1, cat2)

        with patch.object(LeaderboardView, 'leaderboard_length', new=3):
            response = self.client.get('/cat-slug/leaders/')
        
        self.assertEqual(response.status_code, 200)
        self.assertIsInstance(response.context['view'], LeaderboardView)
        self.assertIsNotNone(response.context['leaders'])
        self.assertEqual(list(response.context['leaders']), [cand4, cand3, cand2])
        self.assertIsNotNone(response.context['category'])
        self.assertEqual(response.context['category'], cat1)
        self.assertContains(response, 'Beta')
        self.assertContains(response, 'Gamma')
        self.assertContains(response, 'Delta')
        self.assertTemplateUsed(response, 'notorhot/leaders.html')