在 falcon 1.1.0 中,发送数据的唯一方法是通过采用字节数据的 body。在使用 pytest 测试 falcon API 的同时,我们如何在这种情况下使用simulate_post 方法发布 json。
最佳答案
使用 body 将 JSON 作为字符串发送:
data = json.dumps(data)
client.simulate_request(method='POST', path=url, body=data)
您还可以选择设置 content-type header 以指示它是 JSON 请求:
headers = {'Content-Type': 'application/json'}
data = json.dumps(data)
client.simulate_request(method='POST', path=url, headers=headers, body=data)
关于pytest - 如何使用 pytest 在测试 API 中传递 json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50366195/