mirror of
https://github.com/pacnpal/django-anymail.git
synced 2025-12-20 11:51:05 -05:00
Deprecate DjrillBackendHTTPError
This commit is contained in:
@@ -16,8 +16,6 @@ import json
|
||||
import mimetypes
|
||||
import requests
|
||||
|
||||
DjrillBackendHTTPError = MandrillAPIError # Backwards-compat Djrill<=0.2.0
|
||||
|
||||
|
||||
def encode_date_for_mandrill(dt):
|
||||
"""Format a date or datetime for use as a Mandrill API date field
|
||||
@@ -361,3 +359,26 @@ class DjrillBackend(BaseEmailBackend):
|
||||
'content': content_b64.decode('ascii'),
|
||||
}
|
||||
return mandrill_attachment, is_embedded_image
|
||||
|
||||
|
||||
############################################################################################
|
||||
# Recreate this module, but with a warning on attempts to import deprecated properties.
|
||||
# This is ugly, but (surprisingly) blessed: http://stackoverflow.com/a/7668273/647002
|
||||
import sys
|
||||
import types
|
||||
|
||||
|
||||
class ModuleWithDeprecatedProps(types.ModuleType):
|
||||
def __init__(self, module):
|
||||
self._orig_module = module # must keep a ref around, or it'll get deallocated
|
||||
super(ModuleWithDeprecatedProps, self).__init__(module.__name__, module.__doc__)
|
||||
self.__dict__.update(module.__dict__)
|
||||
|
||||
@property
|
||||
def DjrillBackendHTTPError(self):
|
||||
removed_in_djrill_2("DjrillBackendHTTPError will be removed in Djrill 2.0. "
|
||||
"Use djrill.MandrillAPIError instead.")
|
||||
return MandrillAPIError
|
||||
|
||||
|
||||
sys.modules[__name__] = ModuleWithDeprecatedProps(sys.modules[__name__])
|
||||
|
||||
@@ -49,6 +49,14 @@ class DjrillBackendDeprecationTests(DjrillBackendMockAPITestCase):
|
||||
"DjrillMessage will be removed in Djrill 2.0",
|
||||
DjrillMessage)
|
||||
|
||||
def test_deprecated_djrill_backend_http_error(self):
|
||||
"""Djrill 0.2 deprecated DjrillBackendHTTPError; 2.0 will drop it"""
|
||||
def try_import():
|
||||
# noinspection PyUnresolvedReferences
|
||||
from djrill.mail.backends.djrill import DjrillBackendHTTPError
|
||||
self.assertWarnsMessage(DeprecationWarning,
|
||||
"DjrillBackendHTTPError will be removed in Djrill 2.0",
|
||||
try_import)
|
||||
|
||||
def assertWarnsMessage(self, warning, message, callable, *args, **kwds):
|
||||
"""Checks that `callable` issues a warning of category `warning` containing `message`"""
|
||||
@@ -149,6 +157,10 @@ class DjrillLegacyExceptionTests(TestCase):
|
||||
def test_DjrillBackendHTTPError(self):
|
||||
"""MandrillApiError was DjrillBackendHTTPError in 0.2.0"""
|
||||
# ... and had to be imported from deep in the package:
|
||||
with warnings.catch_warnings():
|
||||
warnings.filterwarnings('ignore', category=RemovedInDjrill2,
|
||||
message="DjrillBackendHTTPError will be removed in Djrill 2.0")
|
||||
# noinspection PyUnresolvedReferences
|
||||
from djrill.mail.backends.djrill import DjrillBackendHTTPError
|
||||
ex = MandrillAPIError("testing")
|
||||
self.assertIsInstance(ex, DjrillBackendHTTPError)
|
||||
|
||||
@@ -55,6 +55,12 @@ in debug mode.)
|
||||
Djrill 1.4 will report a `DeprecationWarning` if you are still
|
||||
using ``DjrillMessage``.
|
||||
|
||||
* **DjrillBackendHTTPError**
|
||||
|
||||
The ``DjrillBackendHTTPError`` exception was replaced in Djrill 0.3
|
||||
with :exc:`djrill.MandrillAPIError`. Djrill 1.4 will report a
|
||||
`DeprecationWarning` if you are still importing ``DjrillBackendHTTPError``.
|
||||
|
||||
|
||||
Change Log
|
||||
----------
|
||||
|
||||
Reference in New Issue
Block a user