Beispiel #1
0
    def test_submissions_visibility(self):
        contest = Contest.objects.get()
        url = reverse('my_submissions', kwargs={'contest_id': contest.id})
        self.client.login(username='******')
        with fake_time(datetime(2012, 8, 5, tzinfo=utc)):
            response = self.client.get(url)
            self.assertAllIn(['zad1', 'zad3', 'zad4'], response.content)
            self.assertNoneIn([
                'zad2',
            ], response.content)

            self.assertIn('contests/my_submissions.html',
                          [t.name for t in response.templates])
            self.assertEqual(response.content.count('<td>34</td>'), 2)

        with fake_time(datetime(2015, 8, 5, tzinfo=utc)):
            response = self.client.get(url)
            self.assertEqual(response.content.count('<td>34</td>'), 4)

        with fake_time(datetime(2012, 7, 31, 21, tzinfo=utc)):
            response = self.client.get(url)
            self.assertEqual(response.content.count('<td>34</td>'), 1)

        with fake_time(datetime(2012, 7, 31, 22, tzinfo=utc)):
            response = self.client.get(url)
            self.assertEqual(response.content.count('<td>34</td>'), 2)

        round4 = Round.objects.get(pk=4)
        user = User.objects.get(username='******')
        ext = RoundTimeExtension(user=user, round=round4, extra_time=60)
        ext.save()

        with fake_time(datetime(2012, 7, 31, 22, tzinfo=utc)):
            response = self.client.get(url)
            self.assertEqual(response.content.count('<td>34</td>'), 1)

        round4.end_date = datetime(2012, 8, 10, 0, 0, tzinfo=utc)
        round4.results_date = datetime(2012, 8, 10, 0, 10, tzinfo=utc)
        round4.save()

        ext.extra_time = 0
        ext.save()

        with fake_time(datetime(2012, 8, 10, 0, 5, tzinfo=utc)):
            response = self.client.get(url)
            self.assertEqual(response.content.count('<td>34</td>'), 1)

        ext.extra_time = 20
        ext.save()

        with fake_time(datetime(2012, 8, 10, 0, 15, tzinfo=utc)):
            response = self.client.get(url)
            self.assertEqual(response.content.count('<td>34</td>'), 1)

        with fake_time(datetime(2012, 8, 10, 0, 21, tzinfo=utc)):
            response = self.client.get(url)
            self.assertEqual(response.content.count('<td>34</td>'), 2)
Beispiel #2
0
    def test_submissions_visibility(self):
        contest = Contest.objects.get()
        url = reverse('my_submissions', kwargs={'contest_id': contest.id})
        self.client.login(username='******')
        with fake_time(datetime(2012, 8, 5, tzinfo=utc)):
            response = self.client.get(url)
            self.assertAllIn(['zad1', 'zad3', 'zad4'], response.content)
            self.assertNoneIn(['zad2', ], response.content)

            self.assertIn('contests/my_submissions.html',
                    [t.name for t in response.templates])
            self.assertEqual(response.content.count('<td>34</td>'), 2)

        with fake_time(datetime(2015, 8, 5, tzinfo=utc)):
            response = self.client.get(url)
            self.assertEqual(response.content.count('<td>34</td>'), 4)

        with fake_time(datetime(2012, 7, 31, 21, tzinfo=utc)):
            response = self.client.get(url)
            self.assertEqual(response.content.count('<td>34</td>'), 1)

        with fake_time(datetime(2012, 7, 31, 22, tzinfo=utc)):
            response = self.client.get(url)
            self.assertEqual(response.content.count('<td>34</td>'), 2)

        round4 = Round.objects.get(pk=4)
        user = User.objects.get(username='******')
        ext = RoundTimeExtension(user=user, round=round4, extra_time=60)
        ext.save()

        with fake_time(datetime(2012, 7, 31, 22, tzinfo=utc)):
            response = self.client.get(url)
            self.assertEqual(response.content.count('<td>34</td>'), 1)

        round4.end_date = datetime(2012, 8, 10, 0, 0, tzinfo=utc)
        round4.results_date = datetime(2012, 8, 10, 0, 10, tzinfo=utc)
        round4.save()

        ext.extra_time = 0
        ext.save()

        with fake_time(datetime(2012, 8, 10, 0, 5, tzinfo=utc)):
            response = self.client.get(url)
            self.assertEqual(response.content.count('<td>34</td>'), 1)

        ext.extra_time = 20
        ext.save()

        with fake_time(datetime(2012, 8, 10, 0, 15, tzinfo=utc)):
            response = self.client.get(url)
            self.assertEqual(response.content.count('<td>34</td>'), 1)

        with fake_time(datetime(2012, 8, 10, 0, 21, tzinfo=utc)):
            response = self.client.get(url)
            self.assertEqual(response.content.count('<td>34</td>'), 2)
