diff options
| author | Hannes Struss <x@hannesstruss.de> | 2012-11-19 18:57:40 +0100 |
|---|---|---|
| committer | Hannes Struss <x@hannesstruss.de> | 2012-11-20 11:23:12 +0100 |
| commit | f9891f20872e2a468c4910a968c5e2fae75d0e51 (patch) | |
| tree | 1bddda217aa8a319b57801f84f560a658324ee1d /tests | |
| parent | 1f1f60d12f78ee68d59b577fdb6a31857b1d0f44 (diff) | |
Fixed #19325 - Made email backend of AdminEmailHandler configurable
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/regressiontests/logging_tests/logconfig.py | 7 | ||||
| -rw-r--r-- | tests/regressiontests/logging_tests/tests.py | 34 |
2 files changed, 41 insertions, 0 deletions
diff --git a/tests/regressiontests/logging_tests/logconfig.py b/tests/regressiontests/logging_tests/logconfig.py index fc5ea1a0bd..b068103eb9 100644 --- a/tests/regressiontests/logging_tests/logconfig.py +++ b/tests/regressiontests/logging_tests/logconfig.py @@ -1,8 +1,15 @@ import logging from django.conf import settings +from django.core.mail.backends.base import BaseEmailBackend + class MyHandler(logging.Handler): def __init__(self): logging.Handler.__init__(self) self.config = settings.LOGGING + + +class MyEmailBackend(BaseEmailBackend): + def send_messages(self, email_messages): + pass diff --git a/tests/regressiontests/logging_tests/tests.py b/tests/regressiontests/logging_tests/tests.py index 0e56195c41..19ee06eccc 100644 --- a/tests/regressiontests/logging_tests/tests.py +++ b/tests/regressiontests/logging_tests/tests.py @@ -15,6 +15,8 @@ from django.utils.unittest import skipUnless from ..admin_scripts.tests import AdminScriptTestCase +from .logconfig import MyEmailBackend + PYVERS = sys.version_info[:2] # logging config prior to using filter with mail_admins @@ -305,6 +307,38 @@ class AdminEmailHandlerTest(TestCase): self.assertEqual(len(mail.outbox), 1) self.assertEqual(mail.outbox[0].subject, expected_subject) + @override_settings( + ADMINS=(('admin', 'admin@example.com'),), + DEBUG=False, + ) + def test_uses_custom_email_backend(self): + """ + Refs #19325 + """ + message = 'All work and no play makes Jack a dull boy' + admin_email_handler = self.get_admin_email_handler(self.logger) + mail_admins_called = {'called': False} + + def my_mail_admins(*args, **kwargs): + connection = kwargs['connection'] + self.assertTrue(isinstance(connection, MyEmailBackend)) + mail_admins_called['called'] = True + + # Monkeypatches + orig_mail_admins = mail.mail_admins + orig_email_backend = admin_email_handler.email_backend + mail.mail_admins = my_mail_admins + admin_email_handler.email_backend = ( + 'regressiontests.logging_tests.logconfig.MyEmailBackend') + + try: + self.logger.error(message) + self.assertTrue(mail_admins_called['called']) + finally: + # Revert Monkeypatches + mail.mail_admins = orig_mail_admins + admin_email_handler.email_backend = orig_email_backend + class SettingsConfigTest(AdminScriptTestCase): """ |
