Esempio n. 1
0
    def test_ranking_view(self):
        contest = Contest.objects.get()
        url = reverse('default_ranking', kwargs={'contest_id': contest.id})

        self.client.login(username='******')
        with fake_time(datetime(2015, 8, 5, tzinfo=utc)):
            response = self.client.get(url)
            self.assertContains(response, 'Export to CSV')

        # Check that Admin is filtered out.
        self.client.login(username='******')
        with fake_time(datetime(2015, 8, 5, tzinfo=utc)):
            response = self.client.get(url)
            self.assertNotIn('<td>Test Admin</td>', response.content)
            self.assertNotContains(response, 'Export to CSV')

        # Ok, so now we make test_admin a regular user.
        admin = User.objects.get(username='******')
        admin.is_superuser = False
        admin.save()

        self.client.login(username='******')
        with fake_timezone_now(datetime(2012, 8, 5, tzinfo=utc)):
            response = self.client.get(url)
            self.assertIn('rankings/ranking_view.html',
                    [t.name for t in response.templates])
            self.assertEqual(len(response.context['choices']), 3)
            self.assertEqual(response.content.count('<td>Test User'), 1)
            self.assertNotIn('<td>Test Admin</td>', response.content)

        with fake_timezone_now(datetime(2015, 8, 5, tzinfo=utc)):
            response = self.client.get(url)
            expected_order = ['Test User', 'Test User 2', 'Test Admin']
            prev_pos = 0
            for user in expected_order:
                pattern = '<td>%s</td>' % (user,)
                self.assertIn(user, response.content)
                pos = response.content.find(pattern)
                self.assertGreater(pos, prev_pos, msg=('User %s has incorrect '
                    'position' % (user,)))
                prev_pos = pos

            response = self.client.get(reverse('ranking',
                kwargs={'contest_id': contest.id, 'key': '1'}))
            self.assertEqual(response.content.count('<td>Test User'), 1)

        # Test visibility of links to problem statements
        contest.controller_name = \
            'oioioi.rankings.tests.StatementHiderForContestController'
        contest.save()

        with fake_timezone_now(datetime(2015, 8, 5, tzinfo=utc)):
            response = self.client.get(url)

            for task in VISIBLE_TASKS:
                self.assertIn(task + '</a></th>', response.content)

            for task in HIDDEN_TASKS:
                self.assertIn(task + '</th>', response.content)
Esempio n. 2
0
    def test_ranking_ordering(self):

        def check_order(response, expected):
            prev_pos = 0
            for user in expected:
                pattern = b'<td[^>]*>%s</td>' % (user,)
                pattern_match = re.search(pattern, response.content)

                self.assertTrue(pattern_match)
                self.assertContains(response, user)

                pos = pattern_match.start()
                self.assertGreater(pos, prev_pos, msg=('User %s has incorrect '
                    'position' % (user,)))
                prev_pos = pos

        self.assertTrue(self.client.login(username='******'))

        with fake_timezone_now(datetime(2013, 1, 1, 0, 0, tzinfo=utc)):
            # 28 (10, 8, 6, 4), 28 (9, 9, 7, 3), 10 (10)
            response = self.client.get(self._ranking_url(A_PLUS_B_RANKING_KEY))
            check_order(response, [b'Test User', b'Test User 2', b'Test User 3'])
            self.assertContains(response, '28</td>')

            # 10 (10), 10 (7, 3), 10 (6, 4)
            response = self.client.get(self._ranking_url(B_RANKING_KEY))
            check_order(response, [b'Test User 3', b'Test User 2', b'Test User'])
            self.assertNotContains(response, b'28</td>')
Esempio n. 3
0
    def test_anonymous_participants(self):
        contest = Contest.objects.get()
        contest.controller_name = \
                "oioioi.participants.tests.AnonymousContestController"
        contest.save()

        u1 = User.objects.get(pk=1001)
        self._register(u1, anonymous=False, possible=True)

        u2 = User.objects.get(pk=1002)
        self._register(u2, anonymous=True, possible=True)

        contest = Contest.objects.get()
        url = reverse('default_ranking', kwargs={'contest_id': contest.id})
        self.client.login(username='******')

        with fake_timezone_now(datetime(2015, 8, 5, tzinfo=utc)):
            response = self.client.get(url)
            self.assertNotIn('>test_user</a>', response.content)
            self.assertIn('>Test User</a>', response.content)

            self.assertIn('>test_user2</a>', response.content)
            self.assertNotIn('>Test User 2</a>', response.content)

            # Edit contest registration
            self._register(u2, anonymous=False, possible=True)
            # To see the changes in the ranking we have to clear the cache
            cache.clear()

            self.client.login(username='******')
            response = self.client.get(url)
            self.assertNotIn('>test_user2</a>', response.content)
            self.assertIn('>Test User 2</a>', response.content)
Esempio n. 4
0
    def test_ranking_ordering(self):
        def check_order(response, expected):
            prev_pos = 0
            for user in expected:
                pattern = b'<td[^>]*>%s</td>' % (user, )
                pattern_match = re.search(pattern, response.content)

                self.assertTrue(pattern_match)
                self.assertIn(user, response.content)

                pos = pattern_match.start()
                self.assertGreater(pos,
                                   prev_pos,
                                   msg=('User %s has incorrect '
                                        'position' % (user, )))
                prev_pos = pos

        self.client.login(username='******')

        with fake_timezone_now(datetime(2013, 1, 1, 0, 0, tzinfo=utc)):
            # 28 (10, 8, 6, 4), 28 (9, 9, 7, 3), 10 (10)
            response = self.client.get(self._ranking_url(A_PLUS_B_RANKING_KEY))
            check_order(response,
                        [b'Test User', b'Test User 2', b'Test User 3'])
            self.assertIn(b'28</td>', response.content)

            # 10 (10), 10 (7, 3), 10 (6, 4)
            response = self.client.get(self._ranking_url(B_RANKING_KEY))
            check_order(response,
                        [b'Test User 3', b'Test User 2', b'Test User'])
            self.assertNotContains(response, b'28</td>')
Esempio n. 5
0
    def test_anonymous_participants(self):
        contest = Contest.objects.get()
        contest.controller_name = \
                "oioioi.participants.tests.AnonymousContestController"
        contest.save()

        u1 = User.objects.get(pk=1001)
        self._register(u1, anonymous=False, possible=True)

        u2 = User.objects.get(pk=1002)
        self._register(u2, anonymous=True, possible=True)

        contest = Contest.objects.get()
        url = reverse('default_ranking', kwargs={'contest_id': contest.id})
        self.client.login(username='******')

        with fake_timezone_now(datetime(2015, 8, 5, tzinfo=utc)):
            response = self.client.get(url)
            self.assertNotIn('>test_user</a>', response.content)
            self.assertIn('>Test User</a>', response.content)

            self.assertIn('>test_user2</a>', response.content)
            self.assertNotIn('>Test User 2</a>', response.content)

            # Edit contest registration
            self._register(u2, anonymous=False, possible=True)
            # To see the changes in the ranking we have to clear the cache
            cache.clear()

            self.client.login(username='******')
            response = self.client.get(url)
            self.assertNotIn('>test_user2</a>', response.content)
            self.assertIn('>Test User 2</a>', response.content)
Esempio n. 6
0
        def check_round_state(date, expected):
            request = RequestFactory().request()
            request.contest = contest
            request.user = user
            request.timestamp = date

            self.client.login(username='******')
            with fake_timezone_now(date):
                url = reverse('ranking',
                              kwargs={
                                  'contest_id': 'c',
                                  'key': A_PLUS_B_RANKING_KEY
                              })
                response = self.client.get(url)
                if expected[0]:
                    self.assertContains(response, 'taskA1')
                else:
                    self.assertNotContains(response, 'taskA1')

            self.assertEquals(
                expected[1],
                controller.can_see_source(request, not_my_submission))

            self.assertEquals(
                False, controller.can_see_source(request, not_last_submission))
