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

Class TestSeparateBodyFileCache

tests/test_storage_filecache.py:144–173  ·  view source on GitHub ↗

Tests for ``SeparateBodyFileCache``

Source from the content-addressed store, hash-verified

142
143
144class TestSeparateBodyFileCache(FileCacheTestsMixin):
145 """
146 Tests for ``SeparateBodyFileCache``
147 """
148
149 FileCacheClass = SeparateBodyFileCache
150
151 def test_body_actually_stored_separately(self, sess):
152 """
153 Body is stored and can be retrieved from the SeparateBodyFileCache, with assurances
154 it's actually being loaded from separate file than metadata.
155 """
156 url = self.url + "cache_60"
157 response = sess.get(url)
158 body = response.content
159 response2 = sess.get(url)
160 assert response2.from_cache
161 assert response2.content == body
162
163 # OK now let's violate some abstraction boundaries to make sure body
164 # actually came from separate file.
165 with open(self.cache._fn(url), "rb") as f:
166 assert body not in f.read()
167 with open(self.cache._fn(url) + ".body", "rb") as f:
168 assert body == f.read()
169 with open(self.cache._fn(url) + ".body", "wb") as f:
170 f.write(b"CORRUPTED")
171 response2 = sess.get(url)
172 assert response2.from_cache
173 assert response2.content == b"CORRUPTED"

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…