Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions httpx/_multipart.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,6 @@ class DataField:
def __init__(
self, name: str, value: typing.Union[str, bytes, int, float, None]
) -> None:
if not isinstance(name, str):
raise TypeError(
f"Invalid type for name. Expected str, got {type(name)}: {name!r}"
)
if value is not None and not isinstance(value, (str, bytes, int, float)):
raise TypeError(
f"Invalid type for value. Expected primitive type, got {type(value)}: {value!r}"
)
self.name = name
self.value: typing.Union[str, bytes] = (
value if isinstance(value, bytes) else primitive_value_to_str(value)
Expand Down
27 changes: 0 additions & 27 deletions tests/test_multipart.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,33 +92,6 @@ def test_multipart_header_without_boundary(header: str) -> None:
assert response.request.headers["Content-Type"] == header


@pytest.mark.parametrize(("key"), (b"abc", 1, 2.3, None))
def test_multipart_invalid_key(key):
client = httpx.Client(transport=httpx.MockTransport(echo_request_content))

data = {key: "abc"}
files = {"file": io.BytesIO(b"<file content>")}
with pytest.raises(TypeError) as e:
client.post(
"http://127.0.0.1:8000/",
data=data,
files=files,
)
assert "Invalid type for name" in str(e.value)
assert repr(key) in str(e.value)


@pytest.mark.parametrize(("value"), (object(), {"key": "value"}))
def test_multipart_invalid_value(value):
client = httpx.Client(transport=httpx.MockTransport(echo_request_content))

data = {"text": value}
files = {"file": io.BytesIO(b"<file content>")}
with pytest.raises(TypeError) as e:
client.post("http://127.0.0.1:8000/", data=data, files=files)
assert "Invalid type for value" in str(e.value)


def test_multipart_file_tuple():
client = httpx.Client(transport=httpx.MockTransport(echo_request_content))

Expand Down