本文整理汇总了Python中cachecontrol.cache.DictCache.set方法的典型用法代码示例。如果您正苦于以下问题:Python DictCache.set方法的具体用法?Python DictCache.set怎么用?Python DictCache.set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cachecontrol.cache.DictCache
的用法示例。
在下文中一共展示了DictCache.set方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestDisabledETags
# 需要导入模块: from cachecontrol.cache import DictCache [as 别名]
# 或者: from cachecontrol.cache.DictCache import set [as 别名]
class TestDisabledETags(object):
"""Test our use of ETags when the response is stale and the
response has an ETag.
"""
@pytest.fixture()
def sess(self, server):
self.etag_url = urljoin(server.application_url, "/etag")
self.update_etag_url = urljoin(server.application_url, "/update_etag")
self.cache = DictCache()
sess = CacheControl(requests.Session(), cache=self.cache, cache_etags=False, serializer=NullSerializer())
return sess
def test_expired_etags_if_none_match_response(self, sess):
"""Make sure an expired response that contains an ETag uses
the If-None-Match header.
"""
# get our response
r = sess.get(self.etag_url)
# expire our request by changing the date. Our test endpoint
# doesn't provide time base caching headers, so we add them
# here in order to expire the request.
r.headers["Date"] = "Tue, 26 Nov 2012 00:50:49 GMT"
self.cache.set(self.etag_url, r)
r = sess.get(self.etag_url)
assert r.from_cache
assert "if-none-match" in r.request.headers
assert r.status_code == 200