Esempio n. 1
0
    def test_simple_mailsubmission(self):
        contest = Contest.objects.get()
        problem_instance = ProblemInstance.objects.get()
        problem_instance.submissions_limit = 0
        problem_instance.save()
        round = Round.objects.get()
        round.start_date = datetime(2012, 7, 31, tzinfo=utc)
        round.end_date = datetime(2012, 8, 10, tzinfo=utc)
        round.save()
        msc = MailSubmissionConfig(
            contest=contest,
            enabled=True,
            start_date=datetime(2012, 8, 12, tzinfo=utc),
            end_date=datetime(2012, 8, 14, tzinfo=utc),
        )
        msc.save()

        with fake_time(datetime(2012, 8, 11, tzinfo=utc)):
            response = self.submit_file(contest, problem_instance)
            self.assertEqual(403, response.status_code)

        self.assertEqual(MailSubmission.objects.count(), 0)

        with fake_time(datetime(2012, 8, 13, tzinfo=utc)):
            response = self.submit_file(contest, problem_instance)
            self.assertEqual(200, response.status_code)

        self.assertEqual(MailSubmission.objects.count(), 1)

        with fake_time(datetime(2012, 8, 15, tzinfo=utc)):
            response = self.submit_file(contest, problem_instance)
            self.assertEqual(403, response.status_code)

        self.assertEqual(MailSubmission.objects.count(), 1)
Esempio n. 2
0
    def test_simple_mailsubmission(self):
        contest = Contest.objects.get()
        problem_instance = ProblemInstance.objects.get()
        problem_instance.submissions_limit = 0
        problem_instance.save()
        round = Round.objects.get()
        round.start_date = datetime(2012, 7, 31, tzinfo=utc)
        round.end_date = datetime(2012, 8, 10, tzinfo=utc)
        round.save()
        msc = MailSubmissionConfig(contest=contest, enabled=True,
                start_date=datetime(2012, 8, 12, tzinfo=utc),
                end_date=datetime(2012, 8, 14, tzinfo=utc))
        msc.save()

        with fake_time(datetime(2012, 8, 11, tzinfo=utc)):
            response = self.submit_file(contest, problem_instance)
            self.assertEqual(403, response.status_code)

        self.assertEqual(MailSubmission.objects.count(), 0)

        with fake_time(datetime(2012, 8, 13, tzinfo=utc)):
            response = self.submit_file(contest, problem_instance)
            self.assertEqual(200, response.status_code)

        self.assertEqual(MailSubmission.objects.count(), 1)

        with fake_time(datetime(2012, 8, 15, tzinfo=utc)):
            response = self.submit_file(contest, problem_instance)
            self.assertEqual(403, response.status_code)

        self.assertEqual(MailSubmission.objects.count(), 1)
Esempio n. 3
0
    def test_accepting_mailsubmissions(self):
        contest = Contest.objects.get()
        problem_instance = ProblemInstance.objects.get()
        problem_instance.submissions_limit = 0
        problem_instance.save()
        round = Round.objects.get()
        round.start_date = datetime(2012, 7, 31, tzinfo=utc)
        round.end_date = datetime(2012, 8, 10, tzinfo=utc)
        round.save()
        msc = MailSubmissionConfig(
            contest=contest,
            enabled=True,
            start_date=datetime(2012, 8, 12, tzinfo=utc),
            end_date=datetime(2012, 8, 14, tzinfo=utc),
        )
        msc.save()

        with fake_time(datetime(2012, 8, 13, tzinfo=utc)):
            response = self.submit_file(contest, problem_instance)
            self.assertEqual(200, response.status_code)

        self.assertEqual(MailSubmission.objects.count(), 1)
        ms = MailSubmission.objects.get()
        _ms_source_hash, ms_submission_hash = mail_submission_hashes(ms)

        self.assertEqual(Submission.objects.count(), 0)

        url = reverse('accept_mailsubmission_default',
                      kwargs={'contest_id': contest.id})
        valid_post_data = {
            'mailsubmission_id': ms.id,
            'submission_hash': ms_submission_hash,
        }
        invalid_post_data = {
            'mailsubmission_id': ms.id,
            'submission_hash': 'ABCDE'
        }

        response = self.client.post(url, valid_post_data)
        self.assertEqual(403, response.status_code)
        self.assertEqual(Submission.objects.count(), 0)

        self.assertTrue(self.client.login(username='******'))
        response = self.client.post(url, invalid_post_data)
        self.assertEqual(200, response.status_code)
        self.assertContains(response, 'Invalid confirmation code')
        self.assertEqual(Submission.objects.count(), 0)

        response = self.client.post(url, valid_post_data, follow=True)
        self.assertEqual(200, response.status_code)
        self.assertEqual(Submission.objects.count(), 1)
        response = self.client.post(url, valid_post_data, follow=True)
        self.assertEqual(200, response.status_code)
        self.assertContains(response, 'already accepted')
        ms = MailSubmission.objects.get()
        self.assertEqual(ms.accepted_by,
                         User.objects.get(username='******'))
Esempio n. 4
0
    def test_accepting_mailsubmissions(self):
        contest = Contest.objects.get()
        problem_instance = ProblemInstance.objects.get()
        problem_instance.submissions_limit = 0
        problem_instance.save()
        round = Round.objects.get()
        round.start_date = datetime(2012, 7, 31, tzinfo=utc)
        round.end_date = datetime(2012, 8, 10, tzinfo=utc)
        round.save()
        msc = MailSubmissionConfig(contest=contest, enabled=True,
                start_date=datetime(2012, 8, 12, tzinfo=utc),
                end_date=datetime(2012, 8, 14, tzinfo=utc))
        msc.save()

        with fake_time(datetime(2012, 8, 13, tzinfo=utc)):
            response = self.submit_file(contest, problem_instance)
            self.assertEqual(200, response.status_code)

        self.assertEqual(MailSubmission.objects.count(), 1)
        ms = MailSubmission.objects.get()
        _ms_source_hash, ms_submission_hash = mail_submission_hashes(ms)

        self.assertEqual(Submission.objects.count(), 0)

        url = reverse('accept_mailsubmission_default',
                      kwargs={'contest_id': contest.id})
        valid_post_data = {
            'mailsubmission_id': ms.id,
            'submission_hash': ms_submission_hash
        }
        invalid_post_data = {
            'mailsubmission_id': ms.id,
            'submission_hash': 'ABCDE'
        }

        response = self.client.post(url, valid_post_data)
        self.assertEqual(403, response.status_code)
        self.assertEqual(Submission.objects.count(), 0)

        self.client.login(username='******')
        response = self.client.post(url, invalid_post_data)
        self.assertEqual(200, response.status_code)
        self.assertIn('Invalid confirmation code', response.content)
        self.assertEqual(Submission.objects.count(), 0)

        response = self.client.post(url, valid_post_data, follow=True)
        self.assertEqual(200, response.status_code)
        self.assertEqual(Submission.objects.count(), 1)
        response = self.client.post(url, valid_post_data, follow=True)
        self.assertEqual(200, response.status_code)
        self.assertIn('already accepted', response.content)
        ms = MailSubmission.objects.get()
        self.assertEqual(ms.accepted_by,
                         User.objects.get(username='******'))
Esempio n. 5
0
    def test_mailsubmit_permissions(self):
        contest = Contest.objects.get()
        contest.controller_name = (
            'oioioi.participants.tests.ParticipantsContestController'
        )
        contest.save()

        problem_instance = ProblemInstance.objects.get()
        problem_instance.submissions_limit = 0
        problem_instance.save()
        round = Round.objects.get()
        round.start_date = datetime(2012, 7, 31, tzinfo=utc)
        round.end_date = datetime(2012, 8, 10, tzinfo=utc)
        round.save()
        msc = MailSubmissionConfig(
            contest=contest,
            enabled=True,
            start_date=datetime(2012, 8, 12, tzinfo=utc),
            end_date=datetime(2012, 8, 14, tzinfo=utc),
        )
        msc.save()

        user = User.objects.get(username='******')
        p = Participant(contest=contest, user=user, status='BANNED')
        p.save()

        with fake_time(datetime(2012, 8, 13, 0, 5, tzinfo=utc)):
            self.assertTrue(self.client.login(username='******'))
            response = self.submit_file(contest, problem_instance)
            self.assertEqual(403, response.status_code)

            self.assertTrue(self.client.login(username='******'))
            response = self.submit_file(contest, problem_instance)
            self.assertEqual(403, response.status_code)

            p.status = 'ACTIVE'
            p.save()

            self.assertEqual(MailSubmission.objects.count(), 0)

            self.assertTrue(self.client.login(username='******'))
            response = self.submit_file(contest, problem_instance)
            self.assertEqual(200, response.status_code)

            self.assertEqual(MailSubmission.objects.count(), 1)
Esempio n. 6
0
    def test_mailsubmit_permissions(self):
        contest = Contest.objects.get()
        contest.controller_name = \
            'oioioi.participants.tests.ParticipantsContestController'
        contest.save()

        problem_instance = ProblemInstance.objects.get()
        problem_instance.submissions_limit = 0
        problem_instance.save()
        round = Round.objects.get()
        round.start_date = datetime(2012, 7, 31, tzinfo=utc)
        round.end_date = datetime(2012, 8, 10, tzinfo=utc)
        round.save()
        msc = MailSubmissionConfig(contest=contest, enabled=True,
                start_date=datetime(2012, 8, 12, tzinfo=utc),
                end_date=datetime(2012, 8, 14, tzinfo=utc))
        msc.save()

        user = User.objects.get(username='******')
        p = Participant(contest=contest, user=user, status='BANNED')
        p.save()

        with fake_time(datetime(2012, 8, 13, 0, 5, tzinfo=utc)):
            self.client.login(username='******')
            response = self.submit_file(contest, problem_instance)
            self.assertEqual(403, response.status_code)

            self.client.login(username='******')
            response = self.submit_file(contest, problem_instance)
            self.assertEqual(403, response.status_code)

            p.status = 'ACTIVE'
            p.save()

            self.assertEqual(MailSubmission.objects.count(), 0)

            self.client.login(username='******')
            response = self.submit_file(contest, problem_instance)
            self.assertEqual(200, response.status_code)

            self.assertEqual(MailSubmission.objects.count(), 1)