diff options
author | Simon Law <simon.law@ecometrica.com> | 2012-07-20 16:32:58 -0400 |
---|---|---|
committer | Simon Law <simon.law@ecometrica.com> | 2012-07-20 16:32:58 -0400 |
commit | bd8903e7787a7bc0738432d9b75f9d1eac446061 (patch) | |
tree | 85208c75bdb9b42e9e6c7a24eb1d5d16743543f8 | |
parent | 803aba8859109e2c17e4bdf53126c058a2b60918 (diff) | |
download | django-wkhtmltopdf-bd8903e7787a7bc0738432d9b75f9d1eac446061.tar.gz django-wkhtmltopdf-bd8903e7787a7bc0738432d9b75f9d1eac446061.tar.bz2 django-wkhtmltopdf-bd8903e7787a7bc0738432d9b75f9d1eac446061.zip |
Use warnings.warn instead of raising PendingDeprecationWarnings.
-rw-r--r-- | wkhtmltopdf/tests.py | 22 | ||||
-rw-r--r-- | wkhtmltopdf/views.py | 13 |
2 files changed, 29 insertions, 6 deletions
diff --git a/wkhtmltopdf/tests.py b/wkhtmltopdf/tests.py index 3e8359f..8e6b9b2 100644 --- a/wkhtmltopdf/tests.py +++ b/wkhtmltopdf/tests.py @@ -5,11 +5,13 @@ from __future__ import absolute_import from StringIO import StringIO import os import sys +import warnings from django.test import TestCase from .subprocess import CalledProcessError from .utils import _options_to_args, template_to_temp_file, wkhtmltopdf +from .views import PdfResponse, PdfTemplateView class TestUtils(TestCase): @@ -65,3 +67,23 @@ class TestUtils(TestCase): finally: if os.path.exists(temp_file): os.remove(temp_file) + + +class TestViews(TestCase): + def test_deprecated(self): + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter('always') + PdfTemplateView() + self.assertEqual(len(w), 1) + self.assertEqual(w[0].category, PendingDeprecationWarning) + self.assertTrue( + 'PDFTemplateView' in str(w[0].message), + "'PDFTemplateView' not in {!r}".format(w[0].message)) + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter('always') + PdfResponse(None, None) + self.assertEqual(len(w), 1) + self.assertEqual(w[0].category, PendingDeprecationWarning) + self.assertTrue( + 'PDFResponse' in str(w[0].message), + "'PDFResponse' not in {!r}".format(w[0].message)) diff --git a/wkhtmltopdf/views.py b/wkhtmltopdf/views.py index 164f94f..8da86f5 100644 --- a/wkhtmltopdf/views.py +++ b/wkhtmltopdf/views.py @@ -1,5 +1,6 @@ import os from re import compile +import warnings from django.conf import settings from django.contrib.sites.models import Site @@ -21,8 +22,8 @@ class PDFResponse(HttpResponse): class PdfResponse(PDFResponse): def __init__(self, content, filename): - warning = '''PdfResponse is deprecated in favour of PDFResponse. It will be removed in version 1.''' - raise PendingDeprecationWarning(warning) + warnings.warn('PdfResponse is deprecated in favour of PDFResponse. It will be removed in version 1.', + PendingDeprecationWarning, 2) super(PdfResponse, self).__init__(content, filename) @@ -90,7 +91,7 @@ class PDFTemplateView(TemplateView): class PdfTemplateView(PDFTemplateView): #TODO: Remove this in v1.0 - def as_view(cls, **initkwargs): - warning = '''PdfTemplateView is deprecated in favour of PDFTemplateView. It will be removed in version 1.''' - raise PendingDeprecationWarning(warning) - return super(PdfTemplateView, cls).as_view(**initkwargs) + def __init__(self, *args, **kwargs): + warnings.warn('PdfTemplateView is deprecated in favour of PDFTemplateView. It will be removed in version 1.', + PendingDeprecationWarning, 2) + super(PdfTemplateView, self).__init__(*args, **kwargs) |