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)
评论列表
文章目录