Esempio n. 7
0
    def test_anonymous_participants(self):
        contest = Contest.objects.get()
        contest.controller_name = "oioioi.participants.tests.AnonymousContestController"
        contest.save()

        u1 = User.objects.get(pk=1001)
        self._register(u1, anonymous=False, possible=True)

        u2 = User.objects.get(pk=1002)
        self._register(u2, anonymous=True, possible=True)

        contest = Contest.objects.get()
        url = reverse('default_ranking', kwargs={'contest_id': contest.id})
        self.assertTrue(self.client.login(username='******'))

        with fake_timezone_now(datetime(2015, 8, 5, tzinfo=utc)):
            response = self.client.get(url)
            user_pattern = r'>\s*%s\s*</a>'

            self.assertFalse(
                re.search(user_pattern % ('test_user', ),
                          response.content.decode('utf-8')))
            self.assertTrue(
                re.search(user_pattern % ('Test User', ),
                          response.content.decode('utf-8')))
            self.assertTrue(
                re.search(user_pattern % ('test_user2', ),
                          response.content.decode('utf-8')))
            self.assertFalse(
                re.search(user_pattern % ('Test User 2', ),
                          response.content.decode('utf-8')))

            # Edit contest registration
            self._register(u2, anonymous=False, possible=True)
            # To see the changes in the ranking we have to clear the cache
            cache.clear()

            self.assertTrue(self.client.login(username='******'))
            response = self.client.get(url)
            self.assertFalse(
                re.search(user_pattern % ('test_user2', ),
                          response.content.decode('utf-8')))

            self.assertTrue(
                re.search(user_pattern % ('Test User 2', ),
                          response.content.decode('utf-8')))
Esempio n. 8
0
    def test_no_anonymous_participants(self):
        contest = Contest.objects.get()
        contest.controller_name = \
                "oioioi.oi.controllers.OIContestController"
        contest.save()

        u1 = User.objects.get(pk=1001)
        self._register(u1, anonymous=True, possible=False)

        contest = Contest.objects.get()
        url = reverse('default_ranking', kwargs={'contest_id': contest.id})
        self.client.login(username='******')

        with fake_timezone_now(datetime(2015, 8, 5, tzinfo=utc)):
            response = self.client.get(url)
            self.assertNotIn('>test_user</a>', response.content)
            self.assertIn('>Test User</a>', response.content)
Esempio n. 9
0
    def test_no_anonymous_participants(self):
        contest = Contest.objects.get()
        contest.controller_name = \
                "oioioi.oi.controllers.OIContestController"
        contest.save()

        u1 = User.objects.get(pk=1001)
        self._register(u1, anonymous=True, possible=False)

        contest = Contest.objects.get()
        url = reverse('default_ranking', kwargs={'contest_id': contest.id})
        self.client.login(username='******')

        with fake_timezone_now(datetime(2015, 8, 5, tzinfo=utc)):
            response = self.client.get(url)
            self.assertNotIn('>test_user</a>', response.content)
            self.assertIn('>Test User</a>', response.content)
Esempio n. 10
0
    def test_ranking(self):
        def change_publication_url(way, sub_id):
            return reverse(
                'publish_solution' if way else 'unpublish_solution',
                kwargs={
                    'contest_id': contest.id,
                    'submission_id': sub_id
                },
            )

        with fake_timezone_now(self._rounds_14()):
            contest = Contest.objects.get()
            contest.controller_name = (
                'oioioi.publicsolutions.tests.TSolutionSimpleContestController'
            )
            contest.save()

            self.assertTrue(self.client.login(username='******'))

            url = reverse('default_ranking', kwargs={'contest_id': contest.id})

            response = self.client.get(url)
            self.assertUserSubmissionHTMLDataCount(response.content,
                                                   'test_user', 2)

            self.assertTrue(self.client.login(username='******'))
            cache.clear()
            response = self.client.get(url)
            self.assertUserSubmissionHTMLDataCount(response.content,
                                                   'test_user2', 0)

            self.assertTrue(self.client.login(username='******'))
            request = self.client.post(change_publication_url(True, 4))
            self.assertEqual(302, request.status_code)

            cache.clear()
            response = self.client.get(url)
            self.assertUserSubmissionHTMLDataCount(response.content,
                                                   'test_user', 2)

            self.assertTrue(self.client.login(username='******'))
            cache.clear()
            response = self.client.get(url)
            self.assertUserSubmissionHTMLDataCount(response.content,
                                                   'test_user2', 0)
