diff --git a/tcms/kiwi_auth/tests/test_views.py b/tcms/kiwi_auth/tests/test_views.py index 4acdd9ea2a..489e6404d7 100644 --- a/tcms/kiwi_auth/tests/test_views.py +++ b/tcms/kiwi_auth/tests/test_views.py @@ -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 @@ -397,6 +398,7 @@ def test_get_template_names(self): ) +@override_settings(LANGUAGE_CODE="en") class TestPasswordResetView(TestCase): """Test for password reset view""" @@ -417,7 +419,7 @@ def test_open_password_reset_page(self): self.assertContains(response, f">{_password_reset}") @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() @@ -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 + )