_conftest.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:apitest 作者: BBVA 项目源码 文件源码
def request_good(request):
    def _new_fn(url: str, *, method: str = "GET", headers: dict = None, body: str = None):
        # Get the unique signature for the Query
        url_signature = "%s_ok" % make_url_signature(url,
                                                     method=method,
                                                     headers=headers,
                                                     body=body)

        response = request.config.cache.get(url_signature, None)
        # If response is not cached
        if not response:
            # Get and store a GOOD requests
            raw_response = requests.request(url=url, method=method, headers=headers, data=body)

            response = Response(status_code=raw_response.status_code,
                                headers=dict(raw_response.headers),
                                cookies=raw_response.cookies,
                                reason=raw_response.reason,
                                body=raw_response.text)

            request.config.cache.set(url_signature, response.dump_json)
        else:
            # Recover response from cached info
            response = Response.build_from_json(**response)

        return response

    return _new_fn
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号