Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assert that password reset email contains username reminder #3812

Merged
merged 1 commit into from
Oct 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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", "[email protected]", "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
)
Loading