From fd75c4b24d192dfb6b8d2af7b782b8d4496f8b9c Mon Sep 17 00:00:00 2001 From: medmunds Date: Tue, 12 May 2015 18:27:29 -0700 Subject: [PATCH] Deprecate DjrillBackendHTTPError --- djrill/mail/backends/djrill.py | 25 +++++++++++++++++++++++-- djrill/tests/test_legacy.py | 18 +++++++++++++++--- docs/history.rst | 6 ++++++ 3 files changed, 44 insertions(+), 5 deletions(-) diff --git a/djrill/mail/backends/djrill.py b/djrill/mail/backends/djrill.py index a45bc06..f403039 100644 --- a/djrill/mail/backends/djrill.py +++ b/djrill/mail/backends/djrill.py @@ -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__]) diff --git a/djrill/tests/test_legacy.py b/djrill/tests/test_legacy.py index a2ef730..2bcb68b 100644 --- a/djrill/tests/test_legacy.py +++ b/djrill/tests/test_legacy.py @@ -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,9 +157,13 @@ 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) + 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) def test_NotSupportedByMandrillError(self): """Unsupported features used to just raise ValueError in 0.2.0""" diff --git a/docs/history.rst b/docs/history.rst index e7bcb87..3fc283c 100644 --- a/docs/history.rst +++ b/docs/history.rst @@ -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 ----------