Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
trim21 committed Apr 17, 2024
1 parent 84375ae commit ac2aaf4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
25 changes: 21 additions & 4 deletions tests/test_content.py
@@ -1,3 +1,4 @@
import enum
import io
import typing

Expand Down Expand Up @@ -182,7 +183,14 @@ async def test_json_content():

@pytest.mark.anyio
async def test_urlencoded_content():
request = httpx.Request(method, url, data={"Hello": "world!"})
class Flag(enum.Enum):
flag = "f"

request = httpx.Request(
method,
url,
data={"Hello": "world!", "foo": Flag.flag, "like": True, "bar": 123},
)
assert isinstance(request.stream, typing.Iterable)
assert isinstance(request.stream, typing.AsyncIterable)

Expand All @@ -191,11 +199,11 @@ async def test_urlencoded_content():

assert request.headers == {
"Host": "www.example.com",
"Content-Length": "14",
"Content-Length": "38",
"Content-Type": "application/x-www-form-urlencoded",
}
assert sync_content == b"Hello=world%21"
assert async_content == b"Hello=world%21"
assert sync_content == b"Hello=world%21&foo=f&like=true&bar=123"
assert async_content == b"Hello=world%21&foo=f&like=true&bar=123"


@pytest.mark.anyio
Expand Down Expand Up @@ -484,3 +492,12 @@ async def hello_world() -> typing.AsyncIterator[bytes]:
def test_response_invalid_argument():
with pytest.raises(TypeError):
httpx.Response(200, content=123) # type: ignore

with pytest.raises(TypeError):
httpx.Request("GET", "", data={"hello": b""})

class AnyObject:
pass

with pytest.raises(TypeError):
httpx.Request("GET", "", data={"hello": AnyObject()})
2 changes: 1 addition & 1 deletion tests/test_multipart.py
Expand Up @@ -213,7 +213,7 @@ def test_multipart_encode(tmp_path: typing.Any) -> None:

url = "https://www.example.com/"
headers = {"Content-Type": "multipart/form-data; boundary=BOUNDARY"}
data = {
data: dict[str, typing.Any] = {
"a": "1",
"b": b"C",
"c": ["11", "22", "33"],
Expand Down

0 comments on commit ac2aaf4

Please sign in to comment.