1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Refs #32468 -- Added error message on invalid usage of cache decorators.

This commit is contained in:
Haki Benita
2021-02-22 09:32:37 +02:00
committed by Mariusz Felisiak
parent 63bbfa9f45
commit 3fd82a6241
2 changed files with 40 additions and 1 deletions

View File

@@ -470,7 +470,7 @@ class XFrameOptionsDecoratorsTests(TestCase):
self.assertIsNone(r.get('X-Frame-Options', None))
class NeverCacheDecoratorTest(TestCase):
class NeverCacheDecoratorTest(SimpleTestCase):
def test_never_cache_decorator(self):
@never_cache
def a_view(request):
@@ -480,3 +480,30 @@ class NeverCacheDecoratorTest(TestCase):
set(r.headers['Cache-Control'].split(', ')),
{'max-age=0', 'no-cache', 'no-store', 'must-revalidate', 'private'},
)
def test_never_cache_decorator_http_request(self):
class MyClass:
@never_cache
def a_view(self, request):
return HttpResponse()
msg = (
"never_cache didn't receive an HttpRequest. If you are decorating "
"a classmethod, be sure to use @method_decorator."
)
with self.assertRaisesMessage(TypeError, msg):
MyClass().a_view(HttpRequest())
class CacheControlDecoratorTest(SimpleTestCase):
def test_cache_control_decorator_http_request(self):
class MyClass:
@cache_control(a='b')
def a_view(self, request):
return HttpResponse()
msg = (
"cache_control didn't receive an HttpRequest. If you are "
"decorating a classmethod, be sure to use @method_decorator."
)
with self.assertRaisesMessage(TypeError, msg):
MyClass().a_view(HttpRequest())