我正在尝试使用Pythons mock包来模拟Pythons requests模块.让我在以下场景中工作的基本要求是什么?
在我的views.py中,我有一个函数可以使每次request.get()调用具有不同的响应
def myview(request):
res1 = requests.get('aurl')
res2 = request.get('burl')
res3 = request.get('curl')
Run Code Online (Sandbox Code Playgroud)
在我的测试类中,我想做类似的事情,但无法弄清楚确切的方法调用
步骤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'
Run Code Online (Sandbox Code Playgroud)
第2步:
打电话给我
第3步:
验证响应包含'响应','b响应','c响应'
如何完成步骤1(模拟请求模块)?