示例#1
0
 def test_07_permission_04(self):
     # 7.a user can view his own detail in normal mode
     users = self.JUDGE_USERS + [self.NORMAL_USER]
     clients = self.JUDGE_CLIENTS + [self.NORMAL_CLIENT]
     contest_submissions = self.all_submisions_when_contest_running()
     self.stop_running_contest()
     #submission during contest
     for i, _ in enumerate(self.CONTEST_PROBLEMS):
         for j, client in enumerate(clients):
             for k, _ in enumerate(self.STATUSES):
                 idx = i*42+j*6+k
                 file_name, code = create_source_code(
                     CodeSubmitForm.SUBMIT_PATH, contest_submissions[idx].pk,
                     get_extension(contest_submissions[idx].language))
                 target_url = reverse('status:view_code',
                                      args=[contest_submissions[idx].pk])
                 response = client.get(target_url)
                 remove_file_if_exists(file_name)
                 self.assertContains(response, code)
     #submission after contest
     for problem in self.CONTEST_PROBLEMS:
         for i, user in enumerate(users):
             for status in self.STATUSES:
                 submission = create_submission(problem, user, status)
                 file_name, code = create_source_code(
                     CodeSubmitForm.SUBMIT_PATH, submission.pk,
                     get_extension(submission.language))
                 target_url = reverse('status:view_code', args=[submission.pk])
                 response = clients[i].get(target_url)
                 remove_file_if_exists(file_name)
                 self.assertContains(response, code)
示例#2
0
 def test_09_permission_06(self):
     # 9.in normal mode, contest owner/coowner can still view detail during the contest
     users = self.JUDGE_USERS + [self.NORMAL_USER]
     clients = self.JUDGE_CLIENTS[0:3]
     contest_submissions = self.all_submisions_when_contest_running()
     self.stop_running_contest()
     #submission during contest (permission is the same as the moment contest was running)
     for i, _ in enumerate(self.CONTEST_PROBLEMS):
         for j, _ in enumerate(users):
             for k, _ in enumerate(self.STATUSES):
                 idx = i*42+j*6+k
                 target_url = reverse('status:view_code',
                                      args=[contest_submissions[idx].pk])
                 for client in clients:
                     file_name, code = create_source_code(
                         CodeSubmitForm.SUBMIT_PATH, contest_submissions[idx].pk,
                         get_extension(contest_submissions[idx].language))
                     response = client.get(target_url)
                     remove_file_if_exists(file_name)
                     if j<3 or j>4:
                         self.assertContains(response, code)
                     else:
                         self.assertEqual(response.status_code, 403)
     # submission after contest (no permission to view detail)
     for problem in self.CONTEST_PROBLEMS:
         for j, user in enumerate(users):
             for status in self.STATUSES:
                 submission = create_submission(problem, user, status)
                 target_url = reverse('status:view_code', args=[submission.pk])
                 for p, client in enumerate(clients):
                     if p!=j:
                         response = client.get(target_url)
                         self.assertEqual(response.status_code, 403)
示例#3
0
def view_code(request, sid):
    try:
        submission = Submission.objects.get(id=sid)
        filename = '%s.%s' % (sid, get_extension(submission.language))
        if show_detail(submission, request.user):
            f = open('%s%s' % (CodeSubmitForm.SUBMIT_PATH, filename), 'r')
            code = f.read()
            f.close()
            codesubmitform = CodeSubmitForm(
                initial={
                    'code': code,
                    'pid': submission.problem.id,
                    'language': submission.language
                })
            problem_name = str(submission.problem)
            return render_index(request, 'users/submit.html', {
                'form': codesubmitform,
                'problem_name': problem_name
            })
        else:
            logger.warning('User %s attempt to view detail of SID %s' %
                           (request.user, sid))
            raise PermissionDenied(
                "You don't have permission to view detail of SID %s" % sid)
    except Submission.DoesNotExist:
        logger.warning('SID %s Not Found!' % sid)
        raise Http404('SID %s Not Found!' % sid)
    except IOError:
        logger.warning('File %s Not Found!' % filename)
        raise Http404('File %s Not Found!' % filename)
示例#4
0
 def test_03_file_not_found(self):
     # 3.code file related to the submission does not exist
     # Expectation: error 404
     submission = create_submission(
                     self.CONTEST_PROBLEMS[0], self.ADMIN_USER, self.STATUSES[0])
     target_url = reverse('status:view_code', args=[submission.pk])
     response = self.ADMIN_CLIENT.get(target_url)
     filename = '%s.%s' % (submission.pk, get_extension(submission.language))
     self.assertEqual(response.status_code, 404)