Esempio n. 11
0
    def test_ranking_access(self):
        contest = Contest.objects.get()
        contest.controller_name = \
            'oioioi.oi.controllers.OIContestController'
        contest.save()
        round = contest.round_set.get()
        user = User.objects.get(username='******')
        p = Participant(contest=contest, user=user)
        p.save()
        url = reverse('default_ranking', kwargs={'contest_id': contest.id})

        with fake_timezone_now(round.results_date + timedelta(days=1)):
            self.client.login(username='******')
            response = self.client.get(url)
            self.assertContains(response, "No rankings available.")
            self.client.login(username='******')
            response = self.client.get(url)
            self.assertContains(response, '>Test User</a>')
Esempio n. 12
0
    def test_ranking_access(self):
        contest = Contest.objects.get()
        contest.controller_name = \
            'oioioi.oi.controllers.OIContestController'
        contest.save()
        round = contest.round_set.get()
        user = User.objects.get(username='******')
        p = Participant(contest=contest, user=user)
        p.save()
        url = reverse('default_ranking', kwargs={'contest_id': contest.id})

        with fake_timezone_now(round.results_date + timedelta(days=1)):
            self.client.login(username='******')
            response = self.client.get(url)
            self.assertContains(response, "No rankings available.")
            self.client.login(username='******')
            response = self.client.get(url)
            self.assertContains(response, '>Test User</a>')
Esempio n. 13
0
    def test_divisions(self):
        def check_visibility(good_keys, response):
            division_for_pi = {1: 'A', 2: 'A', 3: 'B', 4: 'B', 5: 'NONE'}
            for key, div in division_for_pi.items():
                p = ProblemInstance.objects.get(pk=key)
                if div in good_keys:
                    self.assertContains(response, p.short_name)
                else:
                    self.assertNotContains(response, p.short_name)

        self.client.login(username='******')

        with fake_timezone_now(datetime(2013, 1, 1, 0, 0, tzinfo=utc)):
            response = self.client.get(self._ranking_url(B_RANKING_KEY))
            check_visibility(['B'], response)
            response = self.client.get(self._ranking_url(A_PLUS_B_RANKING_KEY))
            check_visibility(['A', 'B'], response)
            # Round 3 is trial
            response = self.client.get(self._ranking_url(3))
            check_visibility(['NONE'], response)
Esempio n. 14
0
    def test_divisions(self):

        def check_visibility(good_keys, response):
            division_for_pi = {1: 'A', 2: 'A', 3: 'B', 4: 'B', 5: 'NONE'}
            for key, div in division_for_pi.items():
                p = ProblemInstance.objects.get(pk=key)
                if div in good_keys:
                    self.assertContains(response, p.short_name)
                else:
                    self.assertNotContains(response, p.short_name)

        self.assertTrue(self.client.login(username='******'))

        with fake_timezone_now(datetime(2013, 1, 1, 0, 0, tzinfo=utc)):
            response = self.client.get(self._ranking_url(B_RANKING_KEY))
            check_visibility(['B'], response)
            response = self.client.get(self._ranking_url(A_PLUS_B_RANKING_KEY))
            check_visibility(['A', 'B'], response)
            # Round 3 is trial
            response = self.client.get(self._ranking_url(3))
            check_visibility(['NONE'], response)
Esempio n. 15
0
        def check_round_state(date, expected):
            request = RequestFactory().request()
            request.contest = contest
            request.user = user
            request.timestamp = date

            self.assertTrue(self.client.login(username='******'))
            with fake_timezone_now(date):
                url = reverse('ranking', kwargs={'contest_id': 'c',
                    'key': A_PLUS_B_RANKING_KEY})
                response = self.client.get(url)
                if expected[0]:
                    self.assertContains(response, 'taskA1')
                else:
                    self.assertNotContains(response, 'taskA1')

            self.assertEqual(expected[1],
                    controller.can_see_source(request, not_my_submission))

            self.assertEqual(False,
                    controller.can_see_source(request, not_last_submission))
Esempio n. 16
0
    def test_ranking(self):
        def change_publication_url(way, sub_id):
            return reverse('publish_solution' if way else 'unpublish_solution',
                    kwargs={'contest_id': contest.id, 'submission_id': sub_id})

        with fake_timezone_now(self._rounds_14()):
            contest = Contest.objects.get()
            contest.controller_name = \
                'oioioi.publicsolutions.tests.TSolutionSimpleContestController'
            contest.save()

            self.client.login(username='******')

            url = reverse('default_ranking', kwargs={'contest_id': contest.id})

            response = self.client.get(url)
            self.assertUserSubmissionHTMLDataCount(response.content,
                    'test_user', 2)

            self.client.login(username='******')
            cache.clear()
            response = self.client.get(url)
            self.assertUserSubmissionHTMLDataCount(response.content,
                    'test_user2', 0)

            self.client.login(username='******')
            request = self.client.post(change_publication_url(True, 4))
            self.assertEqual(302, request.status_code)

            cache.clear()
            response = self.client.get(url)
            self.assertUserSubmissionHTMLDataCount(response.content,
                    'test_user', 2)

            self.client.login(username='******')
            cache.clear()
            response = self.client.get(url)
            self.assertUserSubmissionHTMLDataCount(response.content,
                    'test_user2', 0)
Esempio n. 17
0
    def test_no_anonymous_participants(self):
        contest = Contest.objects.get()
        contest.controller_name = \
                "oioioi.oi.controllers.OIContestController"
        contest.save()

        u1 = User.objects.get(pk=1001)
        self._register(u1, anonymous=True, possible=False)

        contest = Contest.objects.get()
        url = reverse('default_ranking', kwargs={'contest_id': contest.id})
        self.assertTrue(self.client.login(username='******'))

        with fake_timezone_now(datetime(2015, 8, 5, tzinfo=utc)):
            response = self.client.get(url)

            user_pattern = r'>\s*%s\s*</a>'

            self.assertFalse(re.search(user_pattern % ('test_user',),
                                       response.content.decode('utf-8')))
            self.assertTrue(re.search(user_pattern % ('Test User',),
                                       response.content.decode('utf-8')))
Esempio n. 18
0
    def test_no_anonymous_participants(self):
        contest = Contest.objects.get()
        contest.controller_name = "oioioi.oi.controllers.OIContestController"
        contest.save()

        u1 = User.objects.get(pk=1001)
        self._register(u1, anonymous=True, possible=False)

        contest = Contest.objects.get()
        url = reverse('default_ranking', kwargs={'contest_id': contest.id})
        self.assertTrue(self.client.login(username='******'))

        with fake_timezone_now(datetime(2015, 8, 5, tzinfo=utc)):
            response = self.client.get(url)

            user_pattern = r'>\s*%s\s*</a>'

            self.assertFalse(
                re.search(user_pattern % ('test_user', ),
                          response.content.decode('utf-8')))
            self.assertTrue(
                re.search(user_pattern % ('Test User', ),
                          response.content.decode('utf-8')))
