本文整理汇总了Python中stubo.cache.Cache.get_delay_policy方法的典型用法代码示例。如果您正苦于以下问题:Python Cache.get_delay_policy方法的具体用法?Python Cache.get_delay_policy怎么用?Python Cache.get_delay_policy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stubo.cache.Cache
的用法示例。
在下文中一共展示了Cache.get_delay_policy方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_delay_policy
# 需要导入模块: from stubo.cache import Cache [as 别名]
# 或者: from stubo.cache.Cache import get_delay_policy [as 别名]
def get_delay_policy(handler, name, cache_loc):
cache = Cache(get_hostname(handler.request))
response = {
'version' : version
}
delay = cache.get_delay_policy(name, cache_loc)
response['data'] = delay or {}
return response
示例2: StubCache
# 需要导入模块: from stubo.cache import Cache [as 别名]
# 或者: from stubo.cache.Cache import get_delay_policy [as 别名]
class StubCache(StubData):
def __init__(self, payload, scenario, session_name):
StubData.__init__(self, payload, scenario)
self.session_name = session_name
from stubo.cache import Cache
self.cache = Cache(self.hostname)
def id(self):
return "{0} => {1}".format(self.scenario_key(), self.session_name)
def request_index_id(self):
matchers = u"".join([u"".join(x.split()).strip() for x in self.contains_matchers() or []])
return compute_hash(
u"".join(
[
self.scenario_name,
matchers,
self.request_path() or "",
self.request_method(),
self.request_query_args() or "",
]
)
)
def load_from_cache(self, response_ids, delay_policy_name, recorded, system_date, module_info, request_index_key):
self.payload = dict(response=dict(ids=response_ids))
response = self.get_response_from_cache(request_index_key)
self.payload["response"] = response
self.set_recorded(recorded)
if module_info:
self.set_module(module_info)
if delay_policy_name:
self.load_delay_from_cache(delay_policy_name)
def get_response_from_cache(self, request_index_key):
# look up response
return self.cache.get_response(self.scenario_name, self.session_name, self.response_ids(), request_index_key)
def load_delay_from_cache(self, name):
self.set_delay_policy(self.cache.get_delay_policy(name))
def response_ids(self):
return self.response()["ids"]
def delay_policy_name(self):
name = ""
policy = self.delay_policy()
if policy:
name = policy.get("name")
return name
示例3: get_delay_policy
# 需要导入模块: from stubo.cache import Cache [as 别名]
# 或者: from stubo.cache.Cache import get_delay_policy [as 别名]
def get_delay_policy(handler, name, cache_loc):
"""
Gets specified or all delays, returns dictionary
:param handler: RequestHandler (or TrackRequest, BaseHandler, etc..)
:param name: Delay name, if None is passed - gets all delays
:param cache_loc: Cache location, usually just 'master'
:return: dictionary of dictionaries with scenario information and reference URI and status_code for response
"""
cache = Cache(get_hostname(handler.request))
response = {
'version': version
}
status_code = 200
delays = cache.get_delay_policy(name, cache_loc)
# if delay policy not found but name was specified, return error message
if delays is None and name is not None:
status_code = 404
response['error'] = "Delay policy '%s' not found" % name
return response, status_code
# list for storing delay objects since cache.get_delay_policy(name, cache_loc) returns a dict
delay_list = []
# adding references
if name is None:
if delays is not None:
# All stored delays should be returned
for k, v in delays.items():
v['delayPolicyRef'] = "/stubo/api/v2/delay-policy/objects/%s" % k
delay_list.append(v)
else:
# Returning empty dict
delays = {}
delay_list.append(delays)
else:
delays['delayPolicyRef'] = "/stubo/api/v2/delay-policy/objects/%s" % name
delay_list.append(delays)
response['data'] = delay_list
return response, status_code