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

Function test_multipart_file_tuple_headers

tests/test_multipart.py:153–175  ·  view source on GitHub ↗
(file_content_type: str | None)

Source from the content-addressed store, hash-verified

151
152@pytest.mark.parametrize("file_content_type", [None, "text/plain"])
153def test_multipart_file_tuple_headers(file_content_type: str | None) -> None:
154 file_name = "test.txt"
155 file_content = io.BytesIO(b"<file content>")
156 file_headers = {"Expires": "0"}
157
158 url = "https://www.example.com/"
159 headers = {"Content-Type": "multipart/form-data; boundary=BOUNDARY"}
160 files = {"file": (file_name, file_content, file_content_type, file_headers)}
161
162 request = httpx.Request("POST", url, headers=headers, files=files)
163 request.read()
164
165 assert request.headers == {
166 "Host": "www.example.com",
167 "Content-Type": "multipart/form-data; boundary=BOUNDARY",
168 "Content-Length": str(len(request.content)),
169 }
170 assert request.content == (
171 f'--BOUNDARY\r\nContent-Disposition: form-data; name="file"; '
172 f'filename="{file_name}"\r\nExpires: 0\r\nContent-Type: '
173 f"text/plain\r\n\r\n<file content>\r\n--BOUNDARY--\r\n"
174 "".encode("ascii")
175 )
176
177
178def test_multipart_headers_include_content_type() -> None:

Callers

nothing calls this directly

Calls 1

readMethod · 0.95

Tested by

no test coverage detected