aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDennis Fink2026-11-13 22:12:02 +0100
committerDennis Fink2026-11-13 22:12:02 +0100
commit2366d455c7d1ae16c84e0bcbffb94ed762c16832 (patch)
tree51de07737ebc12fdcbf29a0a405ff2cd5aa9eb87 /tests
parent64f328d86bba9caa9d0a60aa89e06f70403942b9 (diff)
downloadwebmentions-ssg-2366d455c7d1ae16c84e0bcbffb94ed762c16832.tar.gz
webmentions-ssg-2366d455c7d1ae16c84e0bcbffb94ed762c16832.zip
refactor(core): split task workflows into focused helpers
Decompose receiver verification, source scanning, and Webmention delivery into explicit claim, check, reconciliation, and outcome-recording stages. Extract Huey backend parsing helpers and add focused tests for the new task boundaries while preserving existing processing semantics.
Diffstat (limited to '')
-rw-r--r--tests/tasks/test_receiver.py19
-rw-r--r--tests/tasks/test_scanner.py33
-rw-r--r--tests/tasks/test_sender.py20
3 files changed, 72 insertions, 0 deletions
diff --git a/tests/tasks/test_receiver.py b/tests/tasks/test_receiver.py
index 44e8c58..b817162 100644
--- a/tests/tasks/test_receiver.py
+++ b/tests/tasks/test_receiver.py
@@ -321,6 +321,25 @@ def test_source_mentions_target_rejects_unsupported_media_type(
receiver.source_mentions_target(SOURCE_URL, TARGET_URL)
+@pytest.mark.parametrize(
+ ("mentions", "expected_status", "expected_reason"),
+ [(True, "verified", None), (False, "deleted", "Source does not mention target")],
+)
+def test_check_source_returns_outcome(
+ receiver: ModuleType,
+ monkeypatch: pytest.MonkeyPatch,
+ mentions: bool,
+ expected_status: str,
+ expected_reason: str | None,
+) -> None:
+ monkeypatch.setattr(receiver, "source_mentions_target", Mock(return_value=mentions))
+ claim = receiver.VerificationClaim(
+ uuid.uuid7(), SOURCE_URL, TARGET_URL, datetime.now(UTC)
+ )
+
+ assert receiver.check_source(claim) == (expected_status, expected_reason)
+
+
@patch("webmentions_ssg.tasks.receiver.source_mentions_target")
def test_verify_webmention_marks_row_verifying_before_check(
source_mentions_target: Mock, app: Flask, receiver: ModuleType
diff --git a/tests/tasks/test_scanner.py b/tests/tasks/test_scanner.py
index c0b9223..d16729c 100644
--- a/tests/tasks/test_scanner.py
+++ b/tests/tasks/test_scanner.py
@@ -82,6 +82,39 @@ def test_manual_scan_propagates_unrelated_errors(
scanner_module.manual_scan_sources.call_local()
+def test_scan_tree_returns_count_and_seen_paths(
+ app: Flask, scanner_module: ModuleType, tmp_path: Path, monkeypatch: MonkeyPatch
+) -> None:
+ for name in ("good", "bad"):
+ directory = tmp_path / name
+ directory.mkdir()
+ (directory / "index.html").write_text("<html></html>")
+
+ def parse(index_path: Path, **kwargs: Any) -> source_parser.ScannedSource:
+ if index_path.parent.name == "bad":
+ raise source_parser.SourceScanError("Unparseable source")
+ return source_parser.ScannedSource(
+ path="good/index.html",
+ url=f"{BASE_URL}good/",
+ content_hash="0" * 32,
+ targets=frozenset(),
+ )
+
+ monkeypatch.setattr(scanner_module, "scan_source_file", parse)
+ sources: dict[str, Source] = {}
+ urls: dict[str, str] = {}
+
+ with app.app_context():
+ scan = scanner_module.scan_tree(
+ tmp_path, BASE_URL, sources, urls, datetime.now(UTC)
+ )
+
+ assert scan.scanned_count == 1
+ assert scan.seen_paths == frozenset({"good/index.html", "bad/index.html"})
+ assert list(sources) == ["good/index.html"]
+ assert urls == {f"{BASE_URL}good/": "good/index.html"}
+
+
def test_scan_creates_source_and_webmentions(
app: Flask, scanner_module: ModuleType, tmp_path: Path, monkeypatch: MonkeyPatch
) -> None:
diff --git a/tests/tasks/test_sender.py b/tests/tasks/test_sender.py
index 818092b..7f453c1 100644
--- a/tests/tasks/test_sender.py
+++ b/tests/tasks/test_sender.py
@@ -127,6 +127,26 @@ def test_attempt_is_current(
assert sender_module.attempt_is_current(webmention, revision) is expected
+def test_deliver_webmention_returns_retryable_outcome(
+ app: Flask, sender_module: ModuleType, monkeypatch: pytest.MonkeyPatch
+) -> None:
+ mock_sender_requests(sender_module, monkeypatch, result=(503, None))
+
+ with app.app_context():
+ result = sender_module.deliver_webmention(
+ SOURCE_URL, TARGET_URL, webmention_uuid=uuid.uuid7()
+ )
+
+ assert result == sender_module.DeliveryResult(
+ status=SentWebmentionStatus.FAILED,
+ reason="Webmention endpoint returned HTTP 503",
+ endpoint=ENDPOINT_URL,
+ response_status=503,
+ terminal=False,
+ temporary_failure=True,
+ )
+
+
def test_send_webmention_persists_success(
app: Flask, sender_module: ModuleType, monkeypatch: pytest.MonkeyPatch
) -> None: