MCPcopy
hub / github.com/encode/starlette / test_multipart_request_multiple_files

Function test_multipart_request_multiple_files

tests/test_formparsers.py:193–218  ·  view source on GitHub ↗
(tmpdir: Path, test_client_factory: TestClientFactory)

Source from the content-addressed store, hash-verified

191
192
193def test_multipart_request_multiple_files(tmpdir: Path, test_client_factory: TestClientFactory) -> None:
194 path1 = os.path.join(tmpdir, "test1.txt")
195 with open(path1, "wb") as file:
196 file.write(b"<file1 content>")
197
198 path2 = os.path.join(tmpdir, "test2.txt")
199 with open(path2, "wb") as file:
200 file.write(b"<file2 content>")
201
202 client = test_client_factory(app)
203 with open(path1, "rb") as f1, open(path2, "rb") as f2:
204 response = client.post("/", files={"test1": f1, "test2": ("test2.txt", f2, "text/plain")})
205 assert response.json() == {
206 "test1": {
207 "filename": "test1.txt",
208 "size": 15,
209 "content": "<file1 content>",
210 "content_type": "text/plain",
211 },
212 "test2": {
213 "filename": "test2.txt",
214 "size": 15,
215 "content": "<file2 content>",
216 "content_type": "text/plain",
217 },
218 }
219
220
221def test_multipart_request_multiple_files_with_headers(tmpdir: Path, test_client_factory: TestClientFactory) -> None:

Callers

nothing calls this directly

Calls 4

test_client_factoryFunction · 0.85
jsonMethod · 0.80
writeMethod · 0.45
postMethod · 0.45

Tested by

no test coverage detected