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,])
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])
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')