本文整理汇总了Python中stubo.cache.Cache.get_scenario_sessions_information方法的典型用法代码示例。如果您正苦于以下问题:Python Cache.get_scenario_sessions_information方法的具体用法?Python Cache.get_scenario_sessions_information怎么用?Python Cache.get_scenario_sessions_information使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stubo.cache.Cache
的用法示例。
在下文中一共展示了Cache.get_scenario_sessions_information方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from stubo.cache import Cache [as 别名]
# 或者: from stubo.cache.Cache import get_scenario_sessions_information [as 别名]
def get(self, scenario_name):
"""
Returns scenario name, current sessions and their states,
stub count, total, document size. Also, provides direct URL link to stub list.
:param scenario_name: <string> scenario name
Response JSON:
{
"stubs": 32,
"space_used_kb": 840,
"recorded": "2015-07-15",
"name": "localhost:scenario_16",
"scenarioRef": "/stubo/api/v2/scenarios/objects/localhost:scenario_16"
}
"""
# check if hostname is supplied - if not, override scenario name with new value
scenario_name = _get_scenario_full_name(self, scenario_name)
# query MongoDB
document = yield self.db.scenario.find_one({'name': scenario_name})
# form a result dictionary
if document is not None:
# get stub count
stub_count = yield self.db.scenario_stub.find({'scenario': scenario_name}).count()
# get size
scenario_cl = Scenario()
size = scenario_cl.size(scenario_name)
# check if size is None
if size is None:
size = 0
recorded = scenario_cl.recorded(scenario_name)
if recorded is None:
recorded = '-'
host, scenario = scenario_name.split(':')
# getting session data
sessions = []
cache = Cache(host)
for session_info in cache.get_scenario_sessions_information(scenario):
sessions.append(session_info)
result_dict = {'name': scenario_name,
'stub_count': stub_count,
'recorded': recorded,
'space_used_kb': int(size),
'scenarioRef': '/stubo/api/v2/scenarios/objects/{0}'.format(scenario_name),
'sessions': sessions}
self.set_status(200)
self.write(result_dict)
else:
self.send_error(404)