我有一个web.py应用程序,需要做一些测试+获取测试覆盖率报告。我需要测试POST方法并发送一个包含ascii字符STL(3d文件)的JSON。
使用requests
模块时,我可以轻松地将此json
附加到POST并完美地声明所有内容,但是当我尝试切换到paste.fixture
时,我不知道该怎么做发送此json,我找不到任何示例,更不用说文档了。
使用请求测试脚本(有效):
up = {
"stl_file": open("3dModel.stl", "rb"),
"Stl_type": "regular",
"Mark": "U",
"parameters": (None, open("parameters.json"), "application/json")
}
r = requests.post("http://%s/StlProcessing" % host, files=up)
使用paste.fixture的测试脚本(不起作用):
middleware = []
testApp = TestApp(app.wsgifunc(*middleware))
up = {
"stl_file": open("3dModel.stl", "rb"),
"Stl_type": "regular",
"Mark": "U",
"parameters": (None, open("parameters.json"), "application/json")
}
with open('upload_files.txt', 'w') as outfile:
json.dump(str(up), outfile)
filedata = [("Filedata","upload_files.txt")]
r = testApp.post("http://%s/StlProcessing" % host, upload_files=filedata)
我希望该帖子能够上传JSON