我想让webtest使用Mock运行多部分表单帖子。我遇到的问题是缺少请求有效负载。
这是我使用webtest的请求:
res = app.post(
my_url,
upload_files=files
)
Pyramid的DummyRequest
boundary = "my random string"
content_type = "multipart/form-data; boundary=" + boundary
headers = {"Content-Type":content_type}
from base64 import standard_b64encode
body = standard_b64encode(boundary)
body += standard_b64encode("Content-Disposition: form-data; name=\"file\"; filename=\"" + filename + "\"")
body += standard_b64encode("Content-Type: */*")
body += actual_file
from pyramid.testing import DummyRequest
request = testing.DummyRequest(path=my_path, headers=headers, body=body, post="lmnop")
request.context = testing.DummyResource()
from somewhere import MyClass
imitate = MyClass(request)
response = imitate.formMethod()
self.assertEqual('200 Success', response.status)
有没有人有幸为虚拟多部分表单请求设置请求有效负载?
我找不到如何让webtest.forms.Upload
玩得很好,因为我可以在那里创建我的对象。任何建议都将不胜感激,谢谢。