Skip to content

Commit

Permalink
fix: update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
evemartin committed Apr 4, 2024
1 parent 3ba97c2 commit 9651a2a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
4 changes: 2 additions & 2 deletions portal/tests/test_ratelimit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 8 additions & 5 deletions portal/tests/test_teacher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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)
Expand Down

0 comments on commit 9651a2a

Please sign in to comment.