aboutsummaryrefslogtreecommitdiff
path: root/tests/tasks
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--tests/tasks/test_discovery.py26
-rw-r--r--tests/tasks/test_receiver.py19
-rw-r--r--tests/tasks/test_sender.py23
3 files changed, 64 insertions, 4 deletions
diff --git a/tests/tasks/test_discovery.py b/tests/tasks/test_discovery.py
index 2d6c37e..7c28108 100644
--- a/tests/tasks/test_discovery.py
+++ b/tests/tasks/test_discovery.py
@@ -569,7 +569,7 @@ def test_discovery_falls_back_to_get_after_head_request_error(
assert methods == ["HEAD", "GET"]
-def test_discovery_falls_back_to_get_after_head_dns_failure(
+def test_discovery_does_not_suppress_unexpected_head_error(
app: Flask, sender_module: ModuleType
) -> None:
methods: list[str] = []
@@ -588,11 +588,13 @@ def test_discovery_falls_back_to_get_after_head_dns_failure(
transport=httpx.MockTransport(handler),
event_hooks={"request": [request_hook]},
) as client,
+ pytest.raises(
+ sender_module.TemporarySenderError, match="HEAD DNS lookup failed"
+ ),
):
- endpoint = sender_module.discover_webmention_endpoint(client, TARGET_URL)
+ sender_module.discover_webmention_endpoint(client, TARGET_URL)
- assert endpoint == ENDPOINT_URL
- assert methods == ["GET"]
+ assert methods == []
def test_discovery_get_error_after_head_error_is_not_suppressed(
@@ -753,6 +755,22 @@ def test_read_target_body_rejects_declared_oversized_body(
sender_module.read_target_body(response)
+def test_read_target_body_does_not_mask_unexpected_value_error(
+ app: Flask, sender_module: ModuleType, monkeypatch: pytest.MonkeyPatch
+) -> None:
+ monkeypatch.setattr(
+ sender_module,
+ "read_limited_body",
+ Mock(side_effect=ValueError("unrelated processing error")),
+ )
+
+ with (
+ app.app_context(),
+ pytest.raises(ValueError, match="unrelated processing error"),
+ ):
+ sender_module.read_target_body(httpx.Response(200))
+
+
def test_read_target_body_ignores_invalid_content_length(
app: Flask, sender_module: ModuleType
) -> None:
diff --git a/tests/tasks/test_receiver.py b/tests/tasks/test_receiver.py
index 133ab56..51d1bb6 100644
--- a/tests/tasks/test_receiver.py
+++ b/tests/tasks/test_receiver.py
@@ -198,6 +198,25 @@ def test_fetch_source_rejects_streamed_oversized_body(
receiver.fetch_source(SOURCE_URL)
+@patch("webmentions_ssg.tasks.receiver.httpx.Client")
+def test_fetch_source_does_not_mask_unexpected_value_error(
+ httpx_client: Mock,
+ app: Flask,
+ receiver: ModuleType,
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ set_stream_response(
+ httpx_client,
+ httpx.Response(200, request=httpx.Request("GET", SOURCE_URL)),
+ )
+ monkeypatch.setattr(
+ receiver, "read_limited_body", Mock(side_effect=ValueError("unexpected bug"))
+ )
+
+ with app.app_context(), pytest.raises(ValueError, match="unexpected bug"):
+ receiver.fetch_source(SOURCE_URL)
+
+
@patch("webmentions_ssg.tasks.receiver.fetch_source")
@pytest.mark.parametrize(
("content_type", "body", "expected"),
diff --git a/tests/tasks/test_sender.py b/tests/tasks/test_sender.py
index 94523e5..818092b 100644
--- a/tests/tasks/test_sender.py
+++ b/tests/tasks/test_sender.py
@@ -431,6 +431,29 @@ def test_sender_malformed_request_is_terminal(
assert post.call_count == (1 if stage == "post" else 0)
+def test_sender_logs_unexpected_value_error_traceback(
+ app: Flask,
+ sender_module: ModuleType,
+ monkeypatch: pytest.MonkeyPatch,
+ caplog: pytest.LogCaptureFixture,
+) -> None:
+ identifier = create_sent_webmention(app)
+ _, _, discover, _ = mock_sender_requests(sender_module, monkeypatch)
+ discover.side_effect = ValueError("unexpected parsing bug")
+
+ with caplog.at_level(logging.ERROR):
+ sender_module.send_webmention.call_local(identifier)
+
+ assert f"Unexpected error sending SentWebmention {identifier}" in caplog.text
+ assert "ValueError: unexpected parsing bug" in caplog.text
+ with app.app_context():
+ webmention = db.session.get(SentWebmention, identifier)
+ assert webmention is not None
+ assert webmention.status == SentWebmentionStatus.FAILED
+ assert webmention.failure_reason == "unexpected parsing bug"
+ assert webmention.processed_revision == 1
+
+
@pytest.mark.parametrize(
("target", "reason"),
[