Exemple #1
0
    def test_ignored_submission(self):
        self.client.login(username='******')
        contest = Contest.objects.get()
        pi = ProblemInstance.objects.get()
        url = reverse('submit', kwargs={'contest_id': contest.id})
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)
        self.assertNotIn('IGNORED', response.content)

        data = {
            'problem_instance_id': pi.id,
            'file': open(get_test_filename('sum-various-results.cpp'), 'rb'),
        }
        response = self.client.post(url, data, follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(Submission.objects.count(), 1)
        submission = Submission.objects.get(pk=1)
        self.assertEqual(submission.user.username, 'test_observer')
        self.assertEqual(submission.kind, 'IGNORED')

        url = reverse('default_ranking', kwargs={'contest_id': contest.id})
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)
        self.assertNotIn('Test Observer', response.content)

        url = reverse('my_submissions', kwargs={'contest_id': contest.id})
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)
        self.assertIn('Ignored', response.content)
Exemple #2
0
    def test_submitting_as_self(self):
        self.client.login(username='******')
        contest = Contest.objects.get()
        pi = ProblemInstance.objects.get()
        url = reverse('submit', kwargs={'contest_id': contest.id})

        self.client.login(username='******')
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)
        self.assertIn('IGNORED', response.content)
        self.assertIn('NORMAL', response.content)

        f = open(get_test_filename('sum-various-results.cpp'), 'rb')
        data = {
            'problem_instance_id': pi.id,
            'file': f,
            'user': '******',
            'kind': 'NORMAL'
        }
        response = self.client.post(url, data, follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(Submission.objects.count(), 1)
        submission = Submission.objects.get(pk=1)
        self.assertEqual(submission.user.username, 'test_admin')
        self.assertEqual(submission.kind, 'NORMAL')

        ps = ProgramSubmission.objects.get(pk=1)
        f.seek(0, os.SEEK_END)
        self.assertEqual(ps.source_length, f.tell())

        url = reverse('default_ranking', kwargs={'contest_id': contest.id})
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)
        self.assertNotIn('Test Admin', response.content)
        self.assertIn('no one in this ranking', response.content)
Exemple #3
0
    def test_ignored_submission(self):
        self.client.login(username='******')
        contest = Contest.objects.get()
        pi = ProblemInstance.objects.get()
        url = reverse('submit', kwargs={'contest_id': contest.id})
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)
        self.assertNotIn('IGNORED', response.content)

        data = {
            'problem_instance_id': pi.id,
            'file': open(get_test_filename('sum-various-results.cpp'), 'rb'),
        }
        response = self.client.post(url, data, follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(Submission.objects.count(), 1)
        submission = Submission.objects.get(pk=1)
        self.assertEqual(submission.user.username, 'test_observer')
        self.assertEqual(submission.kind, 'IGNORED')

        url = reverse('default_ranking', kwargs={'contest_id': contest.id})
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)
        self.assertNotIn('Test Observer', response.content)

        url = reverse('my_submissions', kwargs={'contest_id': contest.id})
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)
        self.assertIn('(Ignored)', response.content)
Exemple #4
0
    def test_submitting_as_self(self):
        self.client.login(username='******')
        contest = Contest.objects.get()
        pi = ProblemInstance.objects.get()
        url = reverse('submit', kwargs={'contest_id': contest.id})

        self.client.login(username='******')
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)
        self.assertIn('IGNORED', response.content)
        self.assertIn('NORMAL', response.content)

        data = {
            'problem_instance_id': pi.id,
            'file': open(get_test_filename('sum-various-results.cpp'), 'rb'),
            'user': '******',
            'kind': 'NORMAL'
        }
        response = self.client.post(url, data, follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(Submission.objects.count(), 1)
        submission = Submission.objects.get(pk=1)
        self.assertEqual(submission.user.username, 'test_admin')
        self.assertEqual(submission.kind, 'NORMAL')

        url = reverse('default_ranking', kwargs={'contest_id': contest.id})
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)
        self.assertNotIn('Test Admin', response.content)
        self.assertIn('no one in this ranking', response.content)
Exemple #5
0
 def _submit_solution(self, user, source_file):
     url = reverse('submit', kwargs=self.c_kwargs)
     data = {
         'problem_instance_id': self.pi.id,
         'file': open(get_test_filename(source_file), 'rb'),
         'user': user.username,
         'kind': 'NORMAL'
     }
     return self.client.post(url, data)
