--
Ticket URL: <https://code.djangoproject.com/ticket/23003>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* status: new => assigned
* needs_better_patch: => 0
* owner: => brgl
* needs_tests: => 0
* needs_docs: => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/23003#comment:1>
Comment (by timo):
This is 3 lines of code or so? I don't think it is such a common need that
it needs to be included in Django.
--
Ticket URL: <https://code.djangoproject.com/ticket/23003#comment:2>
Comment (by brgl):
Yes, it's fairly easy, but still - I've always needed to implement it in
every project to cover error handling with tests. Since there are things
like 'dummy' mail backend in core/mail/backends, which is a three-liner
too I thought it would be nice to have it as standard.
Tell me if you don't want it anyway, I wan't bother sending a patch.
--
Ticket URL: <https://code.djangoproject.com/ticket/23003#comment:3>
* status: assigned => closed
* resolution: => wontfix
Comment:
@brgl, I agree with Tim that this doesn't need to be included in Django.
I suggest you take a look at the `mock` library for such use cases. It's
part of the standard library since Python3.3 (in the `unittest` package)
and available as standalone package on pypi for Python3.2-.
{{{#!python
from smtplib import SMTPException
try:
from unittest import mock # Python 3.3+
except ImportError:
try:
import mock # Python 3.2-
except ImportError:
raise ImportError(
'Make sure to install the `mock` package on Python 3.2-.'
)
from django.conf import settings
from django.test import TestCase
class SMTPExceptionHandlingTests(TestCase):
def test_handling(self):
send_messages = "%s.%s" % (settings.EMAIL_BACKEND,
'send_messages')
with mock.patch(send_messages, side_effect=SMTPException):
# Assert exception is correctly handled in this context
below...
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/23003#comment:4>