[Django] #23003: Implement an EmailBackend raising an smtplib.SMTPException on send_messages()

18 views
Skip to first unread message

Django

unread,
Jul 11, 2014, 10:31:33 AM7/11/14
to django-...@googlegroups.com
#23003: Implement an EmailBackend raising an smtplib.SMTPException on
send_messages()
-----------------------------+---------------------------------------------
Reporter: brgl | Owner:
Type: New feature | Status: new
Component: Core (Mail) | Version: master
Severity: Normal | Keywords: mail emailbackend smtpexception
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+---------------------------------------------
There is no standard django mail backend that allows to test the behaviour
of an application when handling SMTPExceptions. Implement a simple
subclass of BaseEmailBackend that raises SMTPException on send_messages().

--
Ticket URL: <https://code.djangoproject.com/ticket/23003>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jul 11, 2014, 10:32:22 AM7/11/14
to django-...@googlegroups.com
#23003: Implement an EmailBackend raising an smtplib.SMTPException on
send_messages()
-------------------------------------+-------------------------------------
Reporter: brgl | Owner: brgl
Type: New feature | Status: assigned

Component: Core (Mail) | Version: master
Severity: Normal | Resolution:
Keywords: mail emailbackend | Triage Stage:
smtpexception | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by brgl):

* 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>

Django

unread,
Jul 11, 2014, 10:35:32 AM7/11/14
to django-...@googlegroups.com
#23003: Implement an EmailBackend raising an smtplib.SMTPException on
send_messages()
-------------------------------------+-------------------------------------
Reporter: brgl | Owner: brgl
Type: New feature | Status: assigned
Component: Core (Mail) | Version: master
Severity: Normal | Resolution:
Keywords: mail emailbackend | Triage Stage:
smtpexception | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Django

unread,
Jul 11, 2014, 11:08:28 AM7/11/14
to django-...@googlegroups.com
#23003: Implement an EmailBackend raising an smtplib.SMTPException on
send_messages()
-------------------------------------+-------------------------------------
Reporter: brgl | Owner: brgl
Type: New feature | Status: assigned
Component: Core (Mail) | Version: master
Severity: Normal | Resolution:
Keywords: mail emailbackend | Triage Stage:
smtpexception | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Django

unread,
Jul 11, 2014, 12:17:38 PM7/11/14
to django-...@googlegroups.com
#23003: Implement an EmailBackend raising an smtplib.SMTPException on
send_messages()
-------------------------------------+-------------------------------------
Reporter: brgl | Owner: brgl
Type: New feature | Status: closed

Component: Core (Mail) | Version: master
Severity: Normal | Resolution: wontfix

Keywords: mail emailbackend | Triage Stage:
smtpexception | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by charettes):

* 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>

Reply all
Reply to author
Forward
0 new messages