Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can you upload multi-part form data? #158

Open
pinventado opened this issue Feb 21, 2016 · 3 comments
Open

Can you upload multi-part form data? #158

pinventado opened this issue Feb 21, 2016 · 3 comments

Comments

@pinventado
Copy link

Does pyresttest allow tests on the submission of multi-part form data? Specifically, sending some values and an image file. This is how I send the request via cURL:

curl -X POST -F "data1=value1" -F "data2=value2" -F "file=@1.gif" "http://localhost:5000/endpoint"
@svanoort
Copy link
Owner

Hi @pinventado, thank you for reaching out with your question. PyRestTest doesn't have any explicit support for multipart form data, but it is possible to construct one manually and specify it as the post body.

This is similar to constructing a manual form request: https://github.com/svanoort/pyresttest/tree/master/examples/dummyapp-posting-forms.yaml

There's a standing enhancement request for greater support of form data and other custom request bodies, in #115.

I'll go ahead and convert this to a proposed enhancement to tackle in the next couple releases.

@pinventado
Copy link
Author

Ok, looking forward to see this implemented. In case anyone is interested in testing multi-part form data, here's what I did:

Create a file with the multipart-form data. For example, store this into formdata.txt:

--------------------------4935875673ad6222
Content-Disposition: form-data; name="username"
george
--------------------------4935875673ad6222
Content-Disposition: form-data; name="file"; filename="image.jpg"
Content-Type: image/jpeg
Content-Transfer-Encoding: base64

/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDA <rest of base64 string>
--------------------------4935875673ad6222--

Set the appropriate headers and load the data into the body of the request.

- test:
  - group: "Group test"
  - name: "Test name"
  - url: "/endpoint"
  - method: "POST"
  - headers: {'Content-Type': 'multipart/form-data; boundary=------------------------4935875673ad6222'}
  - body: {'file':'formdata.txt'}
  - expected_status: [200]

You could place the multipart/form-data directly in the YAML file, but it takes up a lot of space and the extra line spacing requirements make it look messy.

@svanoort
Copy link
Owner

svanoort commented Mar 2, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants