From 21dcd9a94fb3e9edeec883d12cd1dcac5e773abe Mon Sep 17 00:00:00 2001 From: Mike Edmunds Date: Tue, 14 Apr 2026 12:43:07 -0700 Subject: Refs #35514 -- Cleaned up logging and middleware tests. Simplified and removed use of soon-to-be-deprecated or removed features from tests for AdminEmailHandler and BrokenLinkEmailsMiddleware. Added or updated cases to ensure `fail_silently` usage remains consistent during the transition to email providers. Changed custom FailingEmailBackend to respect fail_silently and record its use in a class-level property. In AdminEmailHandlerTest: * Added make_log_record() helper to reduce duplicated code. * Changed test_fail_silently() to send through the FailingEmailBackend, which will fail if not initialized with fail_silently=True. (Rather than inspecting attributes of a soon-to-be-deprecated connection.) * Simplified test_uses_custom_email_backend() by replacing monkeypatches with inspectable custom backend. * In test_customize_send_mail_method(), removed use of the undocumented self.connection() method and the soon-to-be-deprecated `connection` arg to mail_managers(). This test verifies a subclass can customize sending by mailing the managers rather than the admins. Involving a email backend connection was irrelevant. In BrokenLinkEmailsMiddlewareTest, added a case with FailingEmailBackend to verify send uses fail_silently=True. --- tests/auth_tests/test_forms.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tests/auth_tests') diff --git a/tests/auth_tests/test_forms.py b/tests/auth_tests/test_forms.py index 983fe8c39e..167722c617 100644 --- a/tests/auth_tests/test_forms.py +++ b/tests/auth_tests/test_forms.py @@ -4,6 +4,8 @@ import sys import urllib.parse from unittest import mock +from mail.custombackend import FailingEmailBackend + from django import forms from django.contrib.auth.forms import ( AdminPasswordChangeForm, @@ -1382,6 +1384,7 @@ class PasswordResetFormTest(TestDataMixin, TestCase): @override_settings(EMAIL_BACKEND="mail.custombackend.FailingEmailBackend") def test_save_send_email_exceptions_are_catched_and_logged(self): + self.addCleanup(FailingEmailBackend.reset) user, username, email = self.create_dummy_user() form = PasswordResetForm({"email": email}) self.assertTrue(form.is_valid()) -- cgit v1.3