Skip to content

Commit

Permalink
Assert that password reset email contains username reminder
Browse files Browse the repository at this point in the history
b/c invited users may not know that
  • Loading branch information
atodorov committed Oct 12, 2024
1 parent b09df54 commit 5978df1
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions tcms/kiwi_auth/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from django.conf import settings
from django.contrib.auth import get_user_model
from django.contrib.sites.models import Site
from django.template import loader
from django.test import TestCase, override_settings
from django.urls import reverse
from django.utils import timezone
Expand Down Expand Up @@ -397,6 +398,7 @@ def test_get_template_names(self):
)


@override_settings(LANGUAGE_CODE="en")
class TestPasswordResetView(TestCase):
"""Test for password reset view"""

Expand All @@ -417,7 +419,7 @@ def test_open_password_reset_page(self):
self.assertContains(response, f">{_password_reset}</button>")

@patch("tcms.kiwi_auth.forms.DjangoPasswordResetForm.send_mail")
def test_send_mail_for_password_reset(self, mail_sent):
def test_send_mail_for_password_reset(self, send_mail):
user = User.objects.create_user("kiwi-tester", "tester@example.com", "password")
user.is_active = True
user.save()
Expand All @@ -444,4 +446,12 @@ def test_send_mail_for_password_reset(self, mail_sent):
self.assertContains(response, _("Password reset email was sent"))

# Verify mail is sent
mail_sent.assert_called_once()
send_mail.assert_called_once()

# Verify that reset password email will contain the username as a reminder
email_template_name = send_mail.call_args_list[0][0][1]
context = send_mail.call_args_list[0][0][2]
email_body = loader.render_to_string(email_template_name, context)
self.assertIn(
f"Your username, in case you've forgotten: {user.username}", email_body
)

0 comments on commit 5978df1

Please sign in to comment.