mirror of
https://github.com/QingdaoU/OnlineJudge.git
synced 2025-01-16 01:13:47 +00:00
fix tests
This commit is contained in:
parent
abfe99a8bf
commit
f2576a9411
@ -304,7 +304,7 @@ class TwoFactorAuthAPITest(APITestCase):
|
|||||||
self.assertEqual(user.two_factor_auth, False)
|
self.assertEqual(user.two_factor_auth, False)
|
||||||
|
|
||||||
|
|
||||||
@mock.patch("account.views.oj.send_email_async.delay")
|
@mock.patch("account.views.oj.send_email_async.send")
|
||||||
class ApplyResetPasswordAPITest(CaptchaTest):
|
class ApplyResetPasswordAPITest(CaptchaTest):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.create_user("test", "test123", login=False)
|
self.create_user("test", "test123", login=False)
|
||||||
@ -317,20 +317,20 @@ class ApplyResetPasswordAPITest(CaptchaTest):
|
|||||||
def _refresh_captcha(self):
|
def _refresh_captcha(self):
|
||||||
self.data["captcha"] = self._set_captcha(self.client.session)
|
self.data["captcha"] = self._set_captcha(self.client.session)
|
||||||
|
|
||||||
def test_apply_reset_password(self, send_email_delay):
|
def test_apply_reset_password(self, send_email_send):
|
||||||
resp = self.client.post(self.url, data=self.data)
|
resp = self.client.post(self.url, data=self.data)
|
||||||
self.assertSuccess(resp)
|
self.assertSuccess(resp)
|
||||||
send_email_delay.assert_called()
|
send_email_send.assert_called()
|
||||||
|
|
||||||
def test_apply_reset_password_twice_in_20_mins(self, send_email_delay):
|
def test_apply_reset_password_twice_in_20_mins(self, send_email_send):
|
||||||
self.test_apply_reset_password()
|
self.test_apply_reset_password()
|
||||||
send_email_delay.reset_mock()
|
send_email_send.reset_mock()
|
||||||
self._refresh_captcha()
|
self._refresh_captcha()
|
||||||
resp = self.client.post(self.url, data=self.data)
|
resp = self.client.post(self.url, data=self.data)
|
||||||
self.assertDictEqual(resp.data, {"error": "error", "data": "You can only reset password once per 20 minutes"})
|
self.assertDictEqual(resp.data, {"error": "error", "data": "You can only reset password once per 20 minutes"})
|
||||||
send_email_delay.assert_not_called()
|
send_email_send.assert_not_called()
|
||||||
|
|
||||||
def test_apply_reset_password_again_after_20_mins(self, send_email_delay):
|
def test_apply_reset_password_again_after_20_mins(self, send_email_send):
|
||||||
self.test_apply_reset_password()
|
self.test_apply_reset_password()
|
||||||
user = User.objects.first()
|
user = User.objects.first()
|
||||||
user.reset_password_token_expire_time = now() - timedelta(minutes=21)
|
user.reset_password_token_expire_time = now() - timedelta(minutes=21)
|
||||||
|
@ -44,6 +44,7 @@ class ProblemIOModeSerializer(serializers.Serializer):
|
|||||||
raise serializers.ValidationError("Invalid io file name format")
|
raise serializers.ValidationError("Invalid io file name format")
|
||||||
return attrs
|
return attrs
|
||||||
|
|
||||||
|
|
||||||
class CreateOrEditProblemSerializer(serializers.Serializer):
|
class CreateOrEditProblemSerializer(serializers.Serializer):
|
||||||
_id = serializers.CharField(max_length=32, allow_blank=True, allow_null=True)
|
_id = serializers.CharField(max_length=32, allow_blank=True, allow_null=True)
|
||||||
title = serializers.CharField(max_length=1024)
|
title = serializers.CharField(max_length=1024)
|
||||||
|
@ -9,7 +9,7 @@ from django.conf import settings
|
|||||||
|
|
||||||
from utils.api.tests import APITestCase
|
from utils.api.tests import APITestCase
|
||||||
|
|
||||||
from .models import ProblemTag
|
from .models import ProblemTag, ProblemIOMode
|
||||||
from .models import Problem, ProblemRuleType
|
from .models import Problem, ProblemRuleType
|
||||||
from contest.models import Contest
|
from contest.models import Contest
|
||||||
from contest.tests import DEFAULT_CONTEST_DATA
|
from contest.tests import DEFAULT_CONTEST_DATA
|
||||||
@ -25,6 +25,8 @@ DEFAULT_PROBLEM_DATA = {"_id": "A-110", "title": "test", "description": "<p>test
|
|||||||
"test_case_score": [{"output_name": "1.out", "input_name": "1.in", "output_size": 0,
|
"test_case_score": [{"output_name": "1.out", "input_name": "1.in", "output_size": 0,
|
||||||
"stripped_output_md5": "d41d8cd98f00b204e9800998ecf8427e",
|
"stripped_output_md5": "d41d8cd98f00b204e9800998ecf8427e",
|
||||||
"input_size": 0, "score": 0}],
|
"input_size": 0, "score": 0}],
|
||||||
|
"io_mode": {"io_mode": ProblemIOMode.standard, "input": "input.txt", "output": "output.txt"},
|
||||||
|
"share_submission": False,
|
||||||
"rule_type": "ACM", "hint": "<p>test</p>", "source": "test"}
|
"rule_type": "ACM", "hint": "<p>test</p>", "source": "test"}
|
||||||
|
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ class SubmissionListTest(SubmissionPrepare):
|
|||||||
self.assertSuccess(resp)
|
self.assertSuccess(resp)
|
||||||
|
|
||||||
|
|
||||||
@mock.patch("submission.views.oj.judge_task.delay")
|
@mock.patch("submission.views.oj.judge_task.send")
|
||||||
class SubmissionAPITest(SubmissionPrepare):
|
class SubmissionAPITest(SubmissionPrepare):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self._create_problem_and_submission()
|
self._create_problem_and_submission()
|
||||||
|
@ -90,5 +90,5 @@ def DRAMATIQ_WORKER_ARGS(time_limit=3600_000, max_retries=0, max_age=7200_000):
|
|||||||
def check_is_id(value):
|
def check_is_id(value):
|
||||||
try:
|
try:
|
||||||
return int(value) > 0
|
return int(value) > 0
|
||||||
except Exception as e:
|
except Exception:
|
||||||
return False
|
return False
|
||||||
|
Loading…
x
Reference in New Issue
Block a user