summaryrefslogtreecommitdiff
path: root/tests/cache
diff options
context:
space:
mode:
authorRinat Khabibiev <srenskiy@gmail.com>2016-09-15 08:41:07 +0300
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2024-02-05 13:27:51 +0100
commit3580b47ed31ec85ae89b13618f36bb463e97acc8 (patch)
tree6835fcee24746b2748aa8563e684180ae34a7afb /tests/cache
parent4b1cd8edc10bb6c3da3a270180d028670a6f2110 (diff)
Fixed #27225 -- Added "Age" header when fetching cached responses.
Co-Authored-By: Author: Alexander Lazarević <laza@e11bits.com>
Diffstat (limited to 'tests/cache')
-rw-r--r--tests/cache/tests.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/cache/tests.py b/tests/cache/tests.py
index e6ebb718f1..978efdd9d3 100644
--- a/tests/cache/tests.py
+++ b/tests/cache/tests.py
@@ -2752,6 +2752,37 @@ class CacheMiddlewareTest(SimpleTestCase):
self.assertIsNot(thread_caches[0], thread_caches[1])
+ def test_cache_control_max_age(self):
+ view = cache_page(2)(hello_world_view)
+ request = self.factory.get("/view/")
+
+ # First request. Freshly created response gets returned with no Age
+ # header.
+ with mock.patch.object(
+ time, "time", return_value=1468749600
+ ): # Sun, 17 Jul 2016 10:00:00 GMT
+ response = view(request, 1)
+ response.close()
+ self.assertIn("Expires", response)
+ self.assertEqual(response["Expires"], "Sun, 17 Jul 2016 10:00:02 GMT")
+ self.assertIn("Cache-Control", response)
+ self.assertEqual(response["Cache-Control"], "max-age=2")
+ self.assertNotIn("Age", response)
+
+ # Second request one second later. Response from the cache gets
+ # returned with an Age header set to 1 (second).
+ with mock.patch.object(
+ time, "time", return_value=1468749601
+ ): # Sun, 17 Jul 2016 10:00:01 GMT
+ response = view(request, 1)
+ response.close()
+ self.assertIn("Expires", response)
+ self.assertEqual(response["Expires"], "Sun, 17 Jul 2016 10:00:02 GMT")
+ self.assertIn("Cache-Control", response)
+ self.assertEqual(response["Cache-Control"], "max-age=2")
+ self.assertIn("Age", response)
+ self.assertEqual(response["Age"], "1")
+
@override_settings(
CACHE_MIDDLEWARE_KEY_PREFIX="settingsprefix",