I'd like to get webtest to run a multipart form post using Mock. The issue I have is the request payload is missing.
Here's my request using webtest:
res = app.post(
my_url,
upload_files=files
)
Pyramid's 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)
Has anyone had any luck to set request payload for a dummy multipart form request?
I couldn't find how to get webtest.forms.Upload
to play nice, since I can create my object there. Any suggestions would be appreciated, thanks.