diff options
| author | Jannis Leidel <jannis@leidel.info> | 2012-11-22 10:03:52 +0100 |
|---|---|---|
| committer | Jannis Leidel <jannis@leidel.info> | 2012-11-22 10:05:08 +0100 |
| commit | 3fb83729b9fd7d5e46263286d42f47cb52ac2824 (patch) | |
| tree | c709637bc8df0b617f35d641f2387788ef6988a8 /tests | |
| parent | d80d05fc673665fa614e65eb2c38b654ccf28235 (diff) | |
| parent | f9891f20872e2a468c4910a968c5e2fae75d0e51 (diff) | |
Merge branch 'ticket_19325' of https://github.com/hannesstruss/django into hannesstruss-ticket_19325
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): """ |
