From f2576a9411468d8c568661877ff8a3d53f49f0ae Mon Sep 17 00:00:00 2001 From: virusdefender Date: Tue, 26 Mar 2019 10:51:49 +0800 Subject: [PATCH] fix tests --- account/tests.py | 14 +++++++------- problem/serializers.py | 1 + problem/tests.py | 4 +++- submission/tests.py | 2 +- utils/shortcuts.py | 2 +- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/account/tests.py b/account/tests.py index cc9dc865..4941eb27 100644 --- a/account/tests.py +++ b/account/tests.py @@ -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) diff --git a/problem/serializers.py b/problem/serializers.py index e4914c7f..2c09a6c9 100644 --- a/problem/serializers.py +++ b/problem/serializers.py @@ -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) diff --git a/problem/tests.py b/problem/tests.py index f4e7321a..7074d2f4 100644 --- a/problem/tests.py +++ b/problem/tests.py @@ -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": "

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": "

test

", "source": "test"} diff --git a/submission/tests.py b/submission/tests.py index 42417ea9..08ccbd46 100644 --- a/submission/tests.py +++ b/submission/tests.py @@ -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() diff --git a/utils/shortcuts.py b/utils/shortcuts.py index f4c7e85e..84e14fd2 100644 --- a/utils/shortcuts.py +++ b/utils/shortcuts.py @@ -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