Skip to content

Commit

Permalink
Merge pull request #115 from yanzkosim/multipart-formdata-feature
Browse files Browse the repository at this point in the history
allow to upload multipart/form-data
  • Loading branch information
eldaduzman authored Dec 5, 2023
2 parents 5d2538e + ea7db37 commit 1d6d837
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/pymeter/api/samplers.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,22 @@
from pymeter.api.samplers import DummySampler
dummy_sampler = DummySampler("dummy_sampler", "hi dummy")
example - 5:
--------------
Lets send a post request with multipart/form-data:
This post request has a multipart/form-data as a content type, and the body has a single file with `name` being the key and `path/to/file.ext` being the filepath
.. code-block:: python
from pymeter.api import ContentType
from pymeter.api.samplers import HttpSampler
http_sampler = (
HttpSampler("echo_get_request", "http://httpbin.org/post")
.post_multipart_formdata("name", "path/to/file.ext", ContentType.MULTIPART_FORM_DATA)
)
"""
import json
from typing import Dict, List, Union
Expand Down Expand Up @@ -150,3 +166,25 @@ def header(self, key: str, value: str) -> Self:
raise TypeError("value field must be a string")
self._http_sampler_instance = self.java_wrapped_element.header(key, value)
return self

def post_multipart_formdata(self, name: str, filePath: str, content_type: ContentType) -> Self:
"""Create a post request sampler
Args:
name: the name to be assigned to the file part.
filePath: path to the file to be sent in the multipart form body.
content_type (ContentType): the content type of the request
Returns:
Self: a new sampler instance
"""

self._http_sampler_instance = self.java_wrapped_element.bodyFilePart(
name, filePath, content_type.value
).method("POST")
return self

0 comments on commit 1d6d837

Please sign in to comment.