From f81868a267071e59b15bac8767cff894fb470fff Mon Sep 17 00:00:00 2001 From: Eve Martin Date: Thu, 4 Apr 2024 08:32:53 +0000 Subject: [PATCH] fix: continue work on updating tests --- portal/tests/test_independent_student.py | 4 ++-- portal/tests/test_ratelimit.py | 19 +++++++++++-------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/portal/tests/test_independent_student.py b/portal/tests/test_independent_student.py index 9ec013bfb..979ffb001 100644 --- a/portal/tests/test_independent_student.py +++ b/portal/tests/test_independent_student.py @@ -21,7 +21,7 @@ from django.urls import reverse from selenium.webdriver.common.by import By from selenium.webdriver.support.wait import WebDriverWait -from unittest.mock import patch, ANY +from unittest.mock import patch, ANY, Mock from portal.forms.error_messages import INVALID_LOGIN_MESSAGE @@ -139,7 +139,7 @@ def test_signup_invalid_name_fails(self): assert response.status_code == 200 @patch("common.mail.send_dotdigital_email") - def test_signup_under_13_sends_parent_email(self, mock_send_dotdigital_email): + def test_signup_under_13_sends_parent_email(self, mock_send_dotdigital_email: Mock): c = Client() response = c.post( diff --git a/portal/tests/test_ratelimit.py b/portal/tests/test_ratelimit.py index fb6e08efd..17d2ec233 100644 --- a/portal/tests/test_ratelimit.py +++ b/portal/tests/test_ratelimit.py @@ -18,6 +18,7 @@ from django.test import Client, TestCase from django.urls import reverse from django.urls import reverse_lazy +from unittest.mock import patch, Mock, ANY from portal.helpers.ratelimit import get_ratelimit_count_for_user from portal.views.login import has_user_lockout_expired @@ -433,7 +434,8 @@ def test_lockout_reset_tracking(self): @pytest.mark.django_db -def test_teacher_already_registered_email(client): +@patch("common.mail.send_dotdigital_email") +def test_teacher_already_registered_email(client, mock_send_dotdigital_email: Mock): first_name, last_name, email, password = generate_details() register_url = reverse("register") data = { @@ -448,19 +450,20 @@ def test_teacher_already_registered_email(client): # Register the teacher first time, there should be a registration email client.post(register_url, data) - assert len(mail.outbox) == 1 + mock_send_dotdigital_email.assert_called_once_with(1551577, ANY, ANY) # Register with the same email again, there should also be an already registered email client.post(register_url, data) - assert len(mail.outbox) == 2 + assert len(mail.outbox) == 1 # Register with the same email one more time, there shouldn't be any new emails client.post(register_url, data) - assert len(mail.outbox) == 2 + assert len(mail.outbox) == 1 @pytest.mark.django_db -def test_independent_student_already_registered_email(client): +@patch("common.mail.send_dotdigital_email") +def test_independent_student_already_registered_email(client, mock_send_dotdigital_email: Mock): name, username, email_address, password = generate_independent_student_details() register_url = reverse("register") data = { @@ -477,12 +480,12 @@ def test_independent_student_already_registered_email(client): # Register the independent student first time, there should be a registration email client.post(register_url, data) - assert len(mail.outbox) == 1 + mock_send_dotdigital_email.assert_called_once_with(1551577, ANY, ANY) # Register with the same email again, there should also be an already registered email client.post(register_url, data) - assert len(mail.outbox) == 2 + assert len(mail.outbox) == 1 # Reset mock and register with the same email one more time, there shouldn't be any new emails client.post(register_url, data) - assert len(mail.outbox) == 2 + assert len(mail.outbox) == 1