From 4bd1d9e348918b2e55db47a1ac3489d035cf55e2 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Thu, 12 Nov 2026 19:57:08 +0100 Subject: refactor(core): split modules by responsibility Break up monolithic views, task helpers, networking, CLI, and application extension setup so each module owns a focused concern. Reorganize the test suite around the new boundaries while preserving existing Webmention behavior and coverage. --- tests/tasks/test_receiver.py | 160 +------------------------------------------ 1 file changed, 2 insertions(+), 158 deletions(-) (limited to 'tests/tasks/test_receiver.py') diff --git a/tests/tasks/test_receiver.py b/tests/tasks/test_receiver.py index 44d1cc2..5441eb7 100644 --- a/tests/tasks/test_receiver.py +++ b/tests/tasks/test_receiver.py @@ -15,7 +15,7 @@ from flask import Flask from webmentions_ssg import DATABASE as db from webmentions_ssg.models import ReceivedWebmention -from webmentions_ssg.url_security import AddressResolutionError +from webmentions_ssg.net import AddressResolutionError SOURCE_URL = "https://source.example/article" TARGET_URL = "https://dennisfink.me/blog/example/" @@ -68,148 +68,6 @@ def set_stream_response(httpx_client: Mock, response: httpx.Response) -> Mock: return client -@pytest.mark.parametrize( - ("body", "expected"), - [ - pytest.param(f'Reply', True, id="a-href"), - pytest.param(f'Target', True, id="area-href"), - pytest.param( - f'', True, id="link-href" - ), - pytest.param(f'', True, id="img-src"), - pytest.param(f'', True, id="audio-src"), - pytest.param(f'', True, id="video-src"), - pytest.param( - f'', True, id="audio-source-src" - ), - pytest.param( - f'', True, id="video-source-src" - ), - pytest.param(f'', True, id="iframe-src"), - pytest.param(f'', True, id="embed-src"), - pytest.param(f'', True, id="script-src"), - pytest.param( - f'', True, id="track-src" - ), - pytest.param( - f'', - True, - id="image-input-src", - ), - pytest.param( - f'', - True, - id="image-input-case-insensitive", - ), - pytest.param( - f'
Quotation
', - True, - id="blockquote-cite", - ), - pytest.param(f'Quotation', True, id="q-cite"), - pytest.param(f'Addition', True, id="ins-cite"), - pytest.param(f'Removal', True, id="del-cite"), - pytest.param( - 'Reply', - True, - id="base-url", - ), - pytest.param(f'', False, id="img-cite-invalid"), - pytest.param( - f'
Quote
', - False, - id="blockquote-src-invalid", - ), - pytest.param(f'Reply', False, id="a-src-invalid"), - pytest.param(f'
', False, id="div-href-invalid"), - pytest.param(f'', False, id="link-src-invalid"), - pytest.param( - f'', - False, - id="text-input-src-invalid", - ), - pytest.param( - f'', - False, - id="picture-source-src-invalid", - ), - pytest.param(f'', False, id="base-is-not-mention"), - pytest.param( - f'Different page', False, id="longer-url" - ), - pytest.param( - f'', - False, - id="invalid-cite-does-not-override-valid-src", - ), - pytest.param(f"

{TARGET_URL}

", False, id="text-content"), - pytest.param( - 'Other site', False, id="missing-target" - ), - ], -) -def test_html_mentions_target(receiver: ModuleType, body: str, expected: bool) -> None: - assert ( - receiver.html_mentions_target(body.encode(), SOURCE_URL, TARGET_URL) is expected - ) - - -def test_html_mentions_relative_target(receiver: ModuleType) -> None: - assert receiver.html_mentions_target( - b'Reply', - "https://source.example/posts/article/", - "https://source.example/posts/target/", - ) - - -@pytest.mark.parametrize( - ("body", "target_url", "expected"), - [ - (TARGET_URL, TARGET_URL, True), - (f"This post replies to {TARGET_URL}", TARGET_URL, True), - ( - f"https://example.com/first {TARGET_URL} https://example.com/last", - TARGET_URL, - True, - ), - pytest.param( - f"See {TARGET_URL}, thanks", TARGET_URL, True, id="trailing-comma" - ), - pytest.param(f"({TARGET_URL})", TARGET_URL, True, id="parenthesized-url"), - pytest.param( - f"See ({TARGET_URL}), thanks!", TARGET_URL, True, id="mixed-punctuation" - ), - pytest.param(f"See {TARGET_URL}. Next", TARGET_URL, True, id="trailing-period"), - pytest.param( - "https://example.com/wiki/Foo_(bar)", - "https://example.com/wiki/Foo_(bar)", - True, - id="balanced-parentheses-in-url", - ), - pytest.param( - "https://example.com/wiki/Foo_(bar)", - "https://example.com/wiki/Foo_(bar", - False, - id="balanced-parentheses-not-trimmed", - ), - (f"{TARGET_URL}more", TARGET_URL, False), - pytest.param( - f"{TARGET_URL},another-page", - TARGET_URL, - False, - id="comma-within-longer-url", - ), - ("https://dennisfink.me/blog/other/", TARGET_URL, False), - ("/blog/example/", TARGET_URL, False), - ("There are no links here.", TARGET_URL, False), - ], -) -def test_text_mentions_target( - receiver: ModuleType, body: str, target_url: str, expected: bool -) -> None: - assert receiver.text_mentions_target(body, target_url) is expected - - @patch("webmentions_ssg.tasks.receiver.httpx.Client") def test_fetch_source_returns_response_and_body( httpx_client: Mock, app: Flask, receiver: ModuleType @@ -786,7 +644,7 @@ def test_verify_webmention_ignores_unknown_identifier( def test_fetch_source_rejects_unsafe_destination( httpx_client: Mock, app: Flask, receiver: ModuleType ) -> None: - from webmentions_ssg.url_security import UnsafeAddressError + from webmentions_ssg.net import UnsafeAddressError client = httpx_client.return_value.__enter__.return_value client.stream.side_effect = UnsafeAddressError("Local address") @@ -810,20 +668,6 @@ def test_fetch_source_treats_dns_failure_as_temporary( receiver.fetch_source(SOURCE_URL) -@patch("webmentions_ssg.tasks.receiver.BeautifulSoup") -def test_html_mentions_target_ignores_non_string_attribute( - beautiful_soup: Mock, receiver: ModuleType -) -> None: - document = beautiful_soup.return_value - document.select_one.return_value = None - - element = Mock() - element.get.return_value = ["not", "a", "string"] - document.select.return_value = [element] - - assert not receiver.html_mentions_target(b"", SOURCE_URL, TARGET_URL) - - @patch("webmentions_ssg.tasks.receiver.httpx.Client") def test_fetch_source_ignores_invalid_content_length( httpx_client: Mock, app: Flask, receiver: ModuleType -- cgit v1.3.1