Opened 10 years ago
Closed 10 years ago
#23003 closed New feature (wontfix)
Implement an EmailBackend raising an smtplib.SMTPException on send_messages()
Reported by: | brgl | Owned by: | brgl |
---|---|---|---|
Component: | Core (Mail) | Version: | dev |
Severity: | Normal | Keywords: | mail emailbackend smtpexception |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
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().
Change History (4)
comment:1 by , 10 years ago
Owner: | set to |
---|---|
Status: | new → assigned |
comment:2 by , 10 years ago
comment:3 by , 10 years ago
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.
comment:4 by , 10 years ago
Resolution: | → wontfix |
---|---|
Status: | assigned → closed |
@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-.
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...
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.