【发布时间】:2021-08-10 23:35:32
【问题描述】:
我正在尝试使用 Pythons 模拟包来模拟 Pythons 请求模块。让我在以下场景中工作的基本调用是什么?
我有一个函数可以进行各种 requests.post() 调用,每次都有不同的响应 它们具有相同的 URL,仅在 Body 中发生变化,它们是按顺序执行的,首先是一个调用,然后是另一个调用
def myview(request):
res1 = requests.post(("http://aurl",
body='[{"kind": "company"}]',
content_type="application/json"))
res2 = requests.post(("http://aurl",
body='[{"kind": "people"}]',
content_type="application/json"))
在我的测试类中,我想做这样的事情,但无法弄清楚确切的方法调用
第 1 步:
# Mock the requests module
# when mockedRequests.post('aurl') with body "company" is called then return 'a response'
# when mockedRequests.post('aurl') with body "people" is called then return 'b response'
第 2 步:
verify response contains 'a response', 'b response' , 'c response'
如何完成第 1 步(模拟请求模块)?
【问题讨论】: