diff options
Diffstat (limited to '')
| -rw-r--r-- | tests/tasks/test_verification.py (renamed from tests/tasks/test_receiver.py) | 235 |
1 files changed, 124 insertions, 111 deletions
diff --git a/tests/tasks/test_receiver.py b/tests/tasks/test_verification.py index 7241247..c336b19 100644 --- a/tests/tasks/test_receiver.py +++ b/tests/tasks/test_verification.py @@ -23,10 +23,10 @@ TARGET_URL = "https://dennisfink.me/blog/example/" @pytest.fixture -def receiver(app: Flask) -> ModuleType: - from webmentions_ssg.tasks import receiver +def verification(app: Flask) -> ModuleType: + from webmentions_ssg.tasks import verification - return receiver + return verification def create_webmention( @@ -69,9 +69,9 @@ def set_stream_response(httpx_client: Mock, response: httpx.Response) -> Mock: return client -@patch("webmentions_ssg.tasks.receiver.httpx.Client") +@patch("webmentions_ssg.tasks.verification.httpx.Client") def test_fetch_source_document_returns_response_and_body( - httpx_client: Mock, app: Flask, receiver: ModuleType + httpx_client: Mock, app: Flask, verification: ModuleType ) -> None: response = httpx.Response( HTTPStatus.OK, @@ -82,7 +82,7 @@ def test_fetch_source_document_returns_response_and_body( client = set_stream_response(httpx_client, response) with app.app_context(): - fetched_response, body = receiver.fetch_source_document(SOURCE_URL) + fetched_response, body = verification.fetch_source_document(SOURCE_URL) assert fetched_response is response assert body == b"<p>Document</p>" @@ -92,7 +92,7 @@ def test_fetch_source_document_returns_response_and_body( assert options["headers"] == { "Accept": "text/html, application/xhtml+xml;q=0.9, text/plain;q=0.8", - "User-Agent": f"{receiver.APP_NAME}/{receiver.VERSION} ReceivedWebmention", + "User-Agent": f"{verification.APP_NAME}/{verification.VERSION} ReceivedWebmention", } assert options["follow_redirects"] is True assert options["max_redirects"] == app.config.get("MAX_REDIRECTS", 20) @@ -100,7 +100,7 @@ def test_fetch_source_document_returns_response_and_body( assert options["transport"].__class__.__name__ == "PublicHTTPTransport" -@patch("webmentions_ssg.tasks.receiver.httpx.Client") +@patch("webmentions_ssg.tasks.verification.httpx.Client") @pytest.mark.parametrize( ("status_code", "exception_name"), [ @@ -117,7 +117,7 @@ def test_fetch_source_document_returns_response_and_body( def test_fetch_source_document_maps_http_status_to_exception( httpx_client: Mock, app: Flask, - receiver: ModuleType, + verification: ModuleType, status_code: int, exception_name: str, ) -> None: @@ -126,15 +126,15 @@ def test_fetch_source_document_maps_http_status_to_exception( httpx.Response(status_code, request=httpx.Request("GET", SOURCE_URL)), ) - exception_type = getattr(receiver, exception_name) + exception_type = getattr(verification, exception_name) with app.app_context(), pytest.raises(exception_type, match=f"HTTP {status_code}"): - receiver.fetch_source_document(SOURCE_URL) + verification.fetch_source_document(SOURCE_URL) -@patch("webmentions_ssg.tasks.receiver.httpx.Client") +@patch("webmentions_ssg.tasks.verification.httpx.Client") def test_fetch_source_document_propagates_network_error( - httpx_client: Mock, app: Flask, receiver: ModuleType + httpx_client: Mock, app: Flask, verification: ModuleType ) -> None: client = httpx_client.return_value.__enter__.return_value client.stream.side_effect = httpx.ConnectError( @@ -145,12 +145,12 @@ def test_fetch_source_document_propagates_network_error( app.app_context(), pytest.raises(httpx.ConnectError, match="Connection refused"), ): - receiver.fetch_source_document(SOURCE_URL) + verification.fetch_source_document(SOURCE_URL) -@patch("webmentions_ssg.tasks.receiver.httpx.Client") +@patch("webmentions_ssg.tasks.verification.httpx.Client") def test_fetch_source_document_rejects_declared_oversized_body( - httpx_client: Mock, app: Flask, receiver: ModuleType + httpx_client: Mock, app: Flask, verification: ModuleType ) -> None: app.config["MAX_RECEIVED_SOURCE_BYTES"] = 10 @@ -166,14 +166,16 @@ def test_fetch_source_document_rejects_declared_oversized_body( with ( app.app_context(), - pytest.raises(receiver.VerificationError, match="Source document is too large"), + pytest.raises( + verification.VerificationError, match="Source document is too large" + ), ): - receiver.fetch_source_document(SOURCE_URL) + verification.fetch_source_document(SOURCE_URL) -@patch("webmentions_ssg.tasks.receiver.httpx.Client") +@patch("webmentions_ssg.tasks.verification.httpx.Client") def test_fetch_source_document_rejects_streamed_oversized_body( - httpx_client: Mock, app: Flask, receiver: ModuleType + httpx_client: Mock, app: Flask, verification: ModuleType ) -> None: app.config["MAX_RECEIVED_SOURCE_BYTES"] = 10 @@ -194,16 +196,18 @@ def test_fetch_source_document_rejects_streamed_oversized_body( with ( app.app_context(), - pytest.raises(receiver.VerificationError, match="Source document is too large"), + pytest.raises( + verification.VerificationError, match="Source document is too large" + ), ): - receiver.fetch_source_document(SOURCE_URL) + verification.fetch_source_document(SOURCE_URL) -@patch("webmentions_ssg.tasks.receiver.httpx.Client") +@patch("webmentions_ssg.tasks.verification.httpx.Client") def test_fetch_source_document_does_not_mask_unexpected_value_error( httpx_client: Mock, app: Flask, - receiver: ModuleType, + verification: ModuleType, monkeypatch: pytest.MonkeyPatch, ) -> None: set_stream_response( @@ -211,14 +215,16 @@ def test_fetch_source_document_does_not_mask_unexpected_value_error( httpx.Response(HTTPStatus.OK, request=httpx.Request("GET", SOURCE_URL)), ) monkeypatch.setattr( - receiver, "read_limited_body", Mock(side_effect=ValueError("unexpected bug")) + verification, + "read_limited_body", + Mock(side_effect=ValueError("unexpected bug")), ) with app.app_context(), pytest.raises(ValueError, match="unexpected bug"): - receiver.fetch_source_document(SOURCE_URL) + verification.fetch_source_document(SOURCE_URL) -@patch("webmentions_ssg.tasks.receiver.fetch_source_document") +@patch("webmentions_ssg.tasks.verification.fetch_source_document") @pytest.mark.parametrize( ("content_type", "body", "expected"), [ @@ -271,7 +277,7 @@ def test_fetch_source_document_does_not_mask_unexpected_value_error( ) def test_source_mentions_target_by_media_type( fetch_source_document: Mock, - receiver: ModuleType, + verification: ModuleType, content_type: str, body: bytes, expected: bool, @@ -284,11 +290,11 @@ def test_source_mentions_target_by_media_type( ) fetch_source_document.return_value = response, body - assert receiver.source_mentions_target(SOURCE_URL, TARGET_URL) is expected + assert verification.source_mentions_target(SOURCE_URL, TARGET_URL) is expected fetch_source_document.assert_called_once_with(SOURCE_URL) -@patch("webmentions_ssg.tasks.receiver.fetch_source_document") +@patch("webmentions_ssg.tasks.verification.fetch_source_document") @pytest.mark.parametrize( ("content_type", "expected_media_type"), [ @@ -299,7 +305,7 @@ def test_source_mentions_target_by_media_type( ) def test_source_mentions_target_rejects_unsupported_media_type( fetch_source_document: Mock, - receiver: ModuleType, + verification: ModuleType, content_type: str, expected_media_type: str, ) -> None: @@ -317,37 +323,42 @@ def test_source_mentions_target_rejects_unsupported_media_type( fetch_source_document.return_value = response, b"Document" with pytest.raises( - receiver.VerificationError, + verification.VerificationError, match=f"Unsupported source content type: {expected_media_type}", ): - receiver.source_mentions_target(SOURCE_URL, TARGET_URL) + verification.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")], + [ + (True, "verified", None), + (False, "source_removed", "Source does not mention target"), + ], ) def test_determine_verification_outcome_returns_outcome( - receiver: ModuleType, + verification: 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( + monkeypatch.setattr( + verification, "source_mentions_target", Mock(return_value=mentions) + ) + claim = verification.VerificationClaim( uuid.uuid7(), SOURCE_URL, TARGET_URL, datetime.now(UTC) ) - assert receiver.determine_verification_outcome(claim) == ( + assert verification.determine_verification_outcome(claim) == ( expected_status, expected_reason, ) -@patch("webmentions_ssg.tasks.receiver.source_mentions_target") +@patch("webmentions_ssg.tasks.verification.source_mentions_target") def test_verify_webmention_marks_row_verifying_before_check( - source_mentions_target: Mock, app: Flask, receiver: ModuleType + source_mentions_target: Mock, app: Flask, verification: ModuleType ) -> None: identifier = create_webmention( app, status="failed", failure_reason="Earlier failure" @@ -365,24 +376,24 @@ def test_verify_webmention_marks_row_verifying_before_check( return True source_mentions_target.side_effect = verify_source - receiver.verify_webmention.call_local(identifier) + verification.verify_webmention.call_local(identifier) assert get_webmention_state(app, identifier) == ("verified", None) -@patch("webmentions_ssg.tasks.receiver.source_mentions_target") +@patch("webmentions_ssg.tasks.verification.source_mentions_target") @pytest.mark.parametrize( ("outcome", "expected_status", "expected_reason"), [ ("verified", "verified", None), - ("missing", "deleted", "Source does not mention target"), - ("gone", "deleted", "Source returned HTTP 410"), + ("missing", "source_removed", "Source does not mention target"), + ("gone", "source_removed", "Source returned HTTP 410"), ("permanent-failure", "failed", "Source returned HTTP 404"), ], ) def test_verify_webmention_persists_final_state( source_mentions_target: Mock, app: Flask, - receiver: ModuleType, + verification: ModuleType, outcome: str, expected_status: str, expected_reason: str | None, @@ -395,30 +406,30 @@ def test_verify_webmention_persists_final_state( case "missing": source_mentions_target.return_value = False case "gone": - source_mentions_target.side_effect = receiver.SourceGoneError( + source_mentions_target.side_effect = verification.SourceGoneError( "Source returned HTTP 410" ) case "permanent-failure": - source_mentions_target.side_effect = receiver.VerificationError( + source_mentions_target.side_effect = verification.VerificationError( "Source returned HTTP 404" ) case _: raise AssertionError(f"Unexpected outcome: {outcome}") - receiver.verify_webmention.call_local(identifier) + verification.verify_webmention.call_local(identifier) assert get_webmention_state(app, identifier) == (expected_status, expected_reason) -@patch("webmentions_ssg.tasks.receiver.source_mentions_target") +@patch("webmentions_ssg.tasks.verification.source_mentions_target") @pytest.mark.parametrize("failure", ["temporary-http", "network"]) def test_verify_webmention_persists_retryable_failure_and_reraises( - source_mentions_target: Mock, app: Flask, receiver: ModuleType, failure: str + source_mentions_target: Mock, app: Flask, verification: ModuleType, failure: str ) -> None: identifier = create_webmention(app) match failure: case "temporary-http": - exception = receiver.RetryableFetchError("Source returned HTTP 503") + exception = verification.RetryableFetchError("Source returned HTTP 503") case "network": exception = httpx.ConnectError( "Connection refused", request=httpx.Request("GET", SOURCE_URL) @@ -429,19 +440,19 @@ def test_verify_webmention_persists_retryable_failure_and_reraises( source_mentions_target.side_effect = exception with pytest.raises(type(exception), match=str(exception)): - receiver.verify_webmention.call_local(identifier) + verification.verify_webmention.call_local(identifier) assert get_webmention_state(app, identifier) == ("failed", str(exception)) -@patch("webmentions_ssg.tasks.receiver.source_mentions_target") -@pytest.mark.parametrize("status", ["verifying", "verified", "deleted"]) +@patch("webmentions_ssg.tasks.verification.source_mentions_target") +@pytest.mark.parametrize("status", ["verifying", "verified", "source_removed"]) def test_verify_webmention_skips_active_and_terminal_states( - source_mentions_target: Mock, app: Flask, receiver: ModuleType, status: str + source_mentions_target: Mock, app: Flask, verification: ModuleType, status: str ) -> None: identifier = create_webmention(app, status=status) - receiver.verify_webmention.call_local(identifier) + verification.verify_webmention.call_local(identifier) assert get_webmention_state(app, identifier) == (status, None) source_mentions_target.assert_not_called() @@ -461,17 +472,17 @@ def set_webmention_updated_at( @pytest.mark.parametrize("status", ["verifying", "received"]) def test_reaper_requeues_stale_verifications( - app: Flask, receiver: ModuleType, monkeypatch: pytest.MonkeyPatch, status: str + app: Flask, verification: ModuleType, monkeypatch: pytest.MonkeyPatch, status: str ) -> None: app.config["VERIFICATION_STALE_AFTER_SECONDS"] = 900 identifier = create_webmention(app, status=status, failure_reason="Interrupted") set_webmention_updated_at(app, identifier, datetime.now(UTC) - timedelta(hours=1)) enqueue = Mock() - monkeypatch.setattr(receiver, "verify_webmention", enqueue) + monkeypatch.setattr(verification, "verify_webmention", enqueue) with app.app_context(): - assert receiver.recover_stale_verifications() == 1 - assert receiver.recover_stale_verifications() == 0 + assert verification.recover_stale_verifications() == 1 + assert verification.recover_stale_verifications() == 0 row = db.session.get(ReceivedWebmention, identifier) assert row is not None assert row.updated_at.replace(tzinfo=UTC) > datetime.now(UTC) - timedelta( @@ -483,7 +494,7 @@ def test_reaper_requeues_stale_verifications( def test_reaper_does_not_touch_recent_or_terminal_webmentions( - app: Flask, receiver: ModuleType, monkeypatch: pytest.MonkeyPatch + app: Flask, verification: ModuleType, monkeypatch: pytest.MonkeyPatch ) -> None: recent_verifying = create_webmention(app, status="verifying") recent_received = create_webmention( @@ -494,10 +505,10 @@ def test_reaper_does_not_touch_recent_or_terminal_webmentions( ) set_webmention_updated_at(app, old_verified, datetime.now(UTC) - timedelta(hours=1)) enqueue = Mock() - monkeypatch.setattr(receiver, "verify_webmention", enqueue) + monkeypatch.setattr(verification, "verify_webmention", enqueue) with app.app_context(): - assert receiver.recover_stale_verifications() == 0 + assert verification.recover_stale_verifications() == 0 assert get_webmention_state(app, recent_verifying) == ("verifying", None) assert get_webmention_state(app, recent_received) == ("received", None) @@ -506,14 +517,16 @@ def test_reaper_does_not_touch_recent_or_terminal_webmentions( def test_reaper_recovers_after_enqueue_failure( - app: Flask, receiver: ModuleType, monkeypatch: pytest.MonkeyPatch + app: Flask, verification: ModuleType, monkeypatch: pytest.MonkeyPatch ) -> None: identifier = create_webmention(app, status="verifying") set_webmention_updated_at(app, identifier, datetime.now(UTC) - timedelta(hours=1)) - monkeypatch.setattr(receiver, "verify_webmention", Mock(side_effect=RuntimeError)) + monkeypatch.setattr( + verification, "verify_webmention", Mock(side_effect=RuntimeError) + ) with app.app_context(), pytest.raises(RuntimeError): - receiver.recover_stale_verifications() + verification.recover_stale_verifications() assert get_webmention_state(app, identifier) == ("received", None) @@ -521,26 +534,26 @@ def test_reaper_recovers_after_enqueue_failure( # but before Huey persisted the task. app.config["VERIFICATION_STALE_AFTER_SECONDS"] = 0 enqueue = Mock() - monkeypatch.setattr(receiver, "verify_webmention", enqueue) + monkeypatch.setattr(verification, "verify_webmention", enqueue) with app.app_context(): - assert receiver.recover_stale_verifications() == 1 + assert verification.recover_stale_verifications() == 1 enqueue.assert_called_once_with(identifier) def test_late_worker_cannot_overwrite_recovered_verification( - app: Flask, receiver: ModuleType, monkeypatch: pytest.MonkeyPatch + app: Flask, verification: ModuleType, monkeypatch: pytest.MonkeyPatch ) -> None: identifier = create_webmention(app) - original_verify = receiver.verify_webmention + original_verify = verification.verify_webmention def concurrent_recovery(_source: str, _target: str) -> bool: # The reaper supersedes this still-running attempt; a newer attempt # subsequently completes before the original fetch returns. app.config["VERIFICATION_STALE_AFTER_SECONDS"] = 0 with app.app_context(): - with patch.object(receiver, "verify_webmention", Mock()) as enqueue: - assert receiver.recover_stale_verifications() == 1 + with patch.object(verification, "verify_webmention", Mock()) as enqueue: + assert verification.recover_stale_verifications() == 1 enqueue.assert_called_once_with(identifier) db.session.execute( sa.update(ReceivedWebmention) @@ -550,28 +563,28 @@ def test_late_worker_cannot_overwrite_recovered_verification( db.session.commit() return False - monkeypatch.setattr(receiver, "source_mentions_target", concurrent_recovery) + monkeypatch.setattr(verification, "source_mentions_target", concurrent_recovery) original_verify.call_local(identifier) assert get_webmention_state(app, identifier) == ("verified", None) def test_reaper_requeues_and_verifies_integration( - app: Flask, receiver: ModuleType, monkeypatch: pytest.MonkeyPatch + app: Flask, verification: ModuleType, monkeypatch: pytest.MonkeyPatch ) -> None: identifier = create_webmention(app, status="verifying") set_webmention_updated_at(app, identifier, datetime.now(UTC) - timedelta(hours=1)) check = Mock(return_value=True) - monkeypatch.setattr(receiver, "source_mentions_target", check) + monkeypatch.setattr(verification, "source_mentions_target", check) with app.app_context(): - assert receiver.recover_stale_verifications() == 1 + assert verification.recover_stale_verifications() == 1 assert get_webmention_state(app, identifier) == ("verified", None) check.assert_called_once_with(SOURCE_URL, TARGET_URL) -@patch("webmentions_ssg.tasks.receiver.source_mentions_target") +@patch("webmentions_ssg.tasks.verification.source_mentions_target") @pytest.mark.parametrize( "unexpected_error", [ @@ -584,29 +597,29 @@ def test_reaper_requeues_and_verifies_integration( def test_verify_webmention_records_unexpected_error_as_terminal_failure( source_mentions_target: Mock, app: Flask, - receiver: ModuleType, + verification: ModuleType, unexpected_error: Exception, ) -> None: identifier = create_webmention(app, source="http://ex☃mple.test/") source_mentions_target.side_effect = unexpected_error - receiver.verify_webmention.call_local(identifier) + verification.verify_webmention.call_local(identifier) assert get_webmention_state(app, identifier) == ("failed", str(unexpected_error)) source_mentions_target.assert_called_once() # Failed rows are not eligible for automatic reaper recovery. set_webmention_updated_at(app, identifier, datetime.now(UTC) - timedelta(hours=1)) with app.app_context(): - assert receiver.recover_stale_verifications() == 0 + assert verification.recover_stale_verifications() == 0 def test_reaper_caps_stale_verification_recoveries( - app: Flask, receiver: ModuleType, monkeypatch: pytest.MonkeyPatch + app: Flask, verification: ModuleType, monkeypatch: pytest.MonkeyPatch ) -> None: app.config["VERIFICATION_MAX_RECOVERIES"] = 3 identifier = create_webmention(app, status="verifying") enqueue = Mock() - monkeypatch.setattr(receiver, "verify_webmention", enqueue) + monkeypatch.setattr(verification, "verify_webmention", enqueue) # Simulate workers that repeatedly crash before completing the task. for attempt in range(3): @@ -614,7 +627,7 @@ def test_reaper_caps_stale_verification_recoveries( app, identifier, datetime.now(UTC) - timedelta(hours=1) ) with app.app_context(): - assert receiver.recover_stale_verifications() == 1 + assert verification.recover_stale_verifications() == 1 row = db.session.get(ReceivedWebmention, identifier) assert row is not None assert row.status == "received" @@ -622,69 +635,69 @@ def test_reaper_caps_stale_verification_recoveries( set_webmention_updated_at(app, identifier, datetime.now(UTC) - timedelta(hours=1)) with app.app_context(): - assert receiver.recover_stale_verifications() == 0 + assert verification.recover_stale_verifications() == 0 row = db.session.get(ReceivedWebmention, identifier) assert row is not None assert row.status == "failed" - assert row.failure_reason == receiver.RECOVERY_EXHAUSTED_REASON + assert row.failure_reason == verification.RECOVERY_EXHAUSTED_REASON assert row.recovery_attempts == 3 - assert receiver.recover_stale_verifications() == 0 + assert verification.recover_stale_verifications() == 0 assert enqueue.call_count == 3 def test_reaper_caps_received_rows_lost_before_first_task( - app: Flask, receiver: ModuleType, monkeypatch: pytest.MonkeyPatch + app: Flask, verification: ModuleType, monkeypatch: pytest.MonkeyPatch ) -> None: app.config["VERIFICATION_MAX_RECOVERIES"] = 1 identifier = create_webmention(app, status="received", recovery_attempts=1) set_webmention_updated_at(app, identifier, datetime.now(UTC) - timedelta(hours=1)) enqueue = Mock() - monkeypatch.setattr(receiver, "verify_webmention", enqueue) + monkeypatch.setattr(verification, "verify_webmention", enqueue) with app.app_context(): - assert receiver.recover_stale_verifications() == 0 + assert verification.recover_stale_verifications() == 0 assert get_webmention_state(app, identifier) == ( "failed", - receiver.RECOVERY_EXHAUSTED_REASON, + verification.RECOVERY_EXHAUSTED_REASON, ) enqueue.assert_not_called() def test_exhausted_row_cannot_be_revived_by_late_huey_retry( - app: Flask, receiver: ModuleType, monkeypatch: pytest.MonkeyPatch + app: Flask, verification: ModuleType, monkeypatch: pytest.MonkeyPatch ) -> None: identifier = create_webmention( app, status="failed", - failure_reason=receiver.RECOVERY_EXHAUSTED_REASON, + failure_reason=verification.RECOVERY_EXHAUSTED_REASON, recovery_attempts=3, ) source_mentions_target = Mock(return_value=True) - monkeypatch.setattr(receiver, "source_mentions_target", source_mentions_target) + monkeypatch.setattr(verification, "source_mentions_target", source_mentions_target) - receiver.verify_webmention.call_local(identifier) + verification.verify_webmention.call_local(identifier) assert get_webmention_state(app, identifier) == ( "failed", - receiver.RECOVERY_EXHAUSTED_REASON, + verification.RECOVERY_EXHAUSTED_REASON, ) source_mentions_target.assert_not_called() def test_verify_webmention_ignores_unknown_identifier( - receiver: ModuleType, caplog: pytest.LogCaptureFixture + verification: ModuleType, caplog: pytest.LogCaptureFixture ) -> None: identifier = uuid.uuid7() with caplog.at_level(logging.WARNING): - receiver.verify_webmention.call_local(identifier) + verification.verify_webmention.call_local(identifier) assert f"Cannot verify unknown ReceivedWebmention {identifier}" in caplog.text -@patch("webmentions_ssg.tasks.receiver.httpx.Client") +@patch("webmentions_ssg.tasks.verification.httpx.Client") def test_fetch_source_document_rejects_unsafe_destination( - httpx_client: Mock, app: Flask, receiver: ModuleType + httpx_client: Mock, app: Flask, verification: ModuleType ) -> None: from webmentions_ssg.net import UnsafeAddressError @@ -692,27 +705,27 @@ def test_fetch_source_document_rejects_unsafe_destination( client.stream.side_effect = UnsafeAddressError("Local address") with ( app.app_context(), - pytest.raises(receiver.VerificationError, match="non-public address"), + pytest.raises(verification.VerificationError, match="non-public address"), ): - receiver.fetch_source_document(SOURCE_URL) + verification.fetch_source_document(SOURCE_URL) -@patch("webmentions_ssg.tasks.receiver.httpx.Client") +@patch("webmentions_ssg.tasks.verification.httpx.Client") def test_fetch_source_document_treats_dns_failure_as_temporary( - httpx_client: Mock, app: Flask, receiver: ModuleType + httpx_client: Mock, app: Flask, verification: ModuleType ) -> None: client = httpx_client.return_value.__enter__.return_value client.stream.side_effect = AddressResolutionError("DNS timeout") with ( app.app_context(), - pytest.raises(receiver.RetryableFetchError, match="could not be resolved"), + pytest.raises(verification.RetryableFetchError, match="could not be resolved"), ): - receiver.fetch_source_document(SOURCE_URL) + verification.fetch_source_document(SOURCE_URL) -@patch("webmentions_ssg.tasks.receiver.httpx.Client") +@patch("webmentions_ssg.tasks.verification.httpx.Client") def test_fetch_source_document_ignores_invalid_content_length( - httpx_client: Mock, app: Flask, receiver: ModuleType + httpx_client: Mock, app: Flask, verification: ModuleType ) -> None: response = httpx.Response( HTTPStatus.OK, @@ -723,15 +736,15 @@ def test_fetch_source_document_ignores_invalid_content_length( set_stream_response(httpx_client, response) with app.app_context(): - fetched_response, body = receiver.fetch_source_document(SOURCE_URL) + fetched_response, body = verification.fetch_source_document(SOURCE_URL) assert fetched_response is response assert body == b"<p>Document</p>" -@patch("webmentions_ssg.tasks.receiver.fetch_source_document") +@patch("webmentions_ssg.tasks.verification.fetch_source_document") def test_source_mentions_target_falls_back_for_unknown_encoding( - fetch_source_document: Mock, receiver: ModuleType + fetch_source_document: Mock, verification: ModuleType ) -> None: body = f"Reply to {TARGET_URL}".encode() @@ -744,5 +757,5 @@ def test_source_mentions_target_falls_back_for_unknown_encoding( response.encoding = "unknown-encoding" fetch_source_document.return_value = response, body - assert receiver.source_mentions_target(SOURCE_URL, TARGET_URL) + assert verification.source_mentions_target(SOURCE_URL, TARGET_URL) fetch_source_document.assert_called_once_with(SOURCE_URL) |