Esempio n. 19
0
    def test_ranking_view(self):
        contest = Contest.objects.get()
        url = reverse('default_ranking', kwargs={'contest_id': contest.id})

        self.assertTrue(self.client.login(username='******'))
        with fake_time(datetime(2015, 8, 5, tzinfo=utc)):
            response = self.client.get(url)
            self.assertContains(response, 'Export to CSV')
            self.assertContains(response, 'Regenerate ranking')

        # Check that Admin is filtered out.
        self.assertTrue(self.client.login(username='******'))
        with fake_time(datetime(2015, 8, 5, tzinfo=utc)):
            response = self.client.get(url)

            self.assertFalse(re.search(USER_CELL_PATTERN % ('Test Admin',),
                                       response.content.decode('utf-8')))
            self.assertNotContains(response, 'Export to CSV')
            self.assertNotContains(response, 'Regenerate ranking')

        # Ok, so now we make test_admin a regular user.
        admin = User.objects.get(username='******')
        admin.is_superuser = False
        admin.save()

        self.assertTrue(self.client.login(username='******'))
        with fake_timezone_now(datetime(2012, 8, 5, tzinfo=utc)):
            response = self.client.get(url)
            self.assertIn('rankings/ranking_view.html',
                    [t.name for t in response.templates])
            self.assertEqual(len(response.context['choices']), 3)
            self.assertEqual(len(re.findall(USER_CELL_PATTERN % ('Test User',),
                                            response.content.decode('utf-8'))), 1)

            self.assertFalse(re.search(USER_CELL_PATTERN % ('Test Admin',),
                                       response.content.decode('utf-8')))

        with fake_timezone_now(datetime(2015, 8, 5, tzinfo=utc)):
            response = self.client.get(url)
            expected_order = ['Test User', 'Test User 2', 'Test Admin']
            prev_pos = 0
            content = response.content.decode('utf-8')
            for user in expected_order:
                pattern = USER_CELL_PATTERN % (user,)
                pattern_match = re.search(pattern, content)
                self.assertTrue(pattern_match)
                pos = pattern_match.start()
                self.assertGreater(pos, prev_pos, msg=('User %s has incorrect '
                    'position' % (user,)))
                prev_pos = pos

            response = self.client.get(reverse('ranking',
                kwargs={'contest_id': contest.id, 'key': '1'}))
            self.assertEqual(len(re.findall(
                USER_CELL_PATTERN_LEFT % ('Test User',), response.content.decode('utf-8'))), 1)

        # Test visibility of links to problem statements
        contest.controller_name = \
            'oioioi.rankings.tests.StatementHiderForContestController'
        contest.save()

        with fake_timezone_now(datetime(2015, 8, 5, tzinfo=utc)):
            response = self.client.get(url)

            for task in VISIBLE_TASKS:
                self.assertTrue(re.search(task + r'\s*</a>\s*</th>',
                                          response.content.decode('utf-8')))

            for task in HIDDEN_TASKS:
                self.assertTrue(re.search(task + r'\s*</th>',
                                          response.content.decode('utf-8')))
