mirror of
https://github.com/django/django.git
synced 2025-09-11 14:42:46 +03:00
Fixed #35364 -- Stopped AdminEmailHandler rendering email unnecessarily.
This commit is contained in:
parent
b0f2289426
commit
50a702f3fd
|
@ -92,6 +92,13 @@ class AdminEmailHandler(logging.Handler):
|
||||||
)
|
)
|
||||||
|
|
||||||
def emit(self, record):
|
def emit(self, record):
|
||||||
|
# Early return when no email will be sent.
|
||||||
|
if (
|
||||||
|
not settings.ADMINS
|
||||||
|
# Method not overridden.
|
||||||
|
and self.send_mail.__func__ is AdminEmailHandler.send_mail
|
||||||
|
):
|
||||||
|
return
|
||||||
try:
|
try:
|
||||||
request = record.request
|
request = record.request
|
||||||
subject = "%s (%s IP): %s" % (
|
subject = "%s (%s IP): %s" % (
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import logging
|
import logging
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
|
from unittest import mock
|
||||||
|
|
||||||
from admin_scripts.tests import AdminScriptTestCase
|
from admin_scripts.tests import AdminScriptTestCase
|
||||||
|
|
||||||
|
@ -482,7 +483,12 @@ class AdminEmailHandlerTest(SimpleTestCase):
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
handler.emit(record)
|
with mock.patch.object(
|
||||||
|
handler,
|
||||||
|
"format_subject",
|
||||||
|
side_effect=AssertionError("Should not be called"),
|
||||||
|
):
|
||||||
|
handler.emit(record)
|
||||||
self.assertEqual(len(mail.outbox), 0)
|
self.assertEqual(len(mail.outbox), 0)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -123,7 +123,7 @@ class DefaultsTests(TestCase):
|
||||||
)
|
)
|
||||||
def test_custom_bad_request_template(self):
|
def test_custom_bad_request_template(self):
|
||||||
response = self.client.get("/raises400/")
|
response = self.client.get("/raises400/")
|
||||||
self.assertIs(response.wsgi_request, response.context[-1].request)
|
self.assertIs(response.wsgi_request, response.context.request)
|
||||||
|
|
||||||
@override_settings(
|
@override_settings(
|
||||||
TEMPLATES=[
|
TEMPLATES=[
|
||||||
|
|
Loading…
Reference in New Issue
Block a user