示例#5
0
 def test_04_permission_01(self):
     # 4.admin can see everyone's detail
     problem = self.CONTEST_PROBLEMS[0]
     users = [self.ADMIN_USER, self.JUDGE_USERS[0], self.JUDGE_USERS[1],
              self.JUDGE_USERS[3], self.JUDGE_USERS[5], self.NORMAL_USER]
     for i in range(len(self.STATUSES)):
         submission = create_submission(
             problem, users[i], self.STATUSES[i])
         file_name, code = create_source_code(
             CodeSubmitForm.SUBMIT_PATH, submission.pk,
             get_extension(submission.language))
         target_url = reverse('status:view_code', args=[submission.pk])
         response = self.ADMIN_CLIENT.get(target_url)
         remove_file_if_exists(file_name)
         self.assertContains(response, code)
示例#6
0
 def test_06_permission_03(self):
     # 6.during the contest, only owner/coowner can view contestants' detail
     users = self.JUDGE_USERS + [self.NORMAL_USER]
     clients = self.JUDGE_CLIENTS + [self.NORMAL_CLIENT]
     contest_submissions = []
     for problem in self.CONTEST_PROBLEMS:
         for i, user in enumerate(users):
             for status in self.STATUSES:
                 submission = create_submission(problem, user, status)
                 contest_submissions.append(submission)
                 for j, client in enumerate(clients):
                     file_name, code = create_source_code(
                         CodeSubmitForm.SUBMIT_PATH, submission.pk,
                         get_extension(submission.language))
                     target_url = reverse('status:view_code', args=[submission.pk])
                     response = client.get(target_url)
                     remove_file_if_exists(file_name)
                     if j<3 and (i<3 or i>4):
                         self.assertContains(response, code)
                     else:
                         self.assertEqual(response.status_code, 403)
示例#7
0
def view_code(request, sid):
    try:
        submission = Submission.objects.get(id=sid)
        filename = '%s.%s' % (sid, get_extension(submission.language))
        if show_detail(submission, request.user):
            f = open('%s%s' % (CodeSubmitForm.SUBMIT_PATH, filename), 'r')
            code = f.read()
            f.close()
            codesubmitform = CodeSubmitForm(
                initial={'code': code, 'pid': submission.problem.id, 'language': submission.language})
            problem_name = str(submission.problem)
            return render_index(request, 'users/submit.html',
                {'form': codesubmitform, 'problem_name': problem_name})
        else:
            logger.warning('User %s attempt to view detail of SID %s' % (request.user, sid))
            raise PermissionDenied("You don't have permission to view detail of SID %s" % sid)
    except Submission.DoesNotExist:
        logger.warning('SID %s Not Found!' % sid)
        raise Http404('SID %s Not Found!' % sid)
    except IOError:
        logger.warning('File %s Not Found!' % filename)
        raise Http404('File %s Not Found!' % filename)
示例#8
0
    def submit(self):
        pid = self.cleaned_data['pid']
        code = self.cleaned_data['code']
        language = self.cleaned_data['language']

        problem = Problem.objects.get(id=pid)
        problem.total_submission += 1
        problem.save()
        submission = Submission.objects.create(
            user=self.user,
            problem=problem,
            language=language)
        try:
            filename = '%s.%s' % (submission.id, file_info.get_extension(submission.language))
            f = open('%s%s' % (self.SUBMIT_PATH, filename), 'w')
            f.write(code.encode('utf-8'))
            f.close()
        except IOError:
            logger.warning('Sid %s fail to save code' % submission.id)

        if problem.judge_source == Problem.OTHER:
            submit_thread = Thread(target=submit_to_vjudge, args=(code, submission))
            submit_thread.start()
示例#9
0
    def submit(self):
        pid = self.cleaned_data['pid']
        code = self.cleaned_data['code']
        language = self.cleaned_data['language']

        problem = Problem.objects.get(id=pid)
        problem.total_submission += 1
        problem.save()
        submission = Submission.objects.create(
            user=self.user,
            problem=problem,
            language=language)
        try:
            filename = '%s.%s' % (
                submission.id, file_info.get_extension(submission.language))
            f = open('%s%s' % (self.SUBMIT_PATH, filename), 'w')
            f.write(code.encode('utf-8'))
            f.close()
        except IOError:
            logger.warning('Sid %s fail to save code' % submission.id)

        if problem.judge_source == Problem.OTHER:
            #  Send to other judge
            pass