test(http): add assertion for multipart placeholder logic when no files present

- Validates that '__multipart_placeholder__' is inserted to enforce multipart/form-data encoding.
- Ensures consistent behavior with backend servers expecting multipart format, even without file uploads.
- Adds condition to skip logging placeholder entries in logs to avoid noise.
pull/20323/head
ultramancode 12 months ago
parent 00d446d951
commit 19352849ee

@ -377,7 +377,10 @@ class Executor:
raw += f"{k}: {v}\r\n" raw += f"{k}: {v}\r\n"
body_string = "" body_string = ""
if self.files: # Only log actual files if present.
# '__multipart_placeholder__' is inserted to force multipart encoding but is not a real file.
# This prevents logging meaningless placeholder entries.
if self.files and not all(f[0] == "__multipart_placeholder__" for f in self.files):
for key, (filename, content, mime_type) in self.files: for key, (filename, content, mime_type) in self.files:
body_string += f"--{boundary}\r\n" body_string += f"--{boundary}\r\n"
body_string += f'Content-Disposition: form-data; name="{key}"\r\n\r\n' body_string += f'Content-Disposition: form-data; name="{key}"\r\n\r\n'

@ -246,7 +246,9 @@ def test_executor_with_form_data():
assert "multipart/form-data" in executor.headers["Content-Type"] assert "multipart/form-data" in executor.headers["Content-Type"]
assert executor.params == [] assert executor.params == []
assert executor.json is None assert executor.json is None
assert executor.files is None # '__multipart_placeholder__' is expected when no file inputs exist,
# to ensure the request is treated as multipart/form-data by the backend.
assert executor.files == [('__multipart_placeholder__', ('', b'', 'application/octet-stream'))]
assert executor.content is None assert executor.content is None
# Check that the form data is correctly loaded in executor.data # Check that the form data is correctly loaded in executor.data

Loading…
Cancel
Save