コード例 #1
0
    def test_display_ranking(self):
        contest = Contest.objects.get()
        ranking_url = reverse('ranking',
                              kwargs={
                                  'contest_id': contest.id,
                                  'key': '1'
                              })
        response = self.client.get(ranking_url)

        ranking = Ranking.objects.get(key='regular#1')
        page_content = '<b>Some</b> <br/> <i>data</i>'
        RankingPage(ranking=ranking, nr=1, data=page_content + " 1").save()
        RankingPage(ranking=ranking, nr=2, data=page_content + " 2").save()
        self.assertTrue(ranking.pages.count(), 2)

        # Make sure the page includes our rendered data and that HTML
        # hasn't been escaped
        response = self.client.get(ranking_url)
        self.assertContains(response, page_content + " 1")
        response = self.client.get(ranking_url + '?page=2')
        self.assertContains(response, page_content + " 2")

        # Check if the user still can't request pages beyond available limit
        response = self.client.get(ranking_url + '?page=3')
        self.assertContains(response,
                            "You have requested a non-existent ranking page")
コード例 #2
0
ファイル: tests.py プロジェクト: pragacz/oioioi
    def test_display_outdated(self):
        contest = Contest.objects.get()
        ranking_url = reverse('ranking',
            kwargs={'contest_id': contest.id, 'key': '1'})
        response = self.client.get(ranking_url)

        # Add a page to the ranking
        ranking = Ranking.objects.get(key='regular#1')
        ranking.needs_recalculation = False
        ranking.save()
        page_content = '<b>Some</b> <br/> <i>data</i>'
        RankingPage(ranking=ranking, nr=1, data=page_content).save()
        self.assertTrue(ranking.pages.count(), 1)

        outdated_msg = "The data shown in here can be slightly outdated"
        # We shouldn't tell the ranking is outdated, when it isn't
        response = self.client.get(ranking_url)
        self.assertContains(response, page_content)
        self.assertNotContains(response, outdated_msg)

        # Invalidate ranking
        pi = ProblemInstance.objects.get(pk=1)
        user = User.objects.get(username='******')
        contest.controller.update_user_results(user, pi)

        # Make sure we're telling people that the ranking is outdated
        response = self.client.get(ranking_url)
        self.assertContains(response, page_content)
        self.assertContains(response, outdated_msg)

        # Check if the user still can't request pages beyond available limit
        response = self.client.get(ranking_url + '?page=2')
        self.assertContains(response,
                "You have requested a non-existent ranking page")