本文整理汇总了Python中mock.NonCallableMock.send方法的典型用法代码示例。如果您正苦于以下问题:Python NonCallableMock.send方法的具体用法?Python NonCallableMock.send怎么用?Python NonCallableMock.send使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mock.NonCallableMock
的用法示例。
在下文中一共展示了NonCallableMock.send方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: NonCallableMock
# 需要导入模块: from mock import NonCallableMock [as 别名]
# 或者: from mock.NonCallableMock import send [as 别名]
not_found_response.status_code = 404
error_response = NonCallableMock(spec=Response)
error_response.headers = CaseInsensitiveDict(data={"content-type": "application/json"})
error_response.content = json.dumps({"error": "internal error"})
error_response.status_code = 500
def prepare_request(request):
return requests.Session().prepare_request(request)
def return_response(prepared_request, proxies, verify, timeout):
if "404" in prepared_request.url:
return not_found_response
elif "500" in prepared_request.url:
return error_response
else:
return ok_response
MockRequests = NonCallableMock(spec=requests)
MockRequestsSend = Mock(side_effect=return_response)
MockRequests.send = MockRequestsSend
MockRequests.prepare_request = Mock(side_effect=prepare_request)
MockRequestsWithAgent = NonCallableMock(spec=requests)
MockRequestsSendWithAgent = Mock(return_value=agent_response)
MockRequestsWithAgent.send = MockRequestsSendWithAgent
MockRequestsWithAgent.prepare_request = Mock(side_effect=prepare_request)