From bc3dff8c32b70194ac86eb5ef07bb8ca0d222724 Mon Sep 17 00:00:00 2001 From: Jimin Ha Date: Wed, 2 Mar 2022 06:38:04 +0000 Subject: [PATCH] Fix UserContestAPITest MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Problem Tag을 제대로 사용하여 테스트 코드를 작성한다. --- backend/contest/tests.py | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/backend/contest/tests.py b/backend/contest/tests.py index 2b05d8a4a..099adfdbd 100644 --- a/backend/contest/tests.py +++ b/backend/contest/tests.py @@ -7,9 +7,7 @@ from .models import ContestAnnouncement, ContestRuleType, Contest, ACMContestRank from submission.models import Submission -from problem.models import Problem, ProblemIOMode - -from problem.models import ProblemIOMode +from problem.models import Problem, ProblemIOMode, ProblemTag DEFAULT_PROBLEM_DATA = {"_id": "A-110", "title": "test", "description": "

test

", "input_description": "test", "output_description": "test", "time_limit": 1000, "memory_limit": 256, "difficulty": "Level1", @@ -31,18 +29,6 @@ "allowed_ip_ranges": [], "visible": True, "real_time_rank": True} -DEFAULT_PROBLEM_DATA = {"_id": "A-110", "title": "test", "description": "

test

", "input_description": "test", - "output_description": "test", "time_limit": 1000, "memory_limit": 256, "difficulty": "Level1", - "visible": True, "languages": ["C", "C++", "Java", "Python2"], "template": {}, - "samples": [{"input": "test", "output": "test"}], "spj": False, "spj_language": "C", - "spj_code": "", "spj_compile_ok": True, "test_case_id": "499b26290cc7994e0b497212e842ea85", - "test_case_score": [{"output_name": "1.out", "input_name": "1.in", "output_size": 0, - "stripped_output_md5": "d41d8cd98f00b204e9800998ecf8427e", - "input_size": 0, "score": 0}], - "io_mode": {"io_mode": ProblemIOMode.standard, "input": "input.txt", "output": "output.txt"}, - "share_submission": False, - "rule_type": "ACM", "hint": "

test

", "source": "test"} - DEFAULT_SUBMISSION_DATA = { "problem_id": "1", "user_id": 1, @@ -208,8 +194,17 @@ def setUp(self): # create problem in contest data = copy.deepcopy(DEFAULT_PROBLEM_DATA) data["contest_id"] = self.contest.id - self.problem = Problem.objects.create(created_by=admin, **data) + tags = data.pop("tags") + problem = Problem.objects.create(created_by=admin, **data) + + for item in tags: + try: + tag = ProblemTag.objects.get(name=item) + except ProblemTag.DoesNotExist: + tag = ProblemTag.objects.create(name=item) + problem.tags.add(tag) + self.problem = problem # user submit problem user = self.create_user("test", "test123") data = copy.deepcopy(DEFAULT_SUBMISSION_DATA)