我正在尝试使用 Pythons 模拟包 来模拟 Pythons requests
模块。让我在以下情况下工作的基本电话是什么?
在我的views.py 中,我有一个函数可以进行各种requests.get() 调用,每次都有不同的响应
def myview(request):
res1 = requests.get('aurl')
res2 = request.get('burl')
res3 = request.get('curl')
在我的测试类中,我想做这样的事情,但无法弄清楚确切的方法调用
步骤1:
# Mock the requests module
# when mockedRequests.get('aurl') is called then return 'a response'
# when mockedRequests.get('burl') is called then return 'b response'
# when mockedRequests.get('curl') is called then return 'c response'
第2步:
呼唤我的观点
第 3 步:
验证响应包含“a 响应”、“b 响应”、“c 响应”
如何完成第 1 步(模拟请求模块)?
原文由 kk1957 发布,翻译遵循 CC BY-SA 4.0 许可协议
这对我有用: