Пример #1
0
 def test_contest_clean(self):
     _now = timezone.now()
     contest = create_contest(
         key='contest',
         start_time=_now,
         end_time=_now - timezone.timedelta(days=1),
         problem_label_script='invalid',
         format_config={'invalid': 'invalid'},
     )
     with self.assertRaisesRegex(ValidationError, 'ended before it starts'):
         contest.full_clean()
     contest.end_time = _now
     with self.assertRaisesRegex(ValidationError, 'ended before it starts'):
         contest.full_clean()
     contest.end_time = _now + timezone.timedelta(days=1)
     with self.assertRaisesRegex(ValidationError, 'default contest expects'):
         contest.full_clean()
     contest.format_config = {}
     with self.assertRaisesRegex(ValidationError, 'Contest problem label script'):
         contest.full_clean()
     contest.problem_label_script = '''
         function(n)
             return n
         end
     '''
     # Test for bad problem label script caching
     with self.assertRaisesRegex(ValidationError, 'Contest problem label script'):
         contest.full_clean()
     del contest.get_label_for_problem
     with self.assertRaisesRegex(ValidationError, 'should return a string'):
         contest.full_clean()
     contest.problem_label_script = ''
     del contest.get_label_for_problem
     contest.full_clean()
Пример #2
0
 def test_update_contest(self):
     _now = timezone.now()
     for contest in (
             create_contest(
                 key='finished_contest',
                 start_time=_now - timezone.timedelta(days=100),
                 end_time=_now - timezone.timedelta(days=10),
                 is_visible=True,
             ),
             create_contest(
                 key='inaccessible_contest',
                 start_time=_now - timezone.timedelta(days=100),
                 end_time=_now + timezone.timedelta(days=10),
             ),
     ):
         with self.subTest(name=contest.name):
             self.profile.current_contest = create_contest_participation(
                 contest=contest,
                 user=self.profile,
             )
             self.assertIsNotNone(self.profile.current_contest)
             self.profile.update_contest()
             self.assertIsNone(self.profile.current_contest)
Пример #3
0
    def setUpTestData(self):
        super().setUpTestData()
        self.users.update({
            'staff_contest_edit_own': create_user(
                username='******',
                is_staff=True,
                user_permissions=('edit_own_contest',),
            ),
            'staff_contest_see_all': create_user(
                username='******',
                user_permissions=('see_private_contest',),
            ),
            'staff_contest_edit_all': create_user(
                username='******',
                is_staff=True,
                user_permissions=('edit_own_contest', 'edit_all_contest'),
            ),
            'normal_during_window': create_user(
                username='******',
            ),
            'normal_after_window': create_user(
                username='******',
            ),
            'normal_before_window': create_user(
                username='******',
            ),
        })

        _now = timezone.now()

        self.basic_contest = create_contest(
            key='basic',
            start_time=_now - timezone.timedelta(days=1),
            end_time=_now + timezone.timedelta(days=100),
            organizers=('superuser', 'staff_contest_edit_own'),
        )

        self.hidden_scoreboard_contest = create_contest(
            key='hidden_scoreboard',
            start_time=_now - timezone.timedelta(days=1),
            end_time=_now + timezone.timedelta(days=100),
            is_visible=True,
            scoreboard_visibility=Contest.SCOREBOARD_AFTER_CONTEST,
            problem_label_script='''
                function(n)
                    return tostring(math.floor(n))
                end
            ''',
        )

        self.contest_hidden_scoreboard_contest = create_contest(
            key='contest_scoreboard',
            start_time=_now - timezone.timedelta(days=10),
            end_time=_now + timezone.timedelta(days=100),
            time_limit=timezone.timedelta(days=1),
            is_visible=True,
            scoreboard_visibility=Contest.SCOREBOARD_AFTER_CONTEST,
        )

        self.particip_hidden_scoreboard_contest = create_contest(
            key='particip_scoreboard',
            start_time=_now - timezone.timedelta(days=10),
            end_time=_now + timezone.timedelta(days=100),
            time_limit=timezone.timedelta(days=1),
            is_visible=True,
            scoreboard_visibility=Contest.SCOREBOARD_AFTER_PARTICIPATION,
        )

        self.visible_scoreboard_contest = create_contest(
            key='visible_scoreboard',
            start_time=_now - timezone.timedelta(days=10),
            end_time=_now + timezone.timedelta(days=100),
            time_limit=timezone.timedelta(days=1),
            is_visible=True,
            scoreboard_visibility=Contest.SCOREBOARD_VISIBLE,
        )

        for contest_key in ('contest_scoreboard', 'particip_scoreboard', 'visible_scoreboard'):
            create_contest_participation(
                contest=contest_key,
                user='******',
                real_start=_now - timezone.timedelta(hours=1),
                virtual=ContestParticipation.LIVE,
            )

            create_contest_participation(
                contest=contest_key,
                user='******',
                real_start=_now - timezone.timedelta(days=3),
                virtual=ContestParticipation.LIVE,
            )

        create_contest_participation(
            contest='particip_scoreboard',
            user='******',
            real_start=_now - timezone.timedelta(days=3),
            virtual=ContestParticipation.LIVE,
        )

        create_contest_participation(
            contest='particip_scoreboard',
            user='******',
            real_start=_now + timezone.timedelta(days=101),
            virtual=ContestParticipation.SPECTATE,
        )

        self.users['normal'].profile.current_contest = create_contest_participation(
            contest='hidden_scoreboard',
            user='******',
        )
        self.users['normal'].profile.save()

        self.hidden_scoreboard_contest.update_user_count()

        self.private_contest = create_contest(
            key='private',
            start_time=_now - timezone.timedelta(days=5),
            end_time=_now - timezone.timedelta(days=3),
            is_visible=True,
            is_private=True,
            is_organization_private=True,
            private_contestants=('staff_contest_edit_own',),
        )

        self.organization_private_contest = create_contest(
            key='organization_private',
            start_time=_now + timezone.timedelta(days=3),
            end_time=_now + timezone.timedelta(days=6),
            is_visible=True,
            is_organization_private=True,
            organizations=('open',),
            view_contest_scoreboard=('normal',),
        )

        self.private_user_contest = create_contest(
            key='private_user',
            start_time=_now - timezone.timedelta(days=3),
            end_time=_now + timezone.timedelta(days=6),
            is_visible=True,
            is_private=True,
        )
