aboutsummaryrefslogtreecommitdiff
path: root/tests/test_net.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_net.py')
-rw-r--r--tests/test_net.py23
1 files changed, 14 insertions, 9 deletions
diff --git a/tests/test_net.py b/tests/test_net.py
index b778310..3b754c0 100644
--- a/tests/test_net.py
+++ b/tests/test_net.py
@@ -6,6 +6,7 @@
import ipaddress
import socket
+from http import HTTPStatus
from unittest.mock import Mock, PropertyMock, patch
import httpcore
@@ -113,9 +114,11 @@ def test_backend_closes_socket_on_failure(
@pytest.mark.parametrize("mode", ["declared", "streamed"])
def test_read_limited_body_raises_specific_size_error(mode: str) -> None:
response = (
- httpx.Response(200, headers={"Content-Length": "11"}, content=b"x" * 11)
+ httpx.Response(
+ HTTPStatus.OK, headers={"Content-Length": "11"}, content=b"x" * 11
+ )
if mode == "declared"
- else httpx.Response(200, stream=httpx.ByteStream(b"x" * 11))
+ else httpx.Response(HTTPStatus.OK, stream=httpx.ByteStream(b"x" * 11))
)
with pytest.raises(ResponseTooLargeError, match="Source document is too large"):
@@ -164,7 +167,7 @@ def test_transport_keeps_original_http_host_and_tls_sni(
with httpx.Client(transport=PublicHTTPTransport(5.0), trust_env=False) as client:
response = client.get(f"{scheme}://source.example/path")
- assert response.status_code == 200
+ assert response.status_code == HTTPStatus.OK
assert response.text == "OK"
assert b"Host: source.example\r\n" in stream.writes
assert b"GET /path HTTP/1.1\r\n" in stream.writes
@@ -321,12 +324,14 @@ def test_public_addresses_rejects_empty_dns_result() -> None:
@pytest.mark.parametrize(
("status", "expected"),
[
- pytest.param(200, False, id="success"),
- pytest.param(400, False, id="client-error"),
- pytest.param(408, True, id="request-timeout"),
- pytest.param(425, True, id="too-early"),
- pytest.param(429, True, id="too-many-requests"),
- pytest.param(500, True, id="server-error-lower-bound"),
+ pytest.param(HTTPStatus.OK, False, id="success"),
+ pytest.param(HTTPStatus.BAD_REQUEST, False, id="client-error"),
+ pytest.param(HTTPStatus.REQUEST_TIMEOUT, True, id="request-timeout"),
+ pytest.param(HTTPStatus.TOO_EARLY, True, id="too-early"),
+ pytest.param(HTTPStatus.TOO_MANY_REQUESTS, True, id="too-many-requests"),
+ pytest.param(
+ HTTPStatus.INTERNAL_SERVER_ERROR, True, id="server-error-lower-bound"
+ ),
pytest.param(599, True, id="server-error-upper-bound"),
pytest.param(600, False, id="outside-server-error-range"),
],