utils.py 文件源码

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

项目:drf-reverse-proxy 作者: danpoland 项目源码 文件源码
def get_urlopen_mock(body=DEFAULT_BODY_CONTENT, headers=None, status=200):
    mockHttpResponse = Mock(name='httplib.HTTPResponse')

    headers = urllib3.response.HTTPHeaderDict(headers)

    if not hasattr(body, 'read'):
        body = BytesIO(body)

    else:
        body.seek(0)

    urllib3_response = urllib3.HTTPResponse(body,
                                            headers,
                                            status,
                                            preload_content=False,
                                            original_response=mockHttpResponse)

    return MagicMock(return_value=urllib3_response)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号