def test_soltuion_create(self): problem = Problem(desc="For test", input_desc="For test", output_desc="Fore test", pid="ITP1_6_B", objective=1) problem.save() problem_id = problem.to_dict()['id'] solution_body = { "erase_cnt": 12, "elapsed_time": 30.0, "evaluation": 66.0, "code": "n=int(input())\na=[[0 for i in range(13)]for j in range(4)]\nfor k in range(n):\ncard=input().split()\np=5\nif (card[0]=='S'):\np=0\nelif (card[0]=='H':\np=1\nelif (card[0]=='C'):\np=2\nelse:\np=3\nq=int(card[1])-1\na[p][q]=1\nfor i in range(4):\nfor j in range(13):\nif a[i][j]==0:\ntype=''\nif i==0 :\ntype='S'\nelif i==1:\ntype='H'\nelif i==2:\ntype='C'\nelse:\ntype='D'\nprint('{0} {1}'.format(type,j+1))", } response = self.client.post( f"/api/problem/{problem_id}/solution/", json.dumps(solution_body), content_type="application/json", ) self.assertEqual(response.status_code, 201) self.assertEqual(len(Solution.objects.all()), 1)
def get(self, request, remote_oj, remote_id, **kwargs): remote_oj = Controller.get_real_remote_oj(remote_oj) if not Controller.is_support(remote_oj): return Response(res_format('remote_oj not valid', status=Message.ERROR), status=status.HTTP_200_OK) if not remote_id.isalnum(): return Response(res_format('remote_id not valid', status=Message.ERROR), status=status.HTTP_200_OK) try: problem = Problem.objects.get(remote_oj=remote_oj, remote_id=remote_id) if problem.request_status in [ Spider_Problem.Status.STATUS_SUBMIT_FAILED.value, Spider_Problem.Status.STATUS_PROBLEM_NOT_EXIST.value, Spider_Problem.Status.STATUS_NO_ACCOUNT.value, Spider_Problem.Status.STATUS_PARSE_ERROR.value ]: get_problem_task.delay(problem.id) except ObjectDoesNotExist: try: problem = Problem( remote_oj=remote_oj, remote_id=remote_id, request_status=Spider_Problem.Status.STATUS_PENDING.value) problem.save() get_problem_task.delay(problem.id) except IntegrityError: return Response(res_format('System error', Message.ERROR), status=status.HTTP_200_OK) return Response(res_format(ProblemSerializer(problem).data), status=status.HTTP_200_OK)
def test_solution_for_others_view(self): user = User.objects.create_user(username="******", password="******", email="*****@*****.**", salt="123", role=1) client2 = Client() client2.login(username="******", password="******") problem = Problem(desc="For test", input_desc="For test", output_desc="Fore test", pid="ITP1_6_B", objective=1) problem.save() problem_id = problem.to_dict()['id'] solution_body = { "erase_cnt": 12, "elapsed_time": 30, "code": "n=int(input())\na=", "evaluation": 60, } client2.post( f"/api/problem/{problem_id}/solution/", json.dumps(solution_body), content_type="application/json", ) res = self.client.get(f"/api/problem/{problem_id}/solution/{user.id}") self.assertEqual(res.status_code, 200)
def create_problem_input_output_to_database(problem_id): problem_filename = f"{settings.PROB_DIR}/test_cases/{problem_id}/problem.txt" parsed_problem = parse_problem(problem_filename) input_filename = f"{settings.PROB_DIR}/test_cases/{problem_id}/input.txt" parsed_inputs = parse_input(input_filename) output_filename = f"{settings.PROB_DIR}/test_cases/{problem_id}/output.txt" parsed_outputs = parse_output(output_filename) problem = Problem( pid=problem_id, objective=parsed_problem["objective"], title=parsed_problem["title"], input_desc=parsed_problem["input_desc"], output_desc=parsed_problem["output_desc"], desc=parsed_problem["desc"], ) problem.save() assert (len(parsed_inputs) == len(parsed_outputs)) for i in range(len(parsed_inputs)): problem_input = ProblemInput(problem=problem, content=parsed_inputs[i]) problem_input.save() problem_output = ProblemOutput(problem_input=problem_input, content=parsed_outputs[i]) problem_output.save()
def new(request): if request.method == "POST": if 'pname' in request.POST and request.POST['pname'].strip() != "": p = Problem(pname=request.POST['pname'], owner=request.user) p.save() logger.info("problem %s created by %s" % (p.pk, request.user)) return redirect("/problem/%d/edit/" % p.pk) return redirect("/problem/")
def test_create_problem(self): """ Test creating a problem. """ problem = Problem( competition=self.competition, title="Test problem title", description="Test problem description" ) problem.save() self.assertIsNotNone(Problem.objects.get(pk=problem.id))
def update_atcoder_problems(): url = "https://kenkoooo.com/atcoder/resources/contests.json" res = requests.get(url) data = res.json() for contest in data: if len(atcoder_contest.objects.filter(contestId=contest['id'])) == 0: new_contest = atcoder_contest() new_contest.name = contest['title'] new_contest.contestId = contest['id'] new_contest.startTime = contest['start_epoch_second'] new_contest.duration = contest['duration_second'] new_contest.save() url = "https://kenkoooo.com/atcoder/resources/problems.json" res = requests.get(url) data = res.json() for prob in data: if len(Problem.objects.filter(prob_id=prob['id'], platform='A')) == 0: new_problem = Problem() new_problem.prob_id = prob['id'] new_problem.contest_id = prob['contest_id'] new_problem.name = prob['title'] new_problem.url = "https://atcoder.jp/contests/" + prob[ 'contest_id'] + "/tasks/" + prob['id'] new_problem.index = prob['id'].split("_")[-1] new_problem.platform = 'A' new_problem.save() url = "https://kenkoooo.com/atcoder/resources/problem-models.json" res = requests.get(url) data = res.json() problems = Problem.objects.filter(difficulty=None, platform='A') for prob in problems: if prob.prob_id in data: if 'difficulty' in data[prob.prob_id]: old = data[prob.prob_id]['difficulty'] if old < -1000: NewValue = (((old + 10000) * 50) / 9000) + 800 elif old <= 0: NewValue = (((old + 1000) * 350) / 1000) + 850 else: NewValue = ((old * 2400) / 5000) + 1200 prob.rating = str(int(NewValue)) prob.difficulty = rating_to_difficulty(int(NewValue)) prob.save()
def import_tree(path): paths = [] for root, dirs, files in os.walk(path): if is_problem_path(root): paths.append(norm(root)) problem = Problem(path=root) problem.save() import_to_database(problem) problem.save() return paths
def test_problem_create(self): problem = Problem(desc="For test", input_desc="For test", output_desc="Fore test", pid="ITP1_6_B", objective=1) problem.save() self.assertEqual(len(Problem.objects.all()), 1)
def save(self, commit=True): problem_id = len(Problem.objects.filter(judge_type='0')) + 1000 title = self.cleaned_data.get("title") description = self.cleaned_data.get("description") Input = self.cleaned_data.get("input") Output = self.cleaned_data.get("output") sample_input = self.cleaned_data.get("sample_input") sample_output = self.cleaned_data.get("sample_output") inputdata = self.cleaned_data.get("inputdata") outputdata = self.cleaned_data.get("outputdata") hint = self.cleaned_data.get("hint") source = self.cleaned_data.get("source") type = '' oj = 'neau' judge_type = self.cleaned_data.get("judge_type") memory_limit = self.cleaned_data.get("memory_limit_c") time_limit = self.cleaned_data.get("time_limit_c") problem = Problem( problem_id=problem_id, title=title, description=description, input=Input, output=Output, sample_input=sample_input, sample_output=sample_output, hint=hint, source=source, defunct='0', submit='0', solved='0', type=type, oj=oj, judge_type=judge_type, memory_limit_c=str(int(memory_limit) * 1024), memory_limit_java=str(int(memory_limit) * 1024), time_limit_c=time_limit, time_limit_java=str(int(time_limit) * 2) ) problem.save() path = os.getcwd().split('/')[1:-1] path = '/' + os.path.join('/'.join(path), 'data', str(problem.id)) if not os.path.exists(path): try: os.mkdir(path) except: return problem fp = open(path + '/data.in', 'w') fp.write(inputdata) fp.close() fp = open(path + '/data.out', 'w') fp.write(outputdata) fp.close() return problem
def preview(request): problem = Problem() problem.pname = request.POST['pname'] problem.description = request.POST['description'] problem.input = request.POST['input'] problem.output = request.POST['output'] problem.sample_in = request.POST['sample_in'] problem.sample_out = request.POST['sample_out'] problem.tag = request.POST['tags'].split(',') return render_index(request, 'problem/preview.html', {'problem': problem, 'preview': True})
def get(self, request, remote_oj, remote_id, **kwargs): try: problem = Problem.objects.get(remote_oj=remote_oj, remote_id=remote_id) if problem.request_status == config.Problem.Status.STATUS_RETRYABLE.value: problem.request_status = config.Problem.Status.STATUS_PENDING.value problem.save() get_problem_task.delay(problem.id) except ObjectDoesNotExist: problem = Problem(remote_oj=remote_oj, remote_id=remote_id, request_status=config.Problem.Status.STATUS_PENDING.value) problem.save() get_problem_task.delay(problem.id) return HttpResponse(problem.html)
def test_get_problem_by_objective(self): coder = Coder(user=self.user) coder.save() problem = Problem(desc="For test", input_desc="For test", output_desc="Fore test", pid="ITP1_6_B", objective=Problem.ProblemObjective.UM) problem.save() response = self.client.get("/api/problem/objective/") self.assertEqual(response.status_code, 200) response = self.client.post("/api/problem/objective/", {}) self.assertEqual(response.status_code, 405)
def get(self, request, remote_oj, remote_id, **kwargs): if remote_oj not in list({item.oj_name for item in Support.objects.filter(oj_enable=True)}): return Response( res_format('remote_oj not valid', status=Message.ERROR), status=status.HTTP_200_OK) if not remote_id.isalnum(): return Response( res_format('remote_id not valid', status=Message.ERROR), status=status.HTTP_200_OK) if request.GET.get('fresh') and request.GET.get('html'): return Response(res_format('\"fresh\" and \"html\" cannot exist together', Message.ERROR), status=status.HTTP_200_OK) if request.GET.get('fresh'): last_submit_time = request.session.get('last_fresh_time', None) if last_submit_time and (datetime.now() - datetime.fromtimestamp(last_submit_time)).seconds < 5: return Response(res_format("Cannot fresh within five seconds", status=Message.ERROR), status=status.HTTP_200_OK) request.session['last_fresh_time'] = datetime.now().timestamp() try: problem = Problem.objects.get(remote_oj=remote_oj, remote_id=remote_id) problem.request_status = config.Problem.Status.STATUS_PENDING.value problem.save() get_problem_task.delay(problem.id) return Response(res_format(ProblemSerializer(problem).data), status=status.HTTP_200_OK) except ObjectDoesNotExist: return Response(res_format('System error', Message.ERROR), status=status.HTTP_200_OK) if request.GET.get('html'): try: problem = Problem.objects.get(remote_oj=remote_oj, remote_id=remote_id) return HttpResponse(problem.html) except: return Response(res_format('', status=Message.ERROR)) try: problem = Problem.objects.get(remote_oj=remote_oj, remote_id=remote_id) if problem.request_status == config.Problem.Status.STATUS_RETRYABLE.value: get_problem_task.delay(problem.id) except ObjectDoesNotExist: try: problem = Problem(remote_oj=remote_oj, remote_id=remote_id, request_status=config.Problem.Status.STATUS_PENDING.value) problem.save() get_problem_task.delay(problem.id) except IntegrityError: return Response(res_format('System error', Message.ERROR), status=status.HTTP_200_OK) return Response(res_format(ProblemSerializer(problem).data), status=status.HTTP_200_OK)
def preview(request): problem = Problem() problem.pname = request.POST['pname'] problem.description = request.POST['description'] problem.input= request.POST['input'] problem.output = request.POST['output'] problem.sample_in = request.POST['sample_in'] problem.sample_out = request.POST['sample_out'] problem.tag = request.POST['tags'].split(',') return render_index(request, 'problem/preview.html', {'problem': problem, 'preview': True})
def save(self, user): Problem(creator=user, title=self.validated_data['title'], memory_limit=self.validated_data['memory_limit'], source=self.validated_data['source'], content=self.validated_data['content'], time_limit=self.validated_data['time_limit'], manifest=self.validated_data['manifest'], public=self.validated_data['public']).save()
def mutate(self, info: ResolveInfo, **kwargs): form = CreateProblemForm(kwargs) if form.is_valid(): values = form.cleaned_data samples = loads(values.get('samples')) prob = Problem() limitation = Limitation() assign(prob, **values) assign(limitation, **values) limitation.save() prob.limitation = limitation prob.save() for each in samples: ProblemSample( input_content=each.get('inputContent'), output_content=each.get('outputContent'), problem=prob ).save() return CreateProblem(slug=prob.slug) else: raise RuntimeError(form.errors.as_json())
def test_get_problem_input(self): problem = Problem(desc="For test", input_desc="For test", output_desc="Fore test", pid="ITP1_6_B", objective=1) problem.save() problem_input_1 = ProblemInput(problem=problem, content="input str 1") problem_input_1.save() problem_input_2 = ProblemInput(problem=problem, content="input str 2") problem_input_2.save() problem_input_3 = ProblemInput(problem=problem, content="input str 3") problem_input_3.save() problem_output_1 = ProblemOutput(problem_input=problem_input_1, content="output str a") problem_output_1.save() problem_output_2 = ProblemOutput(problem_input=problem_input_2, content="output str b") problem_output_2.save() problem_output_3 = ProblemOutput(problem_input=problem_input_3, content="output str c") problem_output_3.save() problem_id = problem.to_dict()['id'] response = self.client.get(f"/api/problem/{problem_id}/input/") self.assertEqual(response.status_code, 200) expected_response = json.dumps( get_dicts_with_filter(ProblemInput.objects, problem__id=problem_id)) self.assertEqual(response.content.decode(), expected_response) response = self.client.get("/api/problem/1000/input/") self.assertEqual(response.status_code, 400) response = self.client.post("/api/problem/1/input/", {}) self.assertEqual(response.status_code, 405)
def test_get_problem_output(self): problem = Problem(desc="For test", input_desc="For test", output_desc="Fore test", pid="ITP1_6_B", objective=1) problem.save() problem_input = ProblemInput(problem=problem, content=["1", "2", "3"]) problem_input.save() problem_output = ProblemOutput(problem_input=problem_input, content=["1", "2", "3"]) problem_output.save() problem_input_id = problem.to_dict()['id'] response = self.client.get(f"/api/problem/{problem_input_id}/output/") self.assertEqual(response.status_code, 200) response = self.client.post("/api/problem/1/output/", {}) self.assertEqual(response.status_code, 405)
def save(self, user): cid = self.cleaned_data.get("cid") from datetime import datetime from problem.models import Problem from contest.models import Contest, In_Problem try: contest = Contest.objects.get(clone=cid) flag = True except: contest = Contest( title="None", start_time=datetime.now(), end_time=datetime.now(), description="", private=0, impose=0, type=1, password="", creator=user, ) contest.save() flag = False if not flag: for i in range(self.number): p = Problem(oj="hdu_std", problem_id=i + 1001, judge_type=1, data_number=cid) p.save() new_problem = In_Problem( problem=p, problem_new_id=i, title="None", ) new_problem.save() contest.problem.add(new_problem) c = Connect() c.clone_contest(cid, contest.id)
def test_solution_create_exception(self): problem = Problem(desc="For test", input_desc="For test", output_desc="Fore test", pid="ITP1_6_B", objective=1) problem.save() problem_id = problem.to_dict()['id'] response = self.client.post( f"/api/problem/{problem_id}/solution/", json.dumps({}), content_type="application/json", ) self.assertEqual(response.status_code, 400) response = self.client.post("/api/problem/2/solution/", {}) self.assertEqual(response.status_code, 400) response = self.client.delete("/api/problem/2/solution/") self.assertEqual(response.status_code, 405)
def invalidate_problem(problem: Problem, save=True): query_list = list(problem.submission_set.filter(visible=True).values("author_id", "status")) ac_list = list(filter(lambda x: x["status"] == SubmissionStatus.ACCEPTED, query_list)) problem.ac_user_count = len(set(map(lambda x: x["author_id"], ac_list))) problem.total_user_count = len(set(map(lambda x: x["author_id"], query_list))) problem.ac_count = len(ac_list) problem.total_count = len(query_list) reward_est = 5 - (2 * problem.ac_ratio + 3 * problem.ac_user_ratio) * min(log10(problem.ac_user_count + 1), 1.2) \ + max(6 - 2 * log10(problem.ac_user_count + 1), 0) # reward_est = (max(reward_est, 0.) ** 2) / 10 problem.reward = max(min(reward_est, 9.9), 0.1) for field in problem._meta.local_fields: # pylint: disable=protected-access if field.name == "update_time": field.auto_now = False if save: problem.save(update_fields=["ac_user_count", "total_user_count", "ac_count", "total_count", "reward"])
def invalidate_problem(problem: Problem, save=True): query_list = list(problem.submission_set.all().values( "author_id", "status")) ac_list = list( filter(lambda x: x["status"] == SubmissionStatus.ACCEPTED, query_list)) problem.ac_user_count = len(set(map(lambda x: x["author_id"], ac_list))) problem.total_user_count = len( set(map(lambda x: x["author_id"], query_list))) problem.ac_count = len(ac_list) problem.total_count = len(query_list) problem.reward = max( min( 5 - (.02 * problem.ac_ratio + .03 * problem.ac_user_ratio) * min(log10(problem.ac_user_count + 1), 1.2) + max(6 - 2 * log10(problem.ac_user_count + 1), 0), 9.9), 0.1) for field in problem._meta.local_fields: if field.name == "update_time": field.auto_now = False if save: problem.save(update_fields=[ "ac_user_count", "total_user_count", "ac_count", "total_count", "reward" ])
def add_problem_block(request): is_success, is_error = False, False if request.method == 'POST': form = AddProblemForm(request.POST) if form.is_valid(): path = norm(form.cleaned_data['path']) if is_problem_path(path): problem = Problem(path=path) problem.save() import_to_database(problem) problem.save() is_success = True else: is_error = True else: form = AddProblemForm() return { 'form': form, 'is_success': is_success, 'is_error': is_error, }
def import_from_polygon_block(request): is_success = False if request.method == 'POST': form = ProblemImportFromPolygonForm(request.POST) if form.is_valid(): with ChangeDir(form.cleaned_data['target_path']): archive_name = download_zip.get_problem( form.cleaned_data['contest_id'], form.cleaned_data['problem_letter'].upper()) problem_name = create_problem(archive_name + ".zip") problem_path = norm(os.path.join(form.cleaned_data['target_path'], problem_name)) problem = Problem(path=problem_path, short_name=problem_name) problem.save() import_to_database(model=problem) problem.save() form = ProblemImportFromPolygonForm() is_success = True else: form = ProblemImportFromPolygonForm() return { 'form': form, 'is_success': is_success, }
def copy_problem_block(request): is_success, is_error = False, False if request.method == 'POST': form = CopyProblemForm(request.POST) if form.is_valid(): new_path = norm(form.cleaned_data['copy_to']) old_path = Problem.objects.get(id=form.cleaned_data['problem']).path copytree(old_path, new_path) problem = Problem(path=new_path) problem.save() problem = import_to_database(path=new_path) problem.save() is_success = True print(111, problem.id, problem.name) id = problem.id prob = Problem.objects.get(id=id) print(222, prob.id, prob.name) else: form = CopyProblemForm() return { 'form': form, 'is_success': is_success, 'is_error': is_error, }
def post(self, request): teams = Team.objects.all() template = get_object_or_404(ProblemTemplate, pk=request.POST.get('template_id', None)) resp = { 'title': '成功', 'message': f'成功开启{template.name}', 'url': reverse_lazy('home') + '#sheep' } for team in teams: docker_info = docker_controller.run_container( template.image_id, template.internal_port) problem = Problem() problem.container_id = docker_info['id'] problem.ssh_external_port = docker_info['ssh_port'] problem.web_external_port = docker_info['web_port'] problem.status = 'running' problem.template = template problem.team = team problem.flag, command = generate_flag_command( template.change_flag_command) docker_controller.exec_container(problem.container_id, command) problem.ssh_passwd, command = generate_ssh_paasword( template.change_passwd_command) docker_controller.exec_container(problem.container_id, command) problem.save() return render(request, 'alert.html', resp)
def update_uva_problems(): url = "https://uhunt.onlinejudge.org/api/p" res = requests.get(url) data = res.json() for p in data: if len(Problem.objects.filter(prob_id=p[0])) > 0: continue new_problem = Problem() new_problem.prob_id = p[0] new_problem.index = p[1] new_problem.name = p[2] dacu = p[3] wa = p[16] if dacu != 0: rating = min(3600, max(800, (20 - min(log2(dacu), 20)) * 200)) new_problem.rating = str(int(rating)) new_problem.difficulty = rating_to_difficulty(rating) new_problem.platform = 'U' new_problem.url = "https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=" + str( p[0]) new_problem.save() url = "https://uhunt.onlinejudge.org/api/cpbook/3" res = requests.get(url) data = res.json() for p in data: title1 = p['title'] for q in p['arr']: title2 = q['title'] for r in q['arr']: title3 = r[0] for i in range(1, len(r)): prob_num = abs(r[i]) tags = [title1, title2, title3] Problem.objects.filter(index=prob_num).update(tags=tags)
def codeforces_update_problems(): # check whether we have updated the problems of a particular contest , # if no , update the problems , else not .. url = "https://codeforces.com/api/contest.list" res = requests.get(url) data = res.json() if (data["status"] != 'OK'): return for codeforces_contest in data['result']: url = "https://codeforces.com/api/contest.standings?contestId=" + str( codeforces_contest['id']) + "&from=1&count=1" res = requests.get(url) data = res.json() if (data["status"] != 'OK'): continue new_contest = contest() if 'startTimeSeconds' in codeforces_contest: new_contest.startTime = codeforces_contest['startTimeSeconds'] new_contest.Type = 'R' new_contest.contestId = codeforces_contest['id'] new_contest.name = codeforces_contest['name'] new_contest.duration = codeforces_contest['durationSeconds'] if len(contest.objects.filter( contestId=codeforces_contest['id'])) == 0: new_contest.save() for contest_problem in data['result']['problems']: new_problem = Problem() new_problem.name = contest_problem['name'] new_problem.contest_id = contest_problem['contestId'] new_problem.prob_id = str( contest_problem['contestId']) + contest_problem['index'] new_problem.url = "https://codeforces.com/contest/" + str( contest_problem['contestId'] ) + "/problem/" + contest_problem['index'] new_problem.platform = 'F' new_problem.index = contest_problem['index'] new_problem.tags = contest_problem['tags'] if 'rating' in contest_problem: new_problem.rating = contest_problem['rating'] new_problem.difficulty = rating_to_difficulty( int(contest_problem['rating'])) if len( Problem.objects.filter( prob_id=str(contest_problem['contestId']) + contest_problem['index'])) == 0: new_problem.save() url = "https://codeforces.com/api/contest.list?gym=true" res = requests.get(url) data = res.json() if (data["status"] != 'OK'): return for codeforces_contest in data['result']: url = "https://codeforces.com/api/contest.standings?contestId=" + str( codeforces_contest['id']) + "&from=1&count=1" res = requests.get(url) data = res.json() if (data["status"] != 'OK'): continue new_contest = contest() if 'startTimeSeconds' in codeforces_contest: new_contest.startTime = codeforces_contest['startTimeSeconds'] new_contest.Type = 'R' new_contest.contestId = codeforces_contest['id'] new_contest.name = codeforces_contest['name'] new_contest.duration = codeforces_contest['durationSeconds'] if len(contest.objects.filter( contestId=codeforces_contest['id'])) == 0: new_contest.save() for contest_problem in data['result']['problems']: new_problem = Problem() new_problem.name = contest_problem['name'] new_problem.contest_id = contest_problem['contestId'] new_problem.prob_id = str( contest_problem['contestId']) + contest_problem['index'] new_problem.url = "https://codeforces.com/gym/" + str( contest_problem['contestId'] ) + "/problem/" + contest_problem['index'] new_problem.platform = 'F' new_problem.index = contest_problem['index'] new_problem.tags = contest_problem['tags'] if 'rating' in contest_problem: new_problem.rating = contest_problem['rating'] new_problem.difficulty = rating_to_difficulty( int(contest_problem['rating'])) if len( Problem.objects.filter( prob_id=str(contest_problem['contestId']) + contest_problem['index'])) == 0: new_problem.save() return
def test_other_solutions(self): client = Client() user = User.objects.create_user(username="******", password="******", email="*****@*****.**", salt="123", role=1) user_id = User.objects.filter(email="*****@*****.**").first().id client.login(username="******", password="******") problem1 = Problem(desc="For test", input_desc="For test", output_desc="Fore test", pid="ITP1_6_B", objective=1) problem1.save() problem1_id = problem1.to_dict()['id'] problem2 = Problem(desc="For test", input_desc="For test", output_desc="Fore test", pid="ALDS1_4_B", objective=3) problem2.save() problem2_id = problem2.to_dict()['id'] problem3 = Problem(desc="For test", input_desc="For test", output_desc="Fore test", pid="ITP1_7_B", objective=1) problem3.save() problem3_id = problem3.to_dict()['id'] solution1_body = { "erase_cnt": 12, "elapsed_time": 30, "evaluation": 66.0, "code": "n=int(input())\na=[[0 for i in range(13)]for j in range(4)]\nfor k in range(n):\ncard=input().split()\np=5\nif (card[0]=='S'):\np=0\nelif (card[0]=='H':\np=1\nelif (card[0]=='C'):\np=2\nelse:\np=3\nq=int(card[1])-1\na[p][q]=1\nfor i in range(4):\nfor j in range(13):\nif a[i][j]==0:\ntype=''\nif i==0 :\ntype='S'\nelif i==1:\ntype='H'\nelif i==2:\ntype='C'\nelse:\ntype='D'\nprint('{0} {1}'.format(type,j+1))", } response = client.post( f"/api/problem/{problem1_id}/solution/", json.dumps(solution1_body), content_type="application/json", ) self.assertEqual(response.status_code, 201) solution2_body = { "erase_cnt": 12, "elapsed_time": 30, "evaluation": 66.0, "code": "n=int(input())\na=[[0 for i in range(13)]for j in range(4)]\nfor k in range(n):\ncard=input().split()\np=5\nif (card[0]=='S'):\np=0\nelif (card[0]=='H':\np=1\nelif (card[0]=='C'):\np=2\nelse:\np=3\nq=int(card[1])-1\na[p][q]=1\nfor i in range(4):\nfor j in range(13):\nif a[i][j]==0:\ntype=''\nif i==0 :\ntype='S'\nelif i==1:\ntype='H'\nelif i==2:\ntype='C'\nelse:\ntype='D'\nprint('{0} {1}'.format(type,j+1))", } response = client.post( f"/api/problem/{problem2_id}/solution/", json.dumps(solution2_body), content_type="application/json", ) self.assertEqual(response.status_code, 201) solution3_body = { "erase_cnt": 12, "elapsed_time": 30, "evaluation": 66.0, "code": "n=int(input())\na=[[0 for i in range(13)]for j in range(4)]\nfor k in range(n):\ncard=input().split()\np=5\nif (card[0]=='S'):\np=0\nelif (card[0]=='H':\np=1\nelif (card[0]=='C'):\np=2\nelse:\np=3\nq=int(card[1])-1\na[p][q]=1\nfor i in range(4):\nfor j in range(13):\nif a[i][j]==0:\ntype=''\nif i==0 :\ntype='S'\nelif i==1:\ntype='H'\nelif i==2:\ntype='C'\nelse:\ntype='D'\nprint('{0} {1}'.format(type,j+1))", } response = client.post( f"/api/problem/{problem3_id}/solution/", json.dumps(solution3_body), content_type="application/json", ) self.assertEqual(response.status_code, 201) response = client.post("/api/analysis/my/report/") self.assertEqual(response.status_code, 204) User.objects.create_user(username="******", password="******", email="*****@*****.**", salt="123", role=1) client = Client() client.login(username="******", password="******") response = client.get(f"/api/analysis/other/{user_id}/solutions/") self.assertEqual(response.status_code, 200)