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
34 changes: 17 additions & 17 deletions tests/client/test_async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ async def test_get(server):
url = server.url
async with httpx.AsyncClient(http2=True) as client:
response = await client.get(url)
assert response.status_code == 200
assert response.status_code == httpx.codes.OK.value
assert response.text == "Hello, world!"
assert response.http_version == "HTTP/1.1"
assert response.headers
Expand Down Expand Up @@ -45,7 +45,7 @@ async def test_build_request(server):
request.headers.update(headers)
response = await client.send(request)

assert response.status_code == 200
assert response.status_code == httpx.codes.OK.value
assert response.url == url

assert response.json()["Custom-header"] == "value"
Expand All @@ -56,15 +56,15 @@ async def test_post(server):
url = server.url
async with httpx.AsyncClient() as client:
response = await client.post(url, content=b"Hello, world!")
assert response.status_code == 200
assert response.status_code == httpx.codes.OK.value


@pytest.mark.anyio
async def test_post_json(server):
url = server.url
async with httpx.AsyncClient() as client:
response = await client.post(url, json={"text": "Hello, world!"})
assert response.status_code == 200
assert response.status_code == httpx.codes.OK.value


@pytest.mark.anyio
Expand All @@ -73,7 +73,7 @@ async def test_stream_response(server):
async with client.stream("GET", server.url) as response:
body = await response.aread()

assert response.status_code == 200
assert response.status_code == httpx.codes.OK.value
assert body == b"Hello, world!"
assert response.content == b"Hello, world!"

Expand All @@ -84,7 +84,7 @@ async def test_access_content_stream_response(server):
async with client.stream("GET", server.url) as response:
pass

assert response.status_code == 200
assert response.status_code == httpx.codes.OK.value
with pytest.raises(httpx.ResponseNotRead):
response.content # noqa: B018

Expand All @@ -97,7 +97,7 @@ async def hello_world() -> typing.AsyncIterator[bytes]:

async with httpx.AsyncClient() as client:
response = await client.post(server.url, content=hello_world())
assert response.status_code == 200
assert response.status_code == httpx.codes.OK.value


@pytest.mark.anyio
Expand Down Expand Up @@ -131,37 +131,37 @@ async def test_raise_for_status(server):
async def test_options(server):
async with httpx.AsyncClient() as client:
response = await client.options(server.url)
assert response.status_code == 200
assert response.status_code == httpx.codes.OK.value
assert response.text == "Hello, world!"


@pytest.mark.anyio
async def test_head(server):
async with httpx.AsyncClient() as client:
response = await client.head(server.url)
assert response.status_code == 200
assert response.status_code == httpx.codes.OK.value
assert response.text == ""


@pytest.mark.anyio
async def test_put(server):
async with httpx.AsyncClient() as client:
response = await client.put(server.url, content=b"Hello, world!")
assert response.status_code == 200
assert response.status_code == httpx.codes.OK.value


@pytest.mark.anyio
async def test_patch(server):
async with httpx.AsyncClient() as client:
response = await client.patch(server.url, content=b"Hello, world!")
assert response.status_code == 200
assert response.status_code == httpx.codes.OK.value


@pytest.mark.anyio
async def test_delete(server):
async with httpx.AsyncClient() as client:
response = await client.delete(server.url)
assert response.status_code == 200
assert response.status_code == httpx.codes.OK.value
assert response.text == "Hello, world!"


Expand All @@ -175,7 +175,7 @@ async def test_100_continue(server):
server.url.copy_with(path="/echo_body"), headers=headers, content=content
)

assert response.status_code == 200
assert response.status_code == httpx.codes.OK.value
assert response.content == content


Expand Down Expand Up @@ -305,11 +305,11 @@ async def test_mounted_transport():

async with httpx.AsyncClient(transport=transport, mounts=mounts) as client:
response = await client.get("https://www.example.com")
assert response.status_code == 200
assert response.status_code == httpx.codes.OK.value
assert response.json() == {"app": "unmounted"}

response = await client.get("custom://www.example.com")
assert response.status_code == 200
assert response.status_code == httpx.codes.OK.value
assert response.json() == {"app": "mounted"}


Expand All @@ -322,7 +322,7 @@ async def hello_world(request: httpx.Request) -> httpx.Response:

async with httpx.AsyncClient(transport=transport) as client:
response = await client.get("https://www.example.com")
assert response.status_code == 200
assert response.status_code == httpx.codes.OK.value
assert response.text == "Hello, world!"


Expand Down Expand Up @@ -371,5 +371,5 @@ async def test_server_extensions(server):
url = server.url
async with httpx.AsyncClient(http2=True) as client:
response = await client.get(url)
assert response.status_code == 200
assert response.status_code == httpx.codes.OK.value
assert response.extensions["http_version"] == b"HTTP/1.1"
54 changes: 27 additions & 27 deletions tests/client/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ async def test_basic_auth() -> None:
async with httpx.AsyncClient(transport=httpx.MockTransport(app)) as client:
response = await client.get(url, auth=auth)

