当前位置: 首页>>代码示例>>Python>>正文


Python Cache.get_all_saved_request_index_data方法代码示例

本文整理汇总了Python中stubo.cache.Cache.get_all_saved_request_index_data方法的典型用法代码示例。如果您正苦于以下问题:Python Cache.get_all_saved_request_index_data方法的具体用法?Python Cache.get_all_saved_request_index_data怎么用?Python Cache.get_all_saved_request_index_data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在stubo.cache.Cache的用法示例。


在下文中一共展示了Cache.get_all_saved_request_index_data方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: export_stubs_to_commands_format

# 需要导入模块: from stubo.cache import Cache [as 别名]
# 或者: from stubo.cache.Cache import get_all_saved_request_index_data [as 别名]

#.........这里部分代码省略.........
            response = responses[0]
            response = ('{0}_{1}.response'.format(session, i), response)
            cmds.append('put/stub?{0},{1},{2}'.format(url_args, matchers_str,
                                                      response[0]))
            files.append(response)
            files.extend(matchers)
    else:
        cmds.append('put/stub?session={0},text=a_dummy_matcher,text=a_dummy_response'.format(session))
    cmds.append('end/session?session={0}'.format(session))

    runnable = asbool(handler.get_argument('runnable', False))
    runnable_info = dict()

    if runnable:
        playback_session = handler.get_argument('playback_session', None)
        if not playback_session:
            raise exception_response(400,
                                     title="'playback_session' argument required with 'runnable")
        runnable_info['playback_session'] = playback_session

        tracker = Tracker()
        last_used = tracker.session_last_used(scenario_name_key,
                                              playback_session, 'playback')
        if not last_used:
            raise exception_response(400,
                                     title="Unable to find playback session")
        runnable_info['last_used'] = dict(remote_ip=last_used['remote_ip'],
                                          start_time=str(last_used['start_time']))
        playback = tracker.get_last_playback(scenario_name, playback_session,
                                             last_used['start_time'])
        playback = list(playback)
        if not playback:
            raise exception_response(400,
                                     title="Unable to find a playback for scenario='{0}', playback_session='{1}'".format(scenario_name, playback_session))

        cmds.append('begin/session?scenario={0}&session={1}&mode=playback'.format(
            scenario_name, session))
        number_of_requests = len(playback)
        runnable_info['number_of_playback_requests'] = number_of_requests
        for nrequest in range(number_of_requests):
            track = playback[nrequest]
            request_text = track.get('request_text')
            if not request_text:
                raise exception_response(400, title='Unable to obtain playback details, was full tracking enabled?')

            request_file_name = '{0}_{1}.request'.format(session, nrequest)
            files.append((request_file_name, request_text))
            stubo_response_text = track['stubo_response']
            if not isinstance(stubo_response_text, basestring):
                stubo_response_text = unicode(stubo_response_text)
            stubo_response_file_name = '{0}_{1}.stubo_response'.format(session, nrequest)
            files.append((stubo_response_file_name, stubo_response_text))
            url_args = track['request_params']
            url_args['session'] = session
            url_args =  urlencode(url_args)
            cmds.append(u'get/response?{0},{1}'.format(url_args,
                                                       request_file_name))
        cmds.append('end/session?session={0}'.format(session))

    try:
        bookmarks = cache.get_all_saved_request_index_data()
        if bookmarks:
            cmds.append('import/bookmarks?location=bookmarks')
            files.append(('bookmarks', json.dumps(bookmarks)))
    except Exception as ex:
        log.warn("failed to export bookmarks, error: %s" % ex)
        pass

    files.append(('{0}.commands'.format(scenario_name),
                  b"\r\n".join(cmds)))

    static_dir = handler.settings['static_path']
    export_dir = handler.get_argument('export_dir', scenario_name_key).replace(':', '_')
    export_dir_path = os.path.join(static_dir, 'exports', export_dir)

    if os.path.exists(export_dir_path):
        shutil.rmtree(export_dir_path)
    os.makedirs(export_dir_path)

    archive_name = os.path.join(export_dir_path, scenario_name)
    zout = zipfile.ZipFile(archive_name+'.zip', "w")
    tar = tarfile.open(archive_name+".tar.gz", "w:gz")
    for finfo in files:
        fname, contents = finfo
        file_path = os.path.join(export_dir_path, fname)
        with codecs.open(file_path, mode='wb', encoding='utf-8') as f:
            f.write(contents)
        f.close()
        tar.add(file_path, fname)
        zout.write(file_path, fname)
    tar.close()
    zout.close()
    shutil.copy(archive_name+'.zip', archive_name+'.jar')

    files.extend([(scenario_name+'.zip',), (scenario_name+'.tar.gz',),
                  (scenario_name+'.jar',)])
    # getting links
    links = get_export_links(handler, scenario_name_key, files)

    return links
开发者ID:mithun-kumar,项目名称:stubo-app,代码行数:104,代码来源:export_commands.py

示例2: get_bookmarks

# 需要导入模块: from stubo.cache import Cache [as 别名]
# 或者: from stubo.cache.Cache import get_all_saved_request_index_data [as 别名]
def get_bookmarks(handler):
    cache = Cache(get_hostname(handler.request))
    response = dict(version=version, data={}) 
    all_index_state = cache.get_all_saved_request_index_data()
    response['data'] = all_index_state 
    return response   
开发者ID:mithun-kumar,项目名称:stubo-app,代码行数:8,代码来源:api.py


注:本文中的stubo.cache.Cache.get_all_saved_request_index_data方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。