summaryrefslogtreecommitdiff
path: root/tests/cache
diff options
context:
space:
mode:
authorFlavio Curella <flavio.curella@gmail.com>2019-09-26 11:41:38 -0700
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-01-16 13:39:16 +0100
commitd08d4f464ab11cc226d4e197c0f43e26a7fd2961 (patch)
tree568fce9e1eee95192ad4bf2e24edc3b3573cda3d /tests/cache
parent1e0dcd6c8bfa4519c21014c73eb510620dd1a000 (diff)
Fixed #30765 -- Made cache_page decorator take precedence over max-age Cache-Control directive.
Diffstat (limited to 'tests/cache')
-rw-r--r--tests/cache/tests.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/cache/tests.py b/tests/cache/tests.py
index e99ab408a1..141d782203 100644
--- a/tests/cache/tests.py
+++ b/tests/cache/tests.py
@@ -2188,6 +2188,29 @@ class CacheMiddlewareTest(SimpleTestCase):
response = other_with_prefix_view(request, '16')
self.assertEqual(response.content, b'Hello World 16')
+ def test_cache_page_timeout(self):
+ # Page timeout takes precedence over the "max-age" section of the
+ # "Cache-Control".
+ tests = [
+ (1, 3), # max_age < page_timeout.
+ (3, 1), # max_age > page_timeout.
+ ]
+ for max_age, page_timeout in tests:
+ with self.subTest(max_age=max_age, page_timeout=page_timeout):
+ view = cache_page(timeout=page_timeout)(
+ cache_control(max_age=max_age)(hello_world_view)
+ )
+ request = self.factory.get('/view/')
+ response = view(request, '1')
+ self.assertEqual(response.content, b'Hello World 1')
+ time.sleep(1)
+ response = view(request, '2')
+ self.assertEqual(
+ response.content,
+ b'Hello World 1' if page_timeout > max_age else b'Hello World 2',
+ )
+ cache.clear()
+
def test_cached_control_private_not_cached(self):
"""Responses with 'Cache-Control: private' are not cached."""
view_with_private_cache = cache_page(3)(cache_control(private=True)(hello_world_view))