From b439de2005b70ec3867d589d1f4c63b83441e620 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Thu, 12 Nov 2026 23:10:55 +0100 Subject: refactor(sender): simplify HTML endpoint discovery Use a case-insensitive CSS selector to find Webmention links directly, removing manual relation parsing while preserving endpoint validation and document order. --- tests/tasks/test_discovery.py | 42 +++++++++++------------------------------- 1 file changed, 11 insertions(+), 31 deletions(-) (limited to 'tests/tasks/test_discovery.py') diff --git a/tests/tasks/test_discovery.py b/tests/tasks/test_discovery.py index 2fc30b1..2d6c37e 100644 --- a/tests/tasks/test_discovery.py +++ b/tests/tasks/test_discovery.py @@ -714,47 +714,27 @@ def test_endpoint_from_headers_ignores_malformed_link( assert sender_module.endpoint_from_headers(response) == ENDPOINT_URL -def test_endpoint_from_html_accepts_string_rel( - sender_module: ModuleType, monkeypatch: pytest.MonkeyPatch -) -> None: - element = Mock() - element.get.side_effect = lambda name: { - "rel": "webmention alternate", - "href": "/webmention", - }[name] +def test_endpoint_from_html_accepts_string_rel(sender_module: ModuleType) -> None: + response = httpx.Response(200, request=httpx.Request("GET", TARGET_URL)) + body = b'' - document = Mock() - document.find_all.return_value = [element] + assert sender_module.endpoint_from_html(response, body) == ENDPOINT_URL - beautiful_soup = Mock(return_value=document) - monkeypatch.setattr(discovery, "BeautifulSoup", beautiful_soup) +def test_endpoint_from_html_accepts_uppercase_rel(sender_module: ModuleType) -> None: response = httpx.Response(200, request=httpx.Request("GET", TARGET_URL)) + body = b'' - assert sender_module.endpoint_from_html(response, b"") == ENDPOINT_URL + assert sender_module.endpoint_from_html(response, body) == ENDPOINT_URL -def test_endpoint_from_html_ignores_elements_without_rel_and_non_string_href( - sender_module: ModuleType, monkeypatch: pytest.MonkeyPatch +def test_endpoint_from_html_ignores_elements_without_matching_rel_or_href( + sender_module: ModuleType, ) -> None: - missing_rel = Mock() - missing_rel.get.return_value = None - - invalid_href = Mock() - invalid_href.get.side_effect = lambda name: { - "rel": ["webmention"], - "href": ["invalid"], - }[name] - - document = Mock() - document.find_all.return_value = [missing_rel, invalid_href] - - beautiful_soup = Mock(return_value=document) - monkeypatch.setattr(discovery, "BeautifulSoup", beautiful_soup) - response = httpx.Response(200, request=httpx.Request("GET", TARGET_URL)) + body = b'No endpoint' - assert sender_module.endpoint_from_html(response, b"") is None + assert sender_module.endpoint_from_html(response, body) is None def test_read_target_body_rejects_declared_oversized_body( -- cgit v1.3.1