我正在使用requests-mock并试图弄清楚如何断言put
请求已被正确调用:
def funtion_to_be_tested():
requests.put(
headers={'X-API-Key': 'api_key'},
url=url,
params={'param1': 'foo'},
data='This is the data'
)
def test_upload(requests_mock):
url = 'http://example.com/upload'
requests_mock.put(url, text='ok')
funtion_to_be_tested()
# how to check that `data` was `This is the data` and that `headers` contained the `X-API-Key`?
编辑:我将要测试的代码重构为一个名为funtion_to_be_tested