Esempio n. 1
0
    def test_disqualified(self):
        user = User.objects.get(username='******')
        contest = Contest.objects.get()
        controller = contest.controller
        submission = Submission.objects.get(id=1)
        submission_ok = Submission.objects.get(id=2)
        fake_request = self._get_fake_request(user, contest)

        self.assertTrue(controller.is_submission_disqualified(submission))
        self.assertFalse(controller.is_submission_disqualified(submission_ok))
        self.assertTrue(controller.has_disqualification_history(submission))
        self.assertFalse(
            controller.has_disqualification_history(submission_ok))
        self.assertTrue(
            controller.is_any_submission_to_problem_disqualified(
                user, submission.problem_instance))
        self.assertTrue(controller.is_user_disqualified(fake_request(), user))
        self.assertFalse(controller.results_visible(fake_request(),
                                                    submission))

        # submission_ok is a submission to the same problem
        self.assertFalse(
            controller.results_visible(fake_request(), submission_ok))
        self.assertNotIn(
            user, controller.exclude_disqualified_users(User.objects.all()))

        other_contest = Contest(name='finding_another_shrubbery',
                                controller_name=contest.controller_name,
                                creation_date=contest.creation_date)
        other_contest.save()
        other_fake_request = self._get_fake_request(user, other_contest)
        self.assertFalse(
            other_contest.controller.is_user_disqualified(
                other_fake_request(), user))
Esempio n. 2
0
    def test_participants_contest_visibility(self):
        contest = Contest(id='invisible', name='Invisible Contest')
        contest.controller_name = \
                'oioioi.participants.tests.ParticipantsContestController'
        contest.save()
        user = User.objects.get(username='******')
        response = self.client.get(reverse('select_contest'))
        self.assertIn('contests/select_contest.html',
                [t.name for t in response.templates])
        self.assertEqual(len(response.context['contests']), 1)

        self.client.login(username='******')
        response = self.client.get(reverse('select_contest'))
        self.assertEqual(len(response.context['contests']), 1)

        p1 = Participant(contest=contest, user=user, status='BANNED')
        p1.save()
        self.client.login(username='******')
        response = self.client.get(reverse('select_contest'))
        self.assertEqual(len(response.context['contests']), 1)

        p1.status = 'ACTIVE'
        p1.save()
        self.client.login(username='******')
        response = self.client.get(reverse('select_contest'))
        self.assertEqual(len(response.context['contests']), 2)

        self.client.login(username='******')
        response = self.client.get(reverse('select_contest'))
        self.assertEqual(len(response.context['contests']), 2)
        self.assertIn('Invisible Contest', response.content)
Esempio n. 3
0
    def test_recent_contests_list(self):
        contest = Contest.objects.get()
        invisible_contest = Contest(id='invisible', name='Invisible Contest',
            controller_name='oioioi.contests.tests.PrivateContestController')
        invisible_contest.save()

        self.client.login(username='******')
        self.client.get('/c/%s/dashboard/' % contest.id)
        self.client.get('/c/%s/dashboard/' % invisible_contest.id)
        response = self.client.get(reverse('select_contest'))
        self.assertEqual(len(response.context['contests']), 2)
        self.assertContains(response, 'Test contest')
        self.assertContains(response, 'Invisible Contest')
        self.client.logout()

        self.client.login(username='******')
        response = self.client.get('/c/%s/dashboard/' % contest.id)
        self.assertIn('dropdown open', response.content)
        response = self.client.get('/c/%s/dashboard/' % contest.id)
        self.assertNotIn('dropdown open', response.content)

        contests = [cv.contest for cv in ContestView.objects.all()]
        self.assertEqual(contests, [contest, invisible_contest])

        self.client.get('/c/%s/dashboard/' % invisible_contest.id)
        response = self.client.get(reverse('select_contest'))
        self.assertEqual(len(response.context['contests']), 2)
        contests = [cv.contest for cv in ContestView.objects.all()]
        self.assertEqual(contests, [invisible_contest, contest])
Esempio n. 4
0
    def test_recent_contests_list(self):
        contest = Contest.objects.get()
        invisible_contest = Contest(
            id='invisible',
            name='Invisible Contest',
            controller_name='oioioi.contests.tests.PrivateContestController')
        invisible_contest.save()

        self.client.login(username='******')
        self.client.get('/c/%s/dashboard/' % contest.id)
        self.client.get('/c/%s/dashboard/' % invisible_contest.id)
        response = self.client.get(reverse('select_contest'))
        self.assertEqual(len(response.context['contests']), 2)
        self.assertContains(response, 'Test contest')
        self.assertContains(response, 'Invisible Contest')
        self.client.logout()

        self.client.login(username='******')
        response = self.client.get('/c/%s/dashboard/' % contest.id)
        self.assertIn('dropdown open', response.content)
        response = self.client.get('/c/%s/dashboard/' % contest.id)
        self.assertNotIn('dropdown open', response.content)

        contests = [cv.contest for cv in ContestView.objects.all()]
        self.assertEqual(contests, [contest, invisible_contest])

        self.client.get('/c/%s/dashboard/' % invisible_contest.id)
        response = self.client.get(reverse('select_contest'))
        self.assertEqual(len(response.context['contests']), 2)
        contests = [cv.contest for cv in ContestView.objects.all()]
        self.assertEqual(contests, [invisible_contest, contest])
Esempio n. 5
0
    def test_contest_visibility(self):
        contest = Contest(id='invisible', name='Invisible Contest')
        contest.controller_name = 'oioioi.participants.tests.OnsiteContestController'
        contest.save()
        user = User.objects.get(username='******')
        response = self.client.get(reverse('select_contest'))
        self.assertIn('contests/select_contest.html',
                      [t.name for t in response.templates])
        self.assertEqual(len(response.context['contests']), 1)

        self.assertTrue(self.client.login(username='******'))
        response = self.client.get(reverse('select_contest'))
        self.assertEqual(len(response.context['contests']), 1)

        p1 = Participant(contest=contest, user=user, status='BANNED')
        p1.save()
        self.assertTrue(self.client.login(username='******'))
        response = self.client.get(reverse('select_contest'))
        self.assertEqual(len(response.context['contests']), 1)

        p1.status = 'ACTIVE'
        p1.save()
        self.assertTrue(self.client.login(username='******'))
        response = self.client.get(reverse('select_contest'))
        self.assertEqual(len(response.context['contests']), 2)

        self.assertTrue(self.client.login(username='******'))
        response = self.client.get(reverse('select_contest'))
        self.assertEqual(len(response.context['contests']), 2)
        self.assertContains(response, 'Invisible Contest')
Esempio n. 6
0
    def test_disqualified(self):
        user = User.objects.get(username='******')
        contest = Contest.objects.get()
        controller = contest.controller
        submission = Submission.objects.get(id=1)
        submission_ok = Submission.objects.get(id=2)
        fake_request = self._get_fake_request(user, contest)

        self.assertTrue(controller.is_submission_disqualified(submission))
        self.assertFalse(controller.is_submission_disqualified(submission_ok))
        self.assertTrue(controller.has_disqualification_history(submission))
        self.assertFalse(controller.has_disqualification_history(
            submission_ok))
        self.assertTrue(controller.is_any_submission_to_problem_disqualified(
            user, submission.problem_instance))
        self.assertTrue(controller.is_user_disqualified(fake_request(), user))
        self.assertFalse(controller.results_visible(fake_request(),
                                                    submission))

        # submission_ok is a submission to the same problem
        self.assertFalse(controller.results_visible(
            fake_request(), submission_ok))
        self.assertNotIn(user, controller.exclude_disqualified_users(
            fake_request(), User.objects.all()))

        other_contest = Contest(name='finding_another_shrubbery',
                                controller_name=contest.controller_name,
                                creation_date=contest.creation_date)
        other_contest.save()
        other_fake_request = self._get_fake_request(user, other_contest)
        self.assertFalse(other_contest.controller.is_user_disqualified(
            other_fake_request(), user))
Esempio n. 7
0
    def test_contest_visibility(self):
        contest = Contest(id='visible', name='Visible Contest')
        contest.controller_name = 'oioioi.oi.controllers.OIContestController'
        contest.save()

        response = self.client.get(reverse('select_contest'))
        self.assertEqual(len(response.context['contests']), 2)
        self.assertContains(response, 'Visible Contest')

        response = self.client.get(reverse('select_contest'))
        self.assertEqual(len(response.context['contests']), 2)
        self.assertContains(response, 'Visible Contest')
Esempio n. 8
0
    def test_contest_visibility(self):
        contest = Contest(id='visible', name='Visible Contest')
        contest.controller_name = 'oioioi.oi.controllers.OIContestController'
        contest.save()

        response = self.client.get(reverse('select_contest'))
        self.assertEqual(len(response.context['contests']), 2)
        self.assertIn('Visible Contest', response.content)

        response = self.client.get(reverse('select_contest'))
        self.assertEqual(len(response.context['contests']), 2)
        self.assertIn('Visible Contest', response.content)
Esempio n. 9
0
 def test_fields_autogeneration(self):
     contest = Contest()
     contest.save()
     self.assertEqual(contest.id, 'c1')
     round = Round(contest=contest)
     round.save()
     self.assertEqual(round.name, 'Round 1')
     round = Round(contest=contest)
     round.save()
     self.assertEqual(round.name, 'Round 2')
     problem = Problem()
     problem.save()
     pi = ProblemInstance(round=round, problem=problem)
     pi.save()
     self.assertEqual(pi.contest, contest)
Esempio n. 10
0
 def test_contest_visibility(self):
     invisible_contest = Contest(id='invisible', name='Invisible Contest',
         controller_name='oioioi.contests.tests.PrivateContestController')
     invisible_contest.save()
     response = self.client.get(reverse('select_contest'))
     self.assertIn('contests/select_contest.html',
             [t.name for t in response.templates])
     self.assertEqual(len(response.context['contests']), 1)
     self.client.login(username='******')
     response = self.client.get(reverse('select_contest'))
     self.assertEqual(len(response.context['contests']), 1)
     self.client.login(username='******')
     response = self.client.get(reverse('select_contest'))
     self.assertEqual(len(response.context['contests']), 2)
     self.assertIn('Invisible Contest', response.content)
Esempio n. 11
0
 def test_fields_autogeneration(self):
     contest = Contest()
     contest.save()
     self.assertEqual(contest.id, 'c1')
     round = Round(contest=contest)
     round.save()
     self.assertEqual(round.name, 'Round 1')
     round = Round(contest=contest)
     round.save()
     self.assertEqual(round.name, 'Round 2')
     problem = Problem()
     problem.save()
     pi = ProblemInstance(round=round, problem=problem)
     pi.save()
     self.assertEqual(pi.contest, contest)
Esempio n. 12
0
 def test_contest_visibility(self):
     invisible_contest = Contest(
         id='invisible',
         name='Invisible Contest',
         controller_name='oioioi.contests.tests.PrivateContestController')
     invisible_contest.save()
     response = self.client.get(reverse('select_contest'))
     self.assertIn('contests/select_contest.html',
                   [t.name for t in response.templates])
     self.assertEqual(len(response.context['contests']), 1)
     self.client.login(username='******')
     response = self.client.get(reverse('select_contest'))
     self.assertEqual(len(response.context['contests']), 1)
     self.client.login(username='******')
     response = self.client.get(reverse('select_contest'))
     self.assertEqual(len(response.context['contests']), 2)
     self.assertIn('Invisible Contest', response.content)
Esempio n. 13
0
    def test_mailsubmissions_list(self):
        c1 = Contest(id='contest1', name='Contest1', controller_name=
            'oioioi.participants.tests.ParticipantsContestController')
        c1.save()
        c2 = Contest(id='contest2', name='Contest2', controller_name=
            'oioioi.participants.tests.ParticipantsContestController')
        c2.save()
        p = Problem.objects.get()
        pi1 = ProblemInstance(contest=c1, problem=p,
            short_name='problem_instance1')
        pi1.save()
        pi2 = ProblemInstance(contest=c2, problem=p,
            short_name='problem_instance2')
        pi2.save()
        u = User.objects.get(username='******')
        f = ContentFile('aaa', name='bbbb.cpp')
        ms1 = MailSubmission(problem_instance=pi1, user=u)
        ms1.source_file.save(f.name, f)
        ms1.save()
        ms2 = MailSubmission(problem_instance=pi2, user=u)
        ms2.source_file.save(f.name, f)
        ms2.save()

        self.client.login(username='******')
        url = reverse('oioioiadmin:mailsubmit_mailsubmission_changelist',
            kwargs={'contest_id': 'contest1'})
        response = self.client.get(url)
        self.assertContains(response, 'problem_instance1')
        self.assertNotContains(response, 'problem_instance2')
        url = reverse('oioioiadmin:mailsubmit_mailsubmission_changelist',
            kwargs={'contest_id': 'contest2'})
        response = self.client.get(url)
        self.assertContains(response, 'problem_instance2')
        self.assertNotContains(response, 'problem_instance1')
Esempio n. 14
0
    def test_mailsubmissions_list(self):
        c1 = Contest(
            id='contest1',
            name='Contest1',
            controller_name='oioioi.participants.'
            'tests.ParticipantsContestController',
        )
        c1.save()
        c2 = Contest(
            id='contest2',
            name='Contest2',
            controller_name='oioioi.participants.'
            'tests.ParticipantsContestController',
        )
        c2.save()
        p = Problem.objects.get()
        pi1 = ProblemInstance(contest=c1,
                              problem=p,
                              short_name='problem_instance1')
        pi1.save()
        pi2 = ProblemInstance(contest=c2,
                              problem=p,
                              short_name='problem_instance2')
        pi2.save()
        u = User.objects.get(username='******')
        f = ContentFile(b'aaa', name='bbbb.cpp')
        ms1 = MailSubmission(problem_instance=pi1, user=u)
        ms1.source_file.save(f.name, f)
        ms1.save()
        ms2 = MailSubmission(problem_instance=pi2, user=u)
        ms2.source_file.save(f.name, f)
        ms2.save()

        self.assertTrue(self.client.login(username='******'))
        url = reverse(
            'oioioiadmin:mailsubmit_mailsubmission_changelist',
            kwargs={'contest_id': 'contest1'},
        )
        response = self.client.get(url)
        self.assertContains(response, 'problem_instance1')
        self.assertNotContains(response, 'problem_instance2')
        url = reverse(
            'oioioiadmin:mailsubmit_mailsubmission_changelist',
            kwargs={'contest_id': 'contest2'},
        )
        response = self.client.get(url)
        self.assertContains(response, 'problem_instance2')
        self.assertNotContains(response, 'problem_instance1')
Esempio n. 15
0
    def test_user_dashboard_full(self):
        user = User.objects.get(username='******')
        for i in range(10):
            c = Contest()
            c.name = 'tmp' + str(i)
            c.controller_name = 'oioioi.contests.controllers.ContestController'
            c.id = 'tmp' + str(i)
            c.save()

            make_user_contest_admin(user, c)

        self.assertTrue(self.client.login(username='******'))
        url = reverse('simpleui_user_dashboard')
        response = self.client.get(url)

        self.assertEqual(response.status_code, 200)
        self.assertContains(response, 'Show all contests')
Esempio n. 16
0
    def test_user_dashboard_full(self):
        user = User.objects.get(username='******')
        for i in range(10):
            c = Contest()
            c.name = 'tmp' + str(i)
            c.controller_name = \
                'oioioi.teachers.controllers.TeacherContestController'
            c.id = 'tmp' + str(i)
            c.save()

            cp = ContestPermission()
            cp.user = user
            cp.permission = 'contests.contest_admin'
            cp.contest = c
            cp.save()

        self.assertTrue(self.client.login(username='******'))
        url = reverse('simpleui_user_dashboard')
        response = self.client.get(url)

        self.assertEqual(response.status_code, 200)
        self.assertContains(response, 'Show all contests')
Esempio n. 17
0
    def test_teacher_dashboard_full(self):
        user = User.objects.get(username='******')
        for i in range(10):
            c = Contest()
            c.name = 'tmp' + str(i)
            c.controller_name = \
                'oioioi.teachers.controllers.TeacherContestController'
            c.id = 'tmp' + str(i)
            c.save()

            cp = ContestPermission()
            cp.user = user
            cp.permission = 'contests.contest_admin'
            cp.contest = c
            cp.save()

        self.assertTrue(self.client.login(username='******'))
        url = reverse('teacher_dashboard')
        response = self.client.get(url)

        self.assertEqual(response.status_code, 200)
        self.assertContains(response, 'Show all contests')
Esempio n. 18
0
    def test_add_from_selectcontest(self):
        contest2 = Contest(
            id='c2',
            name='Contest2',
            controller_name='oioioi.contests.tests.PrivateContestController')
        contest2.save()
        contest2.creation_date = datetime(2002, 1, 1, tzinfo=utc)
        contest2.save()
        contest3 = Contest(
            id='c3',
            name='Contest3',
            controller_name='oioioi.contests.tests.PrivateContestController')
        contest3.save()
        contest3.creation_date = datetime(2004, 1, 1, tzinfo=utc)
        contest3.save()
        contest4 = Contest(
            id='c4',
            name='Contest4',
            controller_name='oioioi.contests.tests.PrivateContestController')
        contest4.save()
        contest4.creation_date = datetime(2003, 1, 1, tzinfo=utc)
        contest4.save()

        self.client.login(username='******')
        # Now we're not having any contest in recent contests.
        # As we are contest administrator, the button should still appear.
        url = reverse('problemset_all_problems')
        response = self.client.get(url, follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertIn('All problems', str(response.content))
        self.assertEqual(response.content.count('/problemset/problem/'),
                         Problem.objects.count() * 2)
        self.assertEqual(response.content.count('Add to contest'),
                         Problem.objects.count())
        # But it shouldn't be able to fill the form
        self.assertNotIn('data-addorupdate', str(response.content))
        self.assertNotIn('data-urlkey', str(response.content))
        # And it should point to select_contest page
        self.assertIn('/problem/123/add_to_contest/?problem_name=sum',
                      str(response.content))
        # Follow the link...
        url = reverse('problemset_add_to_contest', kwargs={'site_key': '123'})
        url += '?problem_name=sum'
        response = self.client.get(url, follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertIn('to add the <code>sum</code> problem to',
                      str(response.content))
        # This time we should be able to fill the form
        self.assertIn('data-addorupdate', str(response.content))
        self.assertIn('data-urlkey', str(response.content))
        self.assertIn('add_to_contest', str(response.content))
        self.assertIn('123', str(response.content))
        self.assertEqual(len(response.context['administered_contests']), 4)
        self.assertEquals(
            list(response.context['administered_contests']),
            list(Contest.objects.order_by('-creation_date').all()))
        self.assertContains(response, 'Contest2', count=1)
        self.assertContains(response, 'Contest3', count=1)
        self.assertContains(response, 'Contest4', count=1)
        self.assertLess(response.content.index('Contest3'),
                        response.content.index('Contest4'))
        self.assertLess(response.content.index('Contest4'),
                        response.content.index('Contest2'))
Esempio n. 19
0
    def test_add_from_selectcontest(self):
        contest2 = Contest(id='c2', name='Contest2',
            controller_name='oioioi.contests.tests.PrivateContestController')
        contest2.save()
        contest2.creation_date = datetime(2002, 1, 1, tzinfo=utc)
        contest2.save()
        contest3 = Contest(id='c3', name='Contest3',
            controller_name='oioioi.contests.tests.PrivateContestController')
        contest3.save()
        contest3.creation_date = datetime(2004, 1, 1, tzinfo=utc)
        contest3.save()
        contest4 = Contest(id='c4', name='Contest4',
            controller_name='oioioi.contests.tests.PrivateContestController')
        contest4.save()
        contest4.creation_date = datetime(2003, 1, 1, tzinfo=utc)
        contest4.save()

        self.client.login(username='******')
        # Now we're not having any contest in recent contests.
        # As we are contest administrator, the button should still appear.
        url = reverse('problemset_all_problems')
        response = self.client.get(url, follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertIn('All problems', str(response.content))
        self.assertEqual(response.content.count('/problemset/problem/'),
                         Problem.objects.count() * 2)
        self.assertEqual(response.content.count('Add to contest'),
                         Problem.objects.count())
        # But it shouldn't be able to fill the form
        self.assertNotIn('data-addorupdate', str(response.content))
        self.assertNotIn('data-urlkey', str(response.content))
        # And it should point to select_contest page
        self.assertIn('/problem/123/add_to_contest/?problem_name=sum',
            str(response.content))
        # Follow the link...
        url = reverse('problemset_add_to_contest', kwargs={'site_key': '123'})
        url += '?problem_name=sum'
        response = self.client.get(url, follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertIn('to add sum problem to', str(response.content))
        # This time we should be able to fill the form
        self.assertIn('data-addorupdate', str(response.content))
        self.assertIn('data-urlkey', str(response.content))
        self.assertIn('add_to_contest', str(response.content))
        self.assertIn('123', str(response.content))
        self.assertEqual(len(response.context['administered_contests']), 4)
        self.assertEquals(list(response.context['administered_contests']),
            list(Contest.objects.order_by('-creation_date').all()))
        self.assertContains(response, 'Contest2', count=1)
        self.assertContains(response, 'Contest3', count=1)
        self.assertContains(response, 'Contest4', count=1)
        self.assertLess(response.content.index('Contest3'),
            response.content.index('Contest4'))
        self.assertLess(response.content.index('Contest4'),
            response.content.index('Contest2'))