fix tests

This commit is contained in:
virusdefender 2019-03-26 10:51:49 +08:00
parent abfe99a8bf
commit f2576a9411
5 changed files with 13 additions and 10 deletions

View File

@ -304,7 +304,7 @@ class TwoFactorAuthAPITest(APITestCase):
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):
def setUp(self):
self.create_user("test", "test123", login=False)
@ -317,20 +317,20 @@ class ApplyResetPasswordAPITest(CaptchaTest):
def _refresh_captcha(self):
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)
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()
send_email_delay.reset_mock()
send_email_send.reset_mock()
self._refresh_captcha()
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"})
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()
user = User.objects.first()
user.reset_password_token_expire_time = now() - timedelta(minutes=21)

View File

@ -44,6 +44,7 @@ class ProblemIOModeSerializer(serializers.Serializer):
raise serializers.ValidationError("Invalid io file name format")
return attrs
class CreateOrEditProblemSerializer(serializers.Serializer):
_id = serializers.CharField(max_length=32, allow_blank=True, allow_null=True)
title = serializers.CharField(max_length=1024)

View File

@ -9,7 +9,7 @@ from django.conf import settings
from utils.api.tests import APITestCase
from .models import ProblemTag
from .models import ProblemTag, ProblemIOMode
from .models import Problem, ProblemRuleType
from contest.models import Contest
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,
"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": "<p>test</p>", "source": "test"}

View File

@ -57,7 +57,7 @@ class SubmissionListTest(SubmissionPrepare):
self.assertSuccess(resp)
@mock.patch("submission.views.oj.judge_task.delay")
@mock.patch("submission.views.oj.judge_task.send")
class SubmissionAPITest(SubmissionPrepare):
def setUp(self):
self._create_problem_and_submission()

View File

@ -90,5 +90,5 @@ def DRAMATIQ_WORKER_ARGS(time_limit=3600_000, max_retries=0, max_age=7200_000):
def check_is_id(value):
try:
return int(value) > 0
except Exception as e:
except Exception:
return False