Esempio n. 20
0
    def test_ranking_view(self):
        contest = Contest.objects.get()
        url = reverse('default_ranking', kwargs={'contest_id': contest.id})
        csv_url = reverse('ranking_csv', kwargs={'contest_id': contest.id,
                                                 'key': 'c'})

        self.client.login(username='******')

        # trial round begins at 11:00, ends at 16:00, results are available
        # at 19:00
        with fake_timezone_now(datetime(2013, 12, 13, 10, 59, tzinfo=utc)):
            response = self.client.get(url)
            for task in ['trial', 'A', 'sum', 'test']:
                self.assertActiveTaskNotIn(task, response.content)

        with fake_timezone_now(datetime(2013, 12, 13, 11, 30, tzinfo=utc)):
            response = self.client.get(url)
            self.assertActiveTaskIn('trial', response.content)
            for task in ['A', 'sum', 'test']:
                self.assertActiveTaskNotIn(task, response.content)

        with fake_timezone_now(datetime(2013, 12, 13, 17, 0, tzinfo=utc)):
            response = self.client.get(url)
            self.assertInactiveTaskIn('trial', response.content)
            for task in ['A', 'sum', 'test']:
                self.assertInactiveTaskNotIn(task, response.content)

        # round 1 starts at 20:40, ends at 01:40, results are available at
        # 09:00
        with fake_timezone_now(datetime(2013, 12, 14, 20, 39, tzinfo=utc)):
            response = self.client.get(url)
            self.assertInactiveTaskIn('trial', response.content)
            for task in ['A', 'sum', 'test']:
                self.assertInactiveTaskNotIn(task, response.content)

        with fake_timezone_now(datetime(2013, 12, 14, 20, 40, tzinfo=utc)):
            response = self.client.get(url)
            self.assertActiveTaskNotIn('trial', response.content)
            for task in ['A', 'sum', 'test']:
                self.assertActiveTaskIn(task, response.content)
            self.assertNotIn('The ranking is frozen.', response.content)

        with fake_timezone_now(datetime(2013, 12, 15, 1, 0, tzinfo=utc)):
            response = self.client.get(url)
            self.assertActiveTaskNotIn('trial', response.content)
            for task in ['A', 'sum', 'test']:
                self.assertActiveTaskIn(task, response.content)
            self.assertIn('The ranking is frozen.', response.content)

        with fake_timezone_now(datetime(2013, 12, 15, 7, 0, tzinfo=utc)):
            response = self.client.get(url)
            self.assertInactiveTaskNotIn('trial', response.content)
            for task in ['A', 'sum', 'test']:
                self.assertInactiveTaskIn(task, response.content)
            self.assertIn('The ranking is frozen.', response.content)

        with fake_timezone_now(datetime(2013, 12, 15, 9, 0, tzinfo=utc)):
            response = self.client.get(url)
            self.assertInactiveTaskNotIn('trial', response.content)
            for task in ['A', 'sum', 'test']:
                self.assertInactiveTaskIn(task, response.content)
            self.assertNotIn('The ranking is frozen.', response.content)

        with fake_timezone_now(datetime(2013, 12, 15, 0, 40, tzinfo=utc)):
            response = self.client.get(url)
            self.assertEqual(
                response.content.count('data-username="******"'), 2)

        self.client.login(username='******')

        with fake_timezone_now(datetime(2013, 12, 15, 0, 40, tzinfo=utc)):
            response = self.client.get(csv_url)
            self.assertEqual(response.status_code, 200)
            self.assertEqual(response.content.count('\n'), 4)

            response = self.client.get(url)
            self.assertEqual(response.content.count('data-result_url'), 8)
Esempio n. 21
0
    def test_ranking_view(self):
        contest = Contest.objects.get()
        url = reverse('default_ranking', kwargs={'contest_id': contest.id})
        csv_url = reverse('ranking_csv', kwargs={'contest_id': contest.id,
                                                 'key': 'c'})

        self.client.login(username='******')

        # trial round begins at 11:00, ends at 16:00, results are available
        # at 19:00
        with fake_timezone_now(datetime(2013, 12, 13, 10, 59, tzinfo=utc)):
            response = self.client.get(url)
            for task in ['trial', 'A', 'sum', 'test']:
                self.assertActiveTaskNotIn(task, response.content)

        with fake_timezone_now(datetime(2013, 12, 13, 11, 30, tzinfo=utc)):
            response = self.client.get(url)
            self.assertActiveTaskIn('trial', response.content)
            for task in ['A', 'sum', 'test']:
                self.assertActiveTaskNotIn(task, response.content)

        with fake_timezone_now(datetime(2013, 12, 13, 17, 0, tzinfo=utc)):
            response = self.client.get(url)
            self.assertInactiveTaskIn('trial', response.content)
            for task in ['A', 'sum', 'test']:
                self.assertInactiveTaskNotIn(task, response.content)

        # round 1 starts at 20:40, ends at 01:40, results are available at
        # 09:00
        with fake_timezone_now(datetime(2013, 12, 14, 20, 39, tzinfo=utc)):
            response = self.client.get(url)
            self.assertInactiveTaskIn('trial', response.content)
            for task in ['A', 'sum', 'test']:
                self.assertInactiveTaskNotIn(task, response.content)

        with fake_timezone_now(datetime(2013, 12, 14, 20, 40, tzinfo=utc)):
            response = self.client.get(url)
            self.assertActiveTaskNotIn('trial', response.content)
            for task in ['A', 'sum', 'test']:
                self.assertActiveTaskIn(task, response.content)
            self.assertNotIn('The ranking is frozen.', response.content)

        with fake_timezone_now(datetime(2013, 12, 15, 1, 0, tzinfo=utc)):
            response = self.client.get(url)
            self.assertActiveTaskNotIn('trial', response.content)
            for task in ['A', 'sum', 'test']:
                self.assertActiveTaskIn(task, response.content)
            self.assertIn('The ranking is frozen.', response.content)

        with fake_timezone_now(datetime(2013, 12, 15, 7, 0, tzinfo=utc)):
            response = self.client.get(url)
            self.assertInactiveTaskNotIn('trial', response.content)
            for task in ['A', 'sum', 'test']:
                self.assertInactiveTaskIn(task, response.content)
            self.assertIn('The ranking is frozen.', response.content)

        with fake_timezone_now(datetime(2013, 12, 15, 9, 0, tzinfo=utc)):
            response = self.client.get(url)
            self.assertInactiveTaskNotIn('trial', response.content)
            for task in ['A', 'sum', 'test']:
                self.assertInactiveTaskIn(task, response.content)
            self.assertNotIn('The ranking is frozen.', response.content)

        with fake_timezone_now(datetime(2013, 12, 15, 0, 40, tzinfo=utc)):
            response = self.client.get(url)
            self.assertEqual(
                response.content.count('data-username="******"'), 2)

        self.client.login(username='******')

        with fake_timezone_now(datetime(2013, 12, 15, 0, 40, tzinfo=utc)):
            response = self.client.get(csv_url)
            self.assertEqual(response.status_code, 200)
            self.assertEqual(response.content.count('\n'), 4)

            response = self.client.get(url)
            self.assertEqual(response.content.count('data-result_url'), 8)
