From 9651a2ae7d5f83167068bf4485d4e0125c8ea671 Mon Sep 17 00:00:00 2001 From: Eve Martin Date: Thu, 4 Apr 2024 10:45:03 +0000 Subject: [PATCH] fix: update tests --- portal/tests/test_ratelimit.py | 4 ++-- portal/tests/test_teacher.py | 13 ++++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/portal/tests/test_ratelimit.py b/portal/tests/test_ratelimit.py index 7d2e856b9..4705ea224 100644 --- a/portal/tests/test_ratelimit.py +++ b/portal/tests/test_ratelimit.py @@ -450,7 +450,7 @@ def test_teacher_already_registered_email(client, mock_send_dotdigital_email: Mo # Register the teacher first time, there should be a registration email client.post(register_url, data) - mock_send_dotdigital_email.assert_called_once_with(1551577, ANY, ANY) + mock_send_dotdigital_email.assert_called_once_with(1551577, ANY, personalization_values=ANY) # Register with the same email again, there should also be an already registered email client.post(register_url, data) @@ -480,7 +480,7 @@ def test_independent_student_already_registered_email(client, mock_send_dotdigit # Register the independent student first time, there should be a registration email client.post(register_url, data) - mock_send_dotdigital_email.assert_called_once_with(1551577, ANY, ANY) + mock_send_dotdigital_email.assert_called_once_with(1551577, ANY, personalization_values=ANY) # Register with the same email again, there should also be an already registered email client.post(register_url, data) diff --git a/portal/tests/test_teacher.py b/portal/tests/test_teacher.py index 59d07b482..1d3373990 100644 --- a/portal/tests/test_teacher.py +++ b/portal/tests/test_teacher.py @@ -7,6 +7,7 @@ import jwt from aimmo.models import Game +from common.mail import send_dotdigital_email from common.models import Class, Student, Teacher from common.tests.utils import email as email_utils from common.tests.utils.classes import create_class_directly @@ -26,6 +27,7 @@ from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.support.wait import WebDriverWait +from unittest.mock import patch, Mock, ANY from portal.forms.error_messages import INVALID_LOGIN_MESSAGE from portal.tests.base_test import click_buttons_by_id @@ -357,7 +359,8 @@ def test_signup_fails_without_consent(self): # Assert response isn't a redirect (submit failure) assert response.status_code == 200 - def test_signup_email_verification(self): + @patch("common.helpers.emails.send_dotdigital_email") + def test_signup_email_verification(self, mock_send_dotdigital_email: Mock): c = Client() response = c.post( @@ -374,7 +377,7 @@ def test_signup_email_verification(self): ) assert response.status_code == 302 - assert len(mail.outbox) == 1 + mock_send_dotdigital_email.assert_called_once_with(1551577, ANY, personalization_values=ANY) # Try verification URL with a fake token fake_token = jwt.encode( @@ -393,9 +396,9 @@ def test_signup_email_verification(self): # Assert response isn't a redirect (get failure) assert bad_verification_response.status_code == 200 - # Get verification link from email - message = str(mail.outbox[0].body) - verification_url = re.search("http.+/", message).group(0) + # Get verification link from function call + verification_url = mock_send_dotdigital_email.call_args.kwargs["personalization_values"]["VERIFICATION_LINK"] + print(verification_url) # Verify the email properly verification_response = c.get(verification_url)