assert response.status_code == 200
assert response.status_code == httpx.codes.OK.value
assert response.json() == {"auth": "Basic dXNlcjpwYXNzd29yZDEyMw=="}


Expand All @@ -187,7 +187,7 @@ async def test_basic_auth_with_stream() -> None:
async with client.stream("GET", url) as response:
await response.aread()

assert response.status_code == 200
assert response.status_code == httpx.codes.OK.value
assert response.json() == {"auth": "Basic dXNlcjpwYXNzd29yZDEyMw=="}


Expand All @@ -199,7 +199,7 @@ async def test_basic_auth_in_url() -> None:
async with httpx.AsyncClient(transport=httpx.MockTransport(app)) as client:
response = await client.get(url)

assert response.status_code == 200
assert response.status_code == httpx.codes.OK.value
assert response.json() == {"auth": "Basic dXNlcjpwYXNzd29yZDEyMw=="}


Expand All @@ -214,7 +214,7 @@ async def test_basic_auth_on_session() -> None:
) as client:
response = await client.get(url)

assert response.status_code == 200
assert response.status_code == httpx.codes.OK.value
assert response.json() == {"auth": "Basic dXNlcjpwYXNzd29yZDEyMw=="}


Expand All @@ -230,7 +230,7 @@ def auth(request: httpx.Request) -> httpx.Request:
async with httpx.AsyncClient(transport=httpx.MockTransport(app)) as client:
response = await client.get(url, auth=auth)

assert response.status_code == 200
assert response.status_code == httpx.codes.OK.value
assert response.json() == {"auth": "Token 123"}


Expand All @@ -247,7 +247,7 @@ def test_netrc_auth_credentials_exist() -> None:
with httpx.Client(transport=httpx.MockTransport(app), auth=auth) as client:
response = client.get(url)

assert response.status_code == 200
assert response.status_code == httpx.codes.OK.value
assert response.json() == {
"auth": "Basic ZXhhbXBsZS11c2VybmFtZTpleGFtcGxlLXBhc3N3b3Jk"
}
Expand All @@ -266,7 +266,7 @@ def test_netrc_auth_credentials_do_not_exist() -> None:
with httpx.Client(transport=httpx.MockTransport(app), auth=auth) as client:
response = client.get(url)

assert response.status_code == 200
assert response.status_code == httpx.codes.OK.value
assert response.json() == {"auth": None}


Expand Down Expand Up @@ -296,7 +296,7 @@ async def test_auth_disable_per_request() -> None:
) as client:
response = await client.get(url, auth=None)

assert response.status_code == 200
assert response.status_code == httpx.codes.OK.value
assert response.json() == {"auth": None}


Expand Down Expand Up @@ -331,7 +331,7 @@ async def test_auth_property() -> None:

url = "https://example.org/"
response = await client.get(url)
assert response.status_code == 200
assert response.status_code == httpx.codes.OK.value
assert response.json() == {"auth": "Basic dXNlcjpwYXNzd29yZDEyMw=="}


Expand Down Expand Up @@ -362,7 +362,7 @@ async def test_digest_auth_returns_no_auth_if_no_digest_header_in_response() ->
async with httpx.AsyncClient(transport=httpx.MockTransport(app)) as client:
response = await client.get(url, auth=auth)

assert response.status_code == 200
assert response.status_code == httpx.codes.OK.value
assert response.json() == {"auth": None}
assert len(response.history) == 0

Expand All @@ -376,7 +376,7 @@ def test_digest_auth_returns_no_auth_if_alternate_auth_scheme() -> None:
client = httpx.Client(transport=httpx.MockTransport(app))
response = client.get(url, auth=auth)

assert response.status_code == 401
assert response.status_code == httpx.codes.UNAUTHORIZED.value
assert response.json() == {"auth": None}
assert len(response.history) == 0

Expand All @@ -391,7 +391,7 @@ async def test_digest_auth_200_response_including_digest_auth_header() -> None:
async with httpx.AsyncClient(transport=httpx.MockTransport(app)) as client:
response = await client.get(url, auth=auth)

assert response.status_code == 200
assert response.status_code == httpx.codes.OK.value
assert response.json() == {"auth": None}
assert len(response.history) == 0

Expand All @@ -405,7 +405,7 @@ async def test_digest_auth_401_response_without_digest_auth_header() -> None:
async with httpx.AsyncClient(transport=httpx.MockTransport(app)) as client:
response = await client.get(url, auth=auth)

assert response.status_code == 401
assert response.status_code == httpx.codes.UNAUTHORIZED.value
assert response.json() == {"auth": None}
assert len(response.history) == 0

Expand Down Expand Up @@ -434,7 +434,7 @@ async def test_digest_auth(
async with httpx.AsyncClient(transport=httpx.MockTransport(app)) as client:
response = await client.get(url, auth=auth)

assert response.status_code == 200
assert response.status_code == httpx.codes.OK.value
assert len(response.history) == 1

authorization = typing.cast(typing.Dict[str, typing.Any], response.json())["auth"]
Expand Down Expand Up @@ -465,7 +465,7 @@ async def test_digest_auth_no_specified_qop() -> None:
async with httpx.AsyncClient(transport=httpx.MockTransport(app)) as client:
response = await client.get(url, auth=auth)

assert response.status_code == 200
assert response.status_code == httpx.codes.OK.value
assert len(response.history) == 1

authorization = typing.cast(typing.Dict[str, typing.Any], response.json())["auth"]
Expand Down Expand Up @@ -497,7 +497,7 @@ async def test_digest_auth_qop_including_spaces_and_auth_returns_auth(qop: str)
async with httpx.AsyncClient(transport=httpx.MockTransport(app)) as client:
response = await client.get(url, auth=auth)

assert response.status_code == 200
assert response.status_code == httpx.codes.OK.value
assert len(response.history) == 1


Expand Down Expand Up @@ -532,7 +532,7 @@ async def test_digest_auth_incorrect_credentials() -> None:
async with httpx.AsyncClient(transport=httpx.MockTransport(app)) as client:
response = await client.get(url, auth=auth)

assert response.status_code == 401
assert response.status_code == httpx.codes.UNAUTHORIZED.value
assert len(response.history) == 1


Expand All @@ -546,8 +546,8 @@ async def test_digest_auth_reuses_challenge() -> None:
response_1 = await client.get(url, auth=auth)
response_2 = await client.get(url, auth=auth)

assert response_1.status_code == 200
assert response_2.status_code == 200
assert response_1.status_code == httpx.codes.OK.value
assert response_2.status_code == httpx.codes.OK.value

assert len(response_1.history) == 1
assert len(response_2.history) == 0
Expand All @@ -561,7 +561,7 @@ async def test_digest_auth_resets_nonce_count_after_401() -> None:

async with httpx.AsyncClient(transport=httpx.MockTransport(app)) as client:
response_1 = await client.get(url, auth=auth)
assert response_1.status_code == 200
assert response_1.status_code == httpx.codes.OK.value
assert len(response_1.history) == 1

first_nonce = parse_keqv_list(
Expand All @@ -577,7 +577,7 @@ async def test_digest_auth_resets_nonce_count_after_401() -> None:
# we expect the client again to try to authenticate,
# i.e. the history length must be 1
response_2 = await client.get(url, auth=auth)
assert response_2.status_code == 200
assert response_2.status_code == httpx.codes.OK.value
assert len(response_2.history) == 1

second_nonce = parse_keqv_list(
Expand Down Expand Up @@ -645,7 +645,7 @@ async def test_async_auth_history() -> None:
async with httpx.AsyncClient(transport=httpx.MockTransport(app)) as client:
response = await client.get(url, auth=auth)

assert response.status_code == 200
assert response.status_code == httpx.codes.OK.value
assert response.json() == {"auth": "Repeat abc.abc"}

assert len(response.history) == 2
Expand All @@ -671,7 +671,7 @@ def test_sync_auth_history() -> None:
with httpx.Client(transport=httpx.MockTransport(app)) as client:
response = client.get(url, auth=auth)

assert response.status_code == 200
assert response.status_code == httpx.codes.OK.value
assert response.json() == {"auth": "Repeat abc.abc"}

assert len(response.history) == 2
Expand Down Expand Up @@ -719,7 +719,7 @@ async def test_async_auth_reads_response_body() -> None:
async with httpx.AsyncClient(transport=httpx.MockTransport(app)) as client:
response = await client.get(url, auth=auth)

assert response.status_code == 200
assert response.status_code == httpx.codes.OK.value
assert response.json() == {"auth": '{"auth":"xyz"}'}


Expand All @@ -735,7 +735,7 @@ def test_sync_auth_reads_response_body() -> None:
with httpx.Client(transport=httpx.MockTransport(app)) as client:
response = client.get(url, auth=auth)

assert response.status_code == 200
assert response.status_code == httpx.codes.OK.value
assert response.json() == {"auth": '{"auth":"xyz"}'}


Expand All @@ -753,7 +753,7 @@ async def test_async_auth() -> None:
async with httpx.AsyncClient(transport=httpx.MockTransport(app)) as client:
response = await client.get(url, auth=auth)

assert response.status_code == 200
assert response.status_code == httpx.codes.OK.value
assert response.json() == {"auth": "async-auth"}


Expand All @@ -768,5 +768,5 @@ def test_sync_auth() -> None:
with httpx.Client(transport=httpx.MockTransport(app)) as client:
response = client.get(url, auth=auth)

assert response.status_code == 200
assert response.status_code == httpx.codes.OK.value
assert response.json() == {"auth": "sync-auth"}
Loading