Skip to content

Commit

Permalink
fix: continue work on updating tests
Browse files Browse the repository at this point in the history
  • Loading branch information
evemartin committed Apr 4, 2024
1 parent 33d57f4 commit f81868a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
4 changes: 2 additions & 2 deletions portal/tests/test_independent_student.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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(
Expand Down
19 changes: 11 additions & 8 deletions portal/tests/test_ratelimit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = {
Expand All @@ -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 = {
Expand All @@ -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

0 comments on commit f81868a

Please sign in to comment.