Пример #4
0
    def setUpTestData(self):
        super().setUpTestData()
        self.users.update({
            'staff_contest_edit_own':
            create_user(
                username='******',
                is_staff=True,
                user_permissions=('edit_own_contest', ),
            ),
            'staff_contest_see_all':
            create_user(
                username='******',
                user_permissions=('see_private_contest', ),
            ),
            'staff_contest_edit_all':
            create_user(
                username='******',
                is_staff=True,
                user_permissions=('edit_own_contest', 'edit_all_contest'),
            ),
        })

        _now = timezone.now()

        self.basic_contest = create_contest(
            key='basic',
            start_time=_now - timezone.timedelta(days=1),
            end_time=_now + timezone.timedelta(days=100),
            organizers=('superuser', 'staff_contest_edit_own'),
        )

        self.hidden_scoreboard_contest = create_contest(
            key='hidden_scoreboard',
            start_time=_now - timezone.timedelta(days=1),
            end_time=_now + timezone.timedelta(days=100),
            is_visible=True,
            hide_scoreboard=True,
            problem_label_script='''
                function(n)
                    return tostring(math.floor(n))
                end
            ''',
        )

        self.users[
            'normal'].profile.current_contest = create_contest_participation(
                contest='hidden_scoreboard',
                user='******',
            )
        self.users['normal'].profile.save()

        self.hidden_scoreboard_contest.update_user_count()

        self.private_contest = create_contest(
            key='private',
            start_time=_now - timezone.timedelta(days=5),
            end_time=_now - timezone.timedelta(days=3),
            is_visible=True,
            is_private=True,
            is_organization_private=True,
            private_contestants=('staff_contest_edit_own', ),
        )

        self.organization_private_contest = create_contest(
            key='organization_private',
            start_time=_now + timezone.timedelta(days=3),
            end_time=_now + timezone.timedelta(days=6),
            is_visible=True,
            is_organization_private=True,
            organizations=('open', ),
            view_contest_scoreboard=('normal', ),
        )

        self.private_user_contest = create_contest(
            key='private_user',
            start_time=_now - timezone.timedelta(days=3),
            end_time=_now + timezone.timedelta(days=6),
            is_visible=True,
            is_private=True,
        )
Пример #5
0
    def setUpTestData(self):
        super().setUpTestData()

        self.users.update({
            'staff_submission_view_all':
            create_user(
                username='******',
                is_staff=True,
                user_permissions=('view_all_submission', ),
            ),
        })

        self.basic_submission = Submission.objects.create(
            user=self.users['normal'].profile,
            problem=create_problem(code='basic'),
            language=Language.get_python3(),
            result='AC',
            status='D',
            case_points=99,
            case_total=100,
            memory=20,
            locked_after=None,
        )

        self.full_ac_submission = Submission.objects.create(
            user=self.users['normal'].profile,
            problem=create_problem(code='full_ac'),
            language=Language.get_python3(),
            result='AC',
            status='D',
            case_points=1,
            case_total=1,
        )
        self.full_ac_submission_source = SubmissionSource.objects.create(
            submission=self.full_ac_submission,
            source='',
        )

        self.locked_submission = Submission.objects.create(
            user=self.users['normal'].profile,
            problem=create_problem(code='locked'),
            language=Language.get_python3(),
            result='WA',
            status='D',
            case_points=1,
            case_total=1,
            locked_after=timezone.now() - timezone.timedelta(days=100),
        )

        self.future_locked_submission = Submission.objects.create(
            user=self.users['normal'].profile,
            problem=create_problem(code='future_locked'),
            language=Language.get_python3(),
            result='WA',
            status='D',
            case_points=1,
            case_total=1,
            locked_after=timezone.now() + timezone.timedelta(days=100),
        )

        self.ie_submission = Submission.objects.create(
            user=self.users['superuser'].profile,
            problem=create_problem(
                code='ie',
                is_public=True,
            ),
            language=Language.get_python3(),
            result='IE',
            status='IE',
            memory=None,
        )

        # jump down the rabbit hole to attach a contest submission
        problem = create_problem(code='queued')
        contest = create_contest(key='queued')
        self.queued_submission = Submission.objects.create(
            user=self.users['superuser'].profile,
            problem=problem,
            language=Language.get_python3(),
            contest_object=contest,
            case_points=50,
            case_total=100,
        )
        self.queued_contest_submission = ContestSubmission.objects.create(
            submission=self.queued_submission,
            problem=create_contest_problem(problem=problem,
                                           contest=contest,
                                           partial=False),
            participation=create_contest_participation(contest=contest,
                                                       user='******'),
        )