mirror of
https://github.com/pacnpal/django-anymail.git
synced 2025-12-21 04:11:06 -05:00
Exception cleanup
Introduce djrill.NotSupportedByMandrillError for unsupported functionality (previously used generic ValueError). Change to djrill.MandrillAPIError, derived from requests.HTTPError, for API error responses (previously used djrill.mail.backends.djrill.DjrillBackendHTTPError -- retained as equivalent for backwards compatibility).
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
from django.test import TestCase
|
||||
|
||||
from djrill.mail import DjrillMessage
|
||||
from djrill import MandrillAPIError, NotSupportedByMandrillError
|
||||
|
||||
|
||||
class DjrillMessageTests(TestCase):
|
||||
@@ -72,3 +73,17 @@ class DjrillMessageTests(TestCase):
|
||||
self.assertFalse(hasattr(msg, 'tags'))
|
||||
self.assertFalse(hasattr(msg, 'from_name'))
|
||||
self.assertFalse(hasattr(msg, 'preserve_recipients'))
|
||||
|
||||
|
||||
class DjrillLegacyExceptionTests(TestCase):
|
||||
def test_DjrillBackendHTTPError(self):
|
||||
"""MandrillApiError was DjrillBackendHTTPError in 0.2.0"""
|
||||
# ... and had to be imported from deep in the package:
|
||||
from djrill.mail.backends.djrill import DjrillBackendHTTPError
|
||||
ex = MandrillAPIError("testing")
|
||||
self.assertIsInstance(ex, DjrillBackendHTTPError)
|
||||
|
||||
def test_NotSupportedByMandrillError(self):
|
||||
"""Unsupported features used to just raise ValueError in 0.2.0"""
|
||||
ex = NotSupportedByMandrillError("testing")
|
||||
self.assertIsInstance(ex, ValueError)
|
||||
|
||||
@@ -5,7 +5,7 @@ from django.conf import settings
|
||||
from django.core import mail
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
|
||||
from djrill.mail.backends.djrill import DjrillBackendHTTPError
|
||||
from djrill import MandrillAPIError, NotSupportedByMandrillError
|
||||
from djrill.tests.mock_backend import DjrillBackendMockAPITestCase
|
||||
|
||||
|
||||
@@ -123,7 +123,7 @@ class DjrillBackendTests(DjrillBackendMockAPITestCase):
|
||||
email = mail.EmailMessage('Subject', 'Body', 'from@example.com',
|
||||
['to@example.com'],
|
||||
headers={'Non-X-Non-Reply-To-Header': 'not permitted'})
|
||||
with self.assertRaises(ValueError):
|
||||
with self.assertRaises(NotSupportedByMandrillError):
|
||||
email.send()
|
||||
|
||||
# Make sure fail_silently is respected
|
||||
@@ -141,14 +141,14 @@ class DjrillBackendTests(DjrillBackendMockAPITestCase):
|
||||
'from@example.com', ['to@example.com'])
|
||||
email.attach_alternative("<p>First html is OK</p>", "text/html")
|
||||
email.attach_alternative("<p>But not second html</p>", "text/html")
|
||||
with self.assertRaises(ValueError):
|
||||
with self.assertRaises(NotSupportedByMandrillError):
|
||||
email.send()
|
||||
|
||||
# Only html alternatives allowed
|
||||
email = mail.EmailMultiAlternatives('Subject', 'Body',
|
||||
'from@example.com', ['to@example.com'])
|
||||
email.attach_alternative("{'not': 'allowed'}", "application/json")
|
||||
with self.assertRaises(ValueError):
|
||||
with self.assertRaises(NotSupportedByMandrillError):
|
||||
email.send()
|
||||
|
||||
# Make sure fail_silently is respected
|
||||
@@ -162,7 +162,7 @@ class DjrillBackendTests(DjrillBackendMockAPITestCase):
|
||||
|
||||
def test_mandrill_api_failure(self):
|
||||
self.mock_post.return_value = self.MockResponse(status_code=400)
|
||||
with self.assertRaises(DjrillBackendHTTPError):
|
||||
with self.assertRaises(MandrillAPIError):
|
||||
sent = mail.send_mail('Subject', 'Body', 'from@example.com',
|
||||
['to@example.com'])
|
||||
self.assertEqual(sent, 0)
|
||||
|
||||
Reference in New Issue
Block a user