Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def setup(self):
self.sess = Session()
self.cache_sess = CacheControl(self.sess, heuristic=ExpiresAfter(days=1))
def test_simple_lockfile_arg(self, tmpdir, value, expected):
if value is not None:
cache = FileCache(str(tmpdir), use_dir_lock=value)
else:
cache = FileCache(str(tmpdir))
assert issubclass(cache.lock_class, expected)
cache.close()
def test_cache_request_fresh_max_age(self):
now = time.strftime(TIME_FMT, time.gmtime())
resp = Mock(headers={"cache-control": "max-age=3600", "date": now})
cache = DictCache({self.url: resp})
self.c.cache = cache
r = self.req({})
assert r == resp
def setup(self):
self.c = CacheController(DictCache(), serializer=NullSerializer())
def test_cache_request_no_headers(self):
cached_resp = Mock(headers={"ETag": "jfd9094r808", "Content-Length": 100})
self.c.cache = DictCache({self.url: cached_resp})
resp = self.req({})
assert not resp
def test_cache_request_unfresh_max_age(self):
earlier = time.time() - 3700 # epoch - 1h01m40s
now = time.strftime(TIME_FMT, time.gmtime(earlier))
resp = Mock(headers={"cache-control": "max-age=3600", "date": now})
self.c.cache = DictCache({self.url: resp})
r = self.req({})
assert not r
def sess(self, url):
self.url = url
self.cache = DictCache()
sess = Session()
sess.mount(
"http://", CacheControlAdapter(self.cache, serializer=NullSerializer())
)
return sess
def use_adapter():
print("Using adapter")
sess = Session()
sess.mount("http://", CacheControlAdapter())
return sess
def test_close(self):
cache = mock.Mock(spec=DictCache)
sess = Session()
sess.mount("http://", CacheControlAdapter(cache))
sess.close()
assert cache.close.called
def setup(self):
class NoopHeuristic(BaseHeuristic):
warning = Mock()
def update_headers(self, resp):
return {}
self.heuristic = NoopHeuristic()
self.sess = CacheControl(Session(), heuristic=self.heuristic)