Esempio n. 22
0
    def test_ranking_view(self):
        contest = Contest.objects.get()
        url = reverse('default_ranking', kwargs={'contest_id': contest.id})

        self.client.login(username='******')
        with fake_time(datetime(2015, 8, 5, tzinfo=utc)):
            response = self.client.get(url)
            self.assertContains(response, 'Export to CSV')

        # Check that Admin is filtered out.
        self.client.login(username='******')
        with fake_time(datetime(2015, 8, 5, tzinfo=utc)):
            response = self.client.get(url)
            self.assertNotIn('<td>Test Admin</td>', response.content)
            self.assertNotContains(response, 'Export to CSV')

        # Ok, so now we make test_admin a regular user.
        admin = User.objects.get(username='******')
        admin.is_superuser = False
        admin.save()

        self.client.login(username='******')
        with fake_timezone_now(datetime(2012, 8, 5, tzinfo=utc)):
            response = self.client.get(url)
            self.assertIn('rankings/ranking_view.html',
                          [t.name for t in response.templates])
            self.assertEqual(len(response.context['choices']), 3)
            self.assertEqual(response.content.count('<td>Test User'), 1)
            self.assertNotIn('<td>Test Admin</td>', response.content)

        with fake_timezone_now(datetime(2015, 8, 5, tzinfo=utc)):
            response = self.client.get(url)
            expected_order = ['Test User', 'Test User 2', 'Test Admin']
            prev_pos = 0
            for user in expected_order:
                pattern = '<td>%s</td>' % (user, )
                self.assertIn(user, response.content)
                pos = response.content.find(pattern)
                self.assertGreater(pos,
                                   prev_pos,
                                   msg=('User %s has incorrect '
                                        'position' % (user, )))
                prev_pos = pos

            response = self.client.get(
                reverse('ranking',
                        kwargs={
                            'contest_id': contest.id,
                            'key': '1'
                        }))
            self.assertEqual(response.content.count('<td>Test User'), 1)

        # Test visibility of links to problem statements
        contest.controller_name = \
            'oioioi.rankings.tests.StatementHiderForContestController'
        contest.save()

        with fake_timezone_now(datetime(2015, 8, 5, tzinfo=utc)):
            response = self.client.get(url)

            for task in VISIBLE_TASKS:
                self.assertIn(task + '</a></th>', response.content)

            for task in HIDDEN_TASKS:
                self.assertIn(task + '</th>', response.content)