aboutsummaryrefslogtreecommitdiff
path: root/tests/tasks/test_receiver.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--tests/tasks/test_receiver.py34
1 files changed, 18 insertions, 16 deletions
diff --git a/tests/tasks/test_receiver.py b/tests/tasks/test_receiver.py
index b817162..feb7d7d 100644
--- a/tests/tasks/test_receiver.py
+++ b/tests/tasks/test_receiver.py
@@ -5,6 +5,7 @@
import logging
import uuid
from datetime import UTC, datetime, timedelta
+from http import HTTPStatus
from types import ModuleType
from unittest.mock import Mock, patch
@@ -73,7 +74,7 @@ def test_fetch_source_returns_response_and_body(
httpx_client: Mock, app: Flask, receiver: ModuleType
) -> None:
response = httpx.Response(
- 200,
+ HTTPStatus.OK,
headers={"Content-Type": "text/html"},
content=b"<p>Document</p>",
request=httpx.Request("GET", SOURCE_URL),
@@ -103,14 +104,14 @@ def test_fetch_source_returns_response_and_body(
@pytest.mark.parametrize(
("status_code", "exception_name"),
[
- (400, "VerificationError"),
- (404, "VerificationError"),
- (410, "SourceGoneError"),
- (408, "TemporaryFetchError"),
- (425, "TemporaryFetchError"),
- (429, "TemporaryFetchError"),
- (500, "TemporaryFetchError"),
- (503, "TemporaryFetchError"),
+ (HTTPStatus.BAD_REQUEST, "VerificationError"),
+ (HTTPStatus.NOT_FOUND, "VerificationError"),
+ (HTTPStatus.GONE, "SourceGoneError"),
+ (HTTPStatus.REQUEST_TIMEOUT, "TemporaryFetchError"),
+ (HTTPStatus.TOO_EARLY, "TemporaryFetchError"),
+ (HTTPStatus.TOO_MANY_REQUESTS, "TemporaryFetchError"),
+ (HTTPStatus.INTERNAL_SERVER_ERROR, "TemporaryFetchError"),
+ (HTTPStatus.SERVICE_UNAVAILABLE, "TemporaryFetchError"),
],
)
def test_fetch_source_maps_http_status_to_exception(
@@ -156,7 +157,7 @@ def test_fetch_source_rejects_declared_oversized_body(
set_stream_response(
httpx_client,
httpx.Response(
- 200,
+ HTTPStatus.OK,
headers={"Content-Type": "text/html", "Content-Length": "11"},
content=b"x" * 11,
request=httpx.Request("GET", SOURCE_URL),
@@ -184,7 +185,7 @@ def test_fetch_source_rejects_streamed_oversized_body(
set_stream_response(
httpx_client,
httpx.Response(
- 200,
+ HTTPStatus.OK,
headers={"Content-Type": "text/html"},
stream=BodyStream(),
request=httpx.Request("GET", SOURCE_URL),
@@ -206,7 +207,8 @@ def test_fetch_source_does_not_mask_unexpected_value_error(
monkeypatch: pytest.MonkeyPatch,
) -> None:
set_stream_response(
- httpx_client, httpx.Response(200, request=httpx.Request("GET", SOURCE_URL))
+ httpx_client,
+ httpx.Response(HTTPStatus.OK, request=httpx.Request("GET", SOURCE_URL)),
)
monkeypatch.setattr(
receiver, "read_limited_body", Mock(side_effect=ValueError("unexpected bug"))
@@ -275,7 +277,7 @@ def test_source_mentions_target_by_media_type(
expected: bool,
) -> None:
response = httpx.Response(
- 200,
+ HTTPStatus.OK,
headers={"Content-Type": content_type},
content=body,
request=httpx.Request("GET", SOURCE_URL),
@@ -307,7 +309,7 @@ def test_source_mentions_target_rejects_unsupported_media_type(
headers["Content-Type"] = content_type
response = httpx.Response(
- 200,
+ HTTPStatus.OK,
headers=headers,
content=b"Document",
request=httpx.Request("GET", SOURCE_URL),
@@ -710,7 +712,7 @@ def test_fetch_source_ignores_invalid_content_length(
httpx_client: Mock, app: Flask, receiver: ModuleType
) -> None:
response = httpx.Response(
- 200,
+ HTTPStatus.OK,
headers={"Content-Type": "text/html", "Content-Length": "invalid"},
content=b"<p>Document</p>",
request=httpx.Request("GET", SOURCE_URL),
@@ -731,7 +733,7 @@ def test_source_mentions_target_falls_back_for_unknown_encoding(
body = f"Reply to {TARGET_URL}".encode()
response = httpx.Response(
- 200,
+ HTTPStatus.OK,
headers={"Content-Type": "text/plain"},
content=body,
request=httpx.Request("GET", SOURCE_URL),