def test_06_upload_partial_judge_code_and_header(self): # 6.using POST method with argument 'partial_judge_code' and 'partial_judge_header' # Expectation: upload partial judge code and header to server successfully problem = create_problem(self.JUDGE_USER) target_url = reverse('problem:edit', args=[problem.pk]) data = POST_data_of_editing_Problem(self.JUDGE_USER, judge_type=Problem.PARTIAL) file_ex = get_problem_file_extension(problem) partial_judge_code = create_judge_code('partial', problem.pk, file_ex) partial_judge_header = create_judge_code('partial', problem.pk, '.h') try: with open(partial_judge_code, 'r') as fp, open(partial_judge_header, 'r') as fp2: data['partial_judge_code'] = fp data['partial_judge_header'] = fp2 response = self.JUDGE_CLIENT.post(target_url, data=data, follow=True) except (IOError, OSError): print "Something went wrong when reading partial judge files for testing..." raise uploaded_partial_judge_code = '%s%s%s' % (PARTIAL_PATH, problem.pk, file_ex) uploaded_partial_judge_header = '%s%s.h' % (PARTIAL_PATH, problem.pk) try: compare_result = compare_local_and_uploaded_file( partial_judge_code, uploaded_partial_judge_code) compare_result2 = compare_local_and_uploaded_file( partial_judge_header, uploaded_partial_judge_header) except (IOError, OSError): raise finally: remove_file_if_exists(partial_judge_code) remove_file_if_exists(uploaded_partial_judge_code) remove_file_if_exists(partial_judge_header) remove_file_if_exists(uploaded_partial_judge_header) self.assertTrue(compare_result and compare_result2)
def test_05_upload_special_judge_code(self): # 5.using POST method with argument 'special_judge_code' # Expectation: upload special judge code to server successfully problem = create_problem(self.JUDGE_USER) target_url = reverse('problem:edit', args=[problem.pk]) data = POST_data_of_editing_Problem(self.JUDGE_USER, judge_type=Problem.SPECIAL) file_ex = get_problem_file_extension(problem) special_judge_code = create_judge_code('special', problem.pk, file_ex) try: with open(special_judge_code, 'r') as fp: data['special_judge_code'] = fp response = self.JUDGE_CLIENT.post(target_url, data=data, follow=True) except (IOError, OSError): print "Something went wrong when reading special judge files for testing..." raise uploaded_special_judge_code = '%s%s%s' % (SPECIAL_PATH, problem.pk, file_ex) try: compare_result = compare_local_and_uploaded_file( special_judge_code, uploaded_special_judge_code) except (IOError, OSError): raise finally: remove_file_if_exists(special_judge_code) remove_file_if_exists(uploaded_special_judge_code) self.assertTrue(compare_result)
def test_08_change_judge_type_02(self): # 8.changing judge type from partial judge to special judge # Expectation: remove all partial judge files with respect to this problem problem = create_problem(self.JUDGE_USER) target_url = reverse('problem:edit', args=[problem.pk]) data = POST_data_of_editing_Problem(self.JUDGE_USER, judge_type=Problem.PARTIAL) file_ex = get_problem_file_extension(problem) partial_judge_code = create_judge_code('partial', problem.pk, file_ex) partial_judge_header = create_judge_code('partial', problem.pk, '.h') try: with open(partial_judge_code, 'r') as fp, open(partial_judge_header, 'r') as fp2: data['partial_judge_code'] = fp data['partial_judge_header'] = fp2 response = self.JUDGE_CLIENT.post(target_url, data=data, follow=True) except (IOError, OSError): print "Something went wrong when reading partial judge files for testing..." raise data = POST_data_of_editing_Problem(self.JUDGE_USER, judge_type=Problem.SPECIAL) file_ex = get_problem_file_extension(problem) special_judge_code = create_judge_code('special', problem.pk, file_ex) try: with open(special_judge_code, 'r') as fp: data['special_judge_code'] = fp response = self.JUDGE_CLIENT.post(target_url, data=data, follow=True) except (IOError, OSError): print "Something went wrong when reading special judge files for testing..." raise uploaded_special_judge_code = '%s%s%s' % (SPECIAL_PATH, problem.pk, file_ex) uploaded_partial_judge_code = '%s%s%s' % (PARTIAL_PATH, problem.pk, file_ex) uploaded_partial_judge_header = '%s%s.h' % (PARTIAL_PATH, problem.pk) result = os.path.isfile(uploaded_partial_judge_code) result2 = os.path.isfile(uploaded_partial_judge_header) try: compare_result = compare_local_and_uploaded_file( special_judge_code, uploaded_special_judge_code) except (IOError, OSError): raise finally: remove_file_if_exists(special_judge_code) remove_file_if_exists(uploaded_special_judge_code) remove_file_if_exists(partial_judge_code) remove_file_if_exists(uploaded_partial_judge_code) remove_file_if_exists(partial_judge_header) remove_file_if_exists(uploaded_partial_judge_header) self.assertFalse(result) self.assertFalse(result2) self.assertTrue(compare_result)