mirror of
https://github.com/QingdaoU/OnlineJudge.git
synced 2024-12-28 16:12:13 +00:00
Fixed: #164
This commit is contained in:
parent
e730fceda7
commit
ab751ee4b5
@ -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()
|
||||
|
@ -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"],
|
||||
|
Loading…
Reference in New Issue
Block a user