This commit is contained in:
zema1 2018-08-06 22:19:09 +08:00
parent e730fceda7
commit ab751ee4b5
2 changed files with 14 additions and 3 deletions

View File

@ -1,9 +1,9 @@
from unittest import mock
from copy import deepcopy
from unittest import mock
from .models import Submission
from problem.models import Problem, ProblemTag
from utils.api.tests import APITestCase
from .models import Submission
DEFAULT_PROBLEM_DATA = {"_id": "A-110", "title": "test", "description": "<p>test</p>", "input_description": "test",
"output_description": "test", "time_limit": 1000, "memory_limit": 256, "difficulty": "Low",
@ -25,6 +25,8 @@ DEFAULT_SUBMISSION_DATA = {
"language": "C",
"statistic_info": {}
}
# todo contest submission
@ -66,3 +68,11 @@ class SubmissionAPITest(SubmissionPrepare):
resp = self.client.post(self.url, self.submission_data)
self.assertSuccess(resp)
judge_task.assert_called()
def test_create_submission_with_wrong_language(self, judge_task):
self.submission_data.update({"language": "Python3"})
resp = self.client.post(self.url, self.submission_data)
self.assertFailed(resp)
self.assertDictEqual(resp.data, {"error": "error",
"data": "Python3 is now allowed in the problem"})
judge_task.assert_not_called()

View File

@ -64,7 +64,8 @@ class SubmissionAPI(APIView):
problem = Problem.objects.get(id=data["problem_id"], contest_id=data.get("contest_id"), visible=True)
except Problem.DoesNotExist:
return self.error("Problem not exist")
if data["language"] not in problem.languages:
return self.error(f"{data['language']} is now allowed in the problem")
submission = Submission.objects.create(user_id=request.user.id,
username=request.user.username,
language=data["language"],