Exemple #6
0
    def test_upload_package(self):
        ProblemInstance.objects.all().delete()

        contest = Contest.objects.get()
        filename = get_test_filename('test_simple_package.zip')
        self.client.login(username='******')
        url = reverse('oioioi.problems.views.add_or_update_problem_view',
                kwargs={'contest_id': contest.id}) + '?' + \
                        urllib.urlencode({'key': 'zeus'})
        data = {
            'package_file': open(filename, 'rb'),
            'zeus_id': 'dummy',
            'zeus_problem_id': 1,
        }
        response = self.client.post(url, data, follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(Problem.objects.count(), 1)
        self.assertEqual(ProblemInstance.objects.count(), 2)
        self.assertEqual(ZeusProblemData.objects.count(), 1)
Exemple #7
0
    def test_upload_package(self):
        ProblemInstance.objects.all().delete()

        contest = Contest.objects.get()
        filename = get_test_filename('test_simple_package.zip')
        self.client.login(username='******')
        url = reverse('oioioi.problems.views.add_or_update_problem_view',
                kwargs={'contest_id': contest.id}) + '?' + \
                        six.moves.urllib.parse.urlencode({'key': 'zeus'})
        data = {
            'package_file': open(filename, 'rb'),
            'zeus_id': 'dummy',
            'zeus_problem_id': 1,
        }
        response = self.client.post(url, data, follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(Problem.objects.count(), 1)
        self.assertEqual(ProblemInstance.objects.count(), 2)
        self.assertEqual(ZeusProblemData.objects.count(), 1)
        self.assertEqual(SavedEnviron.objects.count(), 2)
Exemple #8
0
    def test_missing_permission(self):
        contest = Contest.objects.get()
        contest.controller_name = \
                'oioioi.programs.tests.PrivateProgrammingContestController'
        contest.save()
        pi = ProblemInstance.objects.get()
        url = reverse('submit', kwargs={'contest_id': contest.id})

        self.client.login(username='******')
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)
        self.assertIn('IGNORED', response.content)

        data = {
            'problem_instance_id': pi.id,
            'file': open(get_test_filename('sum-various-results.cpp'), 'rb'),
            'user': '******',
            'kind': 'NORMAL'
        }
        response = self.client.post(url, data, follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(Submission.objects.count(), 0)
        self.assertIn('enough privileges', response.content)
Exemple #9
0
    def test_missing_permission(self):
        contest = Contest.objects.get()
        contest.controller_name = \
                'oioioi.programs.tests.PrivateProgrammingContestController'
        contest.save()
        pi = ProblemInstance.objects.get()
        url = reverse('submit', kwargs={'contest_id': contest.id})

        self.client.login(username='******')
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)
        self.assertIn('IGNORED', response.content)

        data = {
            'problem_instance_id': pi.id,
            'file': open(get_test_filename('sum-various-results.cpp'), 'rb'),
            'user': '******',
            'kind': 'NORMAL'
        }
        response = self.client.post(url, data, follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(Submission.objects.count(), 0)
        self.assertIn('enough privileges', response.content)
Exemple #10
0
    def test_report_after_generate(self):
        self.client.login(username='******')
        contest = Contest.objects.get()
        submission = ProgramSubmission.objects.get(pk=1)
        url = reverse('submission', kwargs={'contest_id': contest.id,
                                            'submission_id': submission.id})
        # test generate out href visibility
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.content.count('[generate out]'), 2)
        self.assertEqual(response.content.count('Generate all'), 4)

        # test download out href visibility
        testreport = TestReport.objects.get(pk=6)
        # path to any existing file
        testreport.output_file = get_test_filename('sum-various-results.cpp')
        testreport.save()
        response = self.client.get(url)
        self.assertEqual(response.content.count('[generate out]'), 1)
        self.assertEqual(response.content.count('[download out]'), 1)

        # test filtering reports to generate user outs
        factory = RequestFactory()
        request = factory.request()
        request.contest = contest
        request.user = User.objects.get(username='******')

        # test filtering and setting as processing test reports
        testreports = TestReport.objects.filter(submission_report=2)
        filtered = _testreports_to_generate_outs(request, testreports)
        # note that report with pk=6 related with test pk=3 has got
        # assigned output, so 3 lefts; 2 of them has AC status
        self.assertEqual(filtered, [2, 6, 5])
        # now all of that three are processing
        response = self.client.get(url)
        self.assertEqual(response.content.count('[processing]'), 1)
        filtered = _testreports_to_generate_outs(request, testreports)
        self.assertEqual(filtered, [])

        # test report visibility for user without permission
        self.client.login(username='******')
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)
        self.assertNotIn('[processing]', response.content)
        self.assertNotIn('Generate all', response.content)

        # test report visibility for user with permission
        ReportActionsConfig(problem=submission.problem_instance.problem,
                            can_user_generate_outs=True).save()
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)
        # Note that 3 test are processing (by admin), what user does not see
        self.assertEqual(response.content.count('Processing'), 0)
        self.assertEqual(response.content.count('[generate out]'), 1)
        # one test has assigned output (e.g. generated by system)
        self.assertEqual(response.content.count('[download out]'), 1)
        self.assertEqual(response.content.count('Generate all'), 4)

        # clicking generate on test which is already generated but by admin
        gen_url = reverse('generate_user_output', kwargs={'testreport_id': 5})
        response = self.client.post(gen_url, follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.content.count('[generate out]'), 0)
        self.assertEqual(response.content.count('[processing]'), 1)