MCPcopy
hub / github.com/django/django / test_cache_page_timeout

Method test_cache_page_timeout

tests/cache/tests.py:2826–2847  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

2824
2825 @retry()
2826 def test_cache_page_timeout(self):
2827 # Page timeout takes precedence over the "max-age" section of the
2828 # "Cache-Control".
2829 tests = [
2830 (1, 3), # max_age < page_timeout.
2831 (3, 1), # max_age > page_timeout.
2832 ]
2833 for max_age, page_timeout in tests:
2834 with self.subTest(max_age=max_age, page_timeout=page_timeout):
2835 view = cache_page(timeout=page_timeout)(
2836 cache_control(max_age=max_age)(hello_world_view)
2837 )
2838 request = self.factory.get("/view/")
2839 response = view(request, "1")
2840 self.assertEqual(response.content, b"Hello World 1")
2841 time.sleep(1)
2842 response = view(request, "2")
2843 self.assertEqual(
2844 response.content,
2845 b"Hello World 1" if page_timeout > max_age else b"Hello World 2",
2846 )
2847 cache.clear()
2848
2849 def test_cache_control_not_cached(self):
2850 """

Callers

nothing calls this directly

Calls 6

cache_pageFunction · 0.90
cache_controlFunction · 0.90
viewFunction · 0.85
sleepMethod · 0.80
getMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected