MCPcopy
hub / github.com/encode/httpx / test_multipart_file_tuple

Function test_multipart_file_tuple

tests/test_multipart.py:124–149  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

122
123
124def test_multipart_file_tuple():
125 client = httpx.Client(transport=httpx.MockTransport(echo_request_content))
126
127 # Test with a list of values 'data' argument,
128 # and a tuple style 'files' argument.
129 data = {"text": ["abc"]}
130 files = {"file": ("name.txt", io.BytesIO(b"<file content>"))}
131 response = client.post("http://127.0.0.1:8000/", data=data, files=files)
132 boundary = response.request.headers["Content-Type"].split("boundary=")[-1]
133 boundary_bytes = boundary.encode("ascii")
134
135 assert response.status_code == 200
136 assert response.content == b"".join(
137 [
138 b"--" + boundary_bytes + b"\r\n",
139 b'Content-Disposition: form-data; name="text"\r\n',
140 b"\r\n",
141 b"abc\r\n",
142 b"--" + boundary_bytes + b"\r\n",
143 b'Content-Disposition: form-data; name="file"; filename="name.txt"\r\n',
144 b"Content-Type: text/plain\r\n",
145 b"\r\n",
146 b"<file content>\r\n",
147 b"--" + boundary_bytes + b"--\r\n",
148 ]
149 )
150
151
152@pytest.mark.parametrize("file_content_type", [None, "text/plain"])

Callers

nothing calls this directly

Calls 2

postMethod · 0.95
joinMethod · 0.80

Tested by

no test coverage detected