Skip to content

Commit

Permalink
fix: fix dotdigital email tests
Browse files Browse the repository at this point in the history
  • Loading branch information
evemartin committed Apr 2, 2024
1 parent d3b94b6 commit 48cb482
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 31 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,6 @@
"."
],
"python.testing.pytestEnabled": true,
"python.testing.unittestEnabled": false
"python.testing.unittestEnabled": false,
"python.analysis.extraPaths": ["./cfl_common"]
}
33 changes: 7 additions & 26 deletions cfl_common/common/helpers/emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from enum import Enum, auto
from uuid import uuid4

from django.urls import reverse
import jwt
from common import app_settings
from common.app_settings import domain
Expand Down Expand Up @@ -120,11 +121,7 @@ def send_verification_email(request, user, data, new_email=None, age=None):
if age is None:
url = f"{request.build_absolute_uri(reverse('verify_email', kwargs={'token': verification}))}"

send_dotdigital_email(
1551577,
[user.email],
personalization_values={"VERIFICATION_LINK": url}
)
send_dotdigital_email(1551577, [user.email], personalization_values={"VERIFICATION_LINK": url})

if _newsletter_ticked(data):
add_to_dotmailer(user.first_name, user.last_name, user.email, DotmailerUserType.TEACHER)
Expand All @@ -135,27 +132,19 @@ def send_verification_email(request, user, data, new_email=None, age=None):
send_dotdigital_email(
1551587,
[user.email],
personalization_values={"FIRST_NAME": user.first_name, "ACTIVATION_LINK": url}
personalization_values={"FIRST_NAME": user.first_name, "ACTIVATION_LINK": url},
)
else:
url = f"{request.build_absolute_uri(reverse('verify_email', kwargs={'token': verification}))}"
send_dotdigital_email(
1551577,
[user.email],
personalization_values={"VERIFICATION_LINK": url}
)
send_dotdigital_email(1551577, [user.email], personalization_values={"VERIFICATION_LINK": url})

if _newsletter_ticked(data):
add_to_dotmailer(user.first_name, user.last_name, user.email, DotmailerUserType.STUDENT)
# verifying change of email address.
else:
verification = generate_token(user, new_email)
url = f"{request.build_absolute_uri(reverse('verify_email', kwargs={'token': verification}))}"
send_dotdigital_email(
1551594,
[new_email],
personalization_values={"VERIFICATION_LINK": url}
)
send_dotdigital_email(1551594, [new_email], personalization_values={"VERIFICATION_LINK": url})


def add_to_dotmailer(first_name: str, last_name: str, email: str, user_type: DotmailerUserType):
Expand Down Expand Up @@ -264,11 +253,7 @@ def update_indy_email(user, request, data):
changing_email = True
users_with_email = User.objects.filter(email=new_email)

send_dotdigital_email(
1551600,
[user.email],
personalization_values={"NEW_EMAIL_ADDRESS": new_email}
)
send_dotdigital_email(1551600, [user.email], personalization_values={"NEW_EMAIL_ADDRESS": new_email})

# email is available
if not users_with_email.exists():
Expand All @@ -285,11 +270,7 @@ def update_email(user: Teacher or Student, request, data):
changing_email = True
users_with_email = User.objects.filter(email=new_email)

send_dotdigital_email(
1551600,
[user.new_user.email],
personalization_values={"NEW_EMAIL_ADDRESS": new_email}
)
send_dotdigital_email(1551600, [user.new_user.email], personalization_values={"NEW_EMAIL_ADDRESS": new_email})

# email is available
if not users_with_email.exists():
Expand Down
7 changes: 4 additions & 3 deletions portal/tests/test_independent_student.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +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 ANY

from portal.forms.error_messages import INVALID_LOGIN_MESSAGE

Expand Down Expand Up @@ -137,7 +138,8 @@ def test_signup_invalid_name_fails(self):
# Assert response isn't a redirect (submit failure)
assert response.status_code == 200

def test_signup_under_13_sends_parent_email(self):
def test_signup_under_13_sends_parent_email(mocker):
mocked_send = mocker.patch("common.mail.send_dotdigital_email")
c = Client()

response = c.post(
Expand All @@ -156,8 +158,7 @@ def test_signup_under_13_sends_parent_email(self):
)

assert response.status_code == 302
assert len(mail.outbox) == 1
assert mail.outbox[0].subject == "Code for Life account request"
mocked_send.assert_called_once_with(1551587, ANY, ANY)


# Class for Selenium tests. We plan to replace these and turn them into Cypress tests
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ build-backend = "setuptools.build_meta:__legacy__"
line-length = 120

[tool.pytest.ini_options]
DJANGO_SETTINGS_MODULE = "example_project.settings"
DJANGO_SETTINGS_MODULE = "example_project.portal_test_settings"

0 comments on commit 48cb482

Please sign in to comment.