MCPcopy Create free account
hub / github.com/psf/cachecontrol / TestMaxAge

Class TestMaxAge

tests/test_max_age.py:13–57  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11
12
13class TestMaxAge:
14 @pytest.fixture()
15 def sess(self, url):
16 self.url = url
17 self.cache = DictCache()
18 sess = Session()
19 sess.mount(
20 "http://", CacheControlAdapter(self.cache, serializer=NullSerializer())
21 )
22 return sess
23
24 def test_client_max_age_0(self, sess):
25 """
26 Making sure when the client uses max-age=0 we don't get a
27 cached copy even though we're still fresh.
28 """
29 print("first request")
30 r = sess.get(self.url)
31 assert self.cache.get(self.url) == r.raw
32
33 print("second request")
34 r = sess.get(self.url, headers={"Cache-Control": "max-age=0"})
35
36 # don't remove from the cache
37 assert self.cache.get(self.url)
38 assert not r.from_cache
39
40 def test_client_max_age_3600(self, sess):
41 """
42 Verify we get a cached value when the client has a
43 reasonable max-age value.
44 """
45 r = sess.get(self.url)
46 assert self.cache.get(self.url) == r.raw
47
48 # request that we don't want a new one unless
49 r = sess.get(self.url, headers={"Cache-Control": "max-age=3600"})
50 assert r.from_cache is True
51
52 # now lets grab one that forces a new request b/c the cache
53 # has expired. To do that we'll inject a new time value.
54 resp = self.cache.get(self.url)
55 resp.headers["date"] = "Tue, 15 Nov 1994 08:12:31 GMT"
56 r = sess.get(self.url)
57 assert not r.from_cache

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…