diff options
| author | Dennis Fink | 2026-11-12 23:10:55 +0100 |
|---|---|---|
| committer | Dennis Fink | 2026-11-12 23:10:55 +0100 |
| commit | b439de2005b70ec3867d589d1f4c63b83441e620 (patch) | |
| tree | 8946413d4ab5ab92c0f81012ea9dce79ebb046ae /tests | |
| parent | 8f4f9041c60991457ccb1b3f145676d90e28aa8c (diff) | |
| download | webmentions-ssg-b439de2005b70ec3867d589d1f4c63b83441e620.tar.gz webmentions-ssg-b439de2005b70ec3867d589d1f4c63b83441e620.zip | |
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.
Diffstat (limited to '')
| -rw-r--r-- | tests/tasks/test_discovery.py | 42 |
1 files changed, 11 insertions, 31 deletions
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'<link rel="webmention alternate" href="/webmention">' - 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'<LINK REL="ALTERNATE WEBMENTION" HREF="/webmention">' - 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'<link href="/ignored"><a rel="webmention">No endpoint</a>' - 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( |
