summaryrefslogtreecommitdiff
path: root/tests/decorators
diff options
context:
space:
mode:
authormgaligniana <marcelogaligniana@gmail.com>2021-12-13 08:57:19 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2021-12-13 15:32:24 +0100
commite61abab6e0d57c333289790496f358bb8ee4c565 (patch)
tree399a569a5906c99c6a69137685cebdd798c1e2f0 /tests/decorators
parent5111b636d9b63535fa8990142f3b5c756d08c1b6 (diff)
Refs #33338 -- Added never_cache() tests for Expires header.
Diffstat (limited to 'tests/decorators')
-rw-r--r--tests/decorators/tests.py26
1 files changed, 21 insertions, 5 deletions
diff --git a/tests/decorators/tests.py b/tests/decorators/tests.py
index e496e2c790..de0edaa787 100644
--- a/tests/decorators/tests.py
+++ b/tests/decorators/tests.py
@@ -1,5 +1,5 @@
from functools import update_wrapper, wraps
-from unittest import TestCase
+from unittest import TestCase, mock
from django.contrib.admin.views.decorators import staff_member_required
from django.contrib.auth.decorators import (
@@ -494,16 +494,32 @@ class XFrameOptionsDecoratorsTests(TestCase):
class NeverCacheDecoratorTest(SimpleTestCase):
- def test_never_cache_decorator(self):
+
+ @mock.patch('time.time')
+ def test_never_cache_decorator_headers(self, mocked_time):
@never_cache
def a_view(request):
return HttpResponse()
- r = a_view(HttpRequest())
+
+ mocked_time.return_value = 1167616461.0
+ response = a_view(HttpRequest())
+ self.assertEqual(
+ response.headers['Expires'],
+ 'Mon, 01 Jan 2007 01:54:21 GMT',
+ )
self.assertEqual(
- set(r.headers['Cache-Control'].split(', ')),
- {'max-age=0', 'no-cache', 'no-store', 'must-revalidate', 'private'},
+ response.headers['Cache-Control'],
+ 'max-age=0, no-cache, no-store, must-revalidate, private',
)
+ def test_never_cache_decorator_expires_not_overridden(self):
+ @never_cache
+ def a_view(request):
+ return HttpResponse(headers={'Expires': 'tomorrow'})
+
+ response = a_view(HttpRequest())
+ self.assertEqual(response.headers['Expires'], 'tomorrow')
+
def test_never_cache_decorator_http_request(self):
class MyClass:
@never_cache