diff options
author | Iacopo Spalletti <i.spalletti@nephila.it> | 2015-11-07 14:30:20 +0100 |
---|---|---|
committer | Tim Graham <timograham@gmail.com> | 2015-12-12 14:46:48 -0500 |
commit | d693074d431c50e4801dd6bf52525ce1436358f0 (patch) | |
tree | ad452646aad45bf9241478f3fc17803d05320cfc /tests/decorators | |
parent | 93fc23b2d542105f5d129dff2dd2c8895e9abd5d (diff) | |
download | django-d693074d431c50e4801dd6bf52525ce1436358f0.tar.gz |
Fixed #20223 -- Added keep_lazy() as a replacement for allow_lazy().
Thanks to bmispelon and uruz for the initial patch.
Diffstat (limited to 'tests/decorators')
-rw-r--r-- | tests/decorators/tests.py | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/tests/decorators/tests.py b/tests/decorators/tests.py index d23d700201..8fed78a67f 100644 --- a/tests/decorators/tests.py +++ b/tests/decorators/tests.py @@ -8,8 +8,12 @@ from django.contrib.auth.decorators import ( from django.http import HttpRequest, HttpResponse, HttpResponseNotAllowed from django.middleware.clickjacking import XFrameOptionsMiddleware from django.test import SimpleTestCase +from django.utils import six from django.utils.decorators import method_decorator -from django.utils.functional import allow_lazy, lazy +from django.utils.deprecation import RemovedInDjango20Warning +from django.utils.encoding import force_text +from django.utils.functional import allow_lazy, keep_lazy, keep_lazy_text, lazy +from django.utils.translation import ugettext_lazy from django.views.decorators.cache import ( cache_control, cache_page, never_cache, ) @@ -67,7 +71,8 @@ full_decorator = compose( staff_member_required, # django.utils.functional - allow_lazy, + keep_lazy(HttpResponse), + keep_lazy_text, lazy, ) @@ -149,6 +154,15 @@ class DecoratorsTest(TestCase): request.method = 'DELETE' self.assertIsInstance(my_safe_view(request), HttpResponseNotAllowed) + def test_deprecated_allow_lazy(self): + with self.assertRaises(RemovedInDjango20Warning): + def noop_text(text): + return force_text(text) + noop_text = allow_lazy(noop_text, six.text_type) + rendered = noop_text(ugettext_lazy("I am a text")) + self.assertEqual(type(rendered), six.text_type) + self.assertEqual(rendered, "I am a text") + # For testing method_decorator, a decorator that assumes a single argument. # We will get type arguments if there is a mismatch in the number of arguments. |