Beispiel #3
0
    def test_round_time_extension(self):
        user = User.objects.get(username='******')
        r1 = Round.objects.get()
        RoundTimeExtension(user=user, round=r1, extra_time=10).save()

        with fake_time(datetime(2012, 8, 9, 23, 10, tzinfo=utc)):
            self.reveal_submit(1)
Beispiel #4
0
    def test_round_extension(self):
        contest = Contest.objects.get()
        round1 = Round.objects.get(pk=1)
        round2 = Round.objects.get(pk=2)
        problem_instance1 = ProblemInstance.objects.get(pk=1)
        problem_instance2 = ProblemInstance.objects.get(pk=2)
        self.assertTrue(problem_instance1.round == round1)
        self.assertTrue(problem_instance2.round == round2)
        round1.start_date = datetime(2012, 7, 31, tzinfo=utc)
        round1.end_date = datetime(2012, 8, 5, tzinfo=utc)
        round1.save()
        round2.start_date = datetime(2012, 8, 10, tzinfo=utc)
        round2.end_date = datetime(2012, 8, 12, tzinfo=utc)
        round2.save()

        user = User.objects.get(username='******')
        ext = RoundTimeExtension(user=user, round=round1, extra_time=10)
        ext.save()

        with fake_time(datetime(2012, 8, 5, 0, 5, tzinfo=utc)):
            self.client.login(username='******')
            response = self.submit_file(contest, problem_instance1)
            self.assertEqual(200, response.status_code)
            self.assertIn('Sorry, there are no problems', response.content)
            self.client.login(username='******')
            response = self.submit_file(contest, problem_instance1)
            self._assertSubmitted(contest, response)

        with fake_time(datetime(2012, 8, 5, 0, 11, tzinfo=utc)):
            response = self.submit_file(contest, problem_instance1)
            self.assertEqual(200, response.status_code)
            self.assertIn('Sorry, there are no problems', response.content)

        with fake_time(datetime(2012, 8, 12, 0, 5, tzinfo=utc)):
            response = self.submit_file(contest, problem_instance2)
            self.assertEqual(200, response.status_code)
            self.assertIn('Sorry, there are no problems', response.content)
Beispiel #5
0
    def test_round_extension(self):
        contest = Contest.objects.get()
        round1 = Round.objects.get(pk=1)
        round2 = Round.objects.get(pk=2)
        problem_instance1 = ProblemInstance.objects.get(pk=1)
        problem_instance2 = ProblemInstance.objects.get(pk=2)
        self.assertTrue(problem_instance1.round == round1)
        self.assertTrue(problem_instance2.round == round2)
        round1.start_date = datetime(2012, 7, 31, tzinfo=utc)
        round1.end_date = datetime(2012, 8, 5, tzinfo=utc)
        round1.save()
        round2.start_date = datetime(2012, 8, 10, tzinfo=utc)
        round2.end_date = datetime(2012, 8, 12, tzinfo=utc)
        round2.save()

        user = User.objects.get(username='******')
        ext = RoundTimeExtension(user=user, round=round1, extra_time=10)
        ext.save()

        with fake_time(datetime(2012, 8, 5, 0, 5, tzinfo=utc)):
            self.client.login(username='******')
            response = self.submit_file(contest, problem_instance1)
            self.assertEqual(200, response.status_code)
            self.assertIn('Sorry, there are no problems', response.content)
            self.client.login(username='******')
            response = self.submit_file(contest, problem_instance1)
            self._assertSubmitted(contest, response)

        with fake_time(datetime(2012, 8, 5, 0, 11, tzinfo=utc)):
            response = self.submit_file(contest, problem_instance1)
            self.assertEqual(200, response.status_code)
            self.assertIn('Sorry, there are no problems', response.content)

        with fake_time(datetime(2012, 8, 12, 0, 5, tzinfo=utc)):
            response = self.submit_file(contest, problem_instance2)
            self.assertEqual(200, response.status_code)
            self.assertIn('Sorry, there are no problems', response.content)
Beispiel #6
0
    def test_countdown_with_extended_rounds(self):
        contest = Contest.objects.get()
        now = time.time()
        r1_start = datetime.fromtimestamp(now - 5)
        r1_end = datetime.fromtimestamp(now + 10)
        r1 = Round(contest=contest, start_date=r1_start, end_date=r1_end)
        r1.save()
        user = User.objects.get(username='******')
        RoundTimeExtension(user=user, round=r1, extra_time=10).save()

        self.assertTrue(self.client.login(username='******'))
        response = self.client.get(
            reverse('get_status', kwargs={'contest_id': contest.id})).json()
        round_start_date = response['round_start_date']
        round_end_date = response['round_end_date']
        self.assertEqual(round_start_date, time.mktime(r1_start.timetuple()))
        self.assertEqual(round_end_date, time.mktime(r1_end.timetuple()) + 600)
Beispiel #7
0
    def extend_round(self, request, queryset):
        form = None

        if 'submit' in request.POST:
            form = ExtendRoundForm(request.contest, request.POST)

            if form.is_valid():
                round = form.cleaned_data['round']
                extra_time = form.cleaned_data['extra_time']

                users = [participant.user for participant in queryset]
                existing_extensions = RoundTimeExtension.objects \
                        .filter(round=round, user__in=users)
                for extension in existing_extensions:
                    extension.extra_time += extra_time
                    extension.save()
                existing_count = existing_extensions.count()

                new_extensions = [
                    RoundTimeExtension(user=user,
                                       round=round,
                                       extra_time=extra_time) for user in users
                    if not existing_extensions.filter(user=user).exists()
                ]
                RoundTimeExtension.objects.bulk_create(new_extensions)

                if existing_count:
                    if existing_count > 1:
                        name = capfirst(
                            RoundTimeExtension._meta.verbose_name_plural)
                    else:
                        name = RoundTimeExtension._meta.verbose_name
                    self.message_user(
                        request,
                        ungettext_lazy(
                            "Updated one %(name)s.",
                            "%(name)s updated: %(existing_count)d.",
                            existing_count) % {
                                'existing_count': existing_count,
                                'name': name
                            })
                if new_extensions:
                    if len(new_extensions) > 1:
                        name = capfirst(
                            RoundTimeExtension._meta.verbose_name_plural)
                    else:
                        name = RoundTimeExtension._meta.verbose_name
                    self.message_user(
                        request,
                        ungettext_lazy("Created one %(name)s.",
                                       "%(name)s created: %(new_count)d.",
                                       len(new_extensions)) % {
                                           'new_count': len(new_extensions),
                                           'name': name
                                       })

                return HttpResponseRedirect(request.get_full_path())

        if not form:
            form = ExtendRoundForm(
                request.contest,
                initial={'_selected_action': [p.id for p in queryset]})

        return TemplateResponse(request,
                                'admin/participants/extend_round.html',
                                {'form': form})