aboutsummaryrefslogtreecommitdiff
path: root/tests/tasks/test_discovery.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/tasks/test_discovery.py')
-rw-r--r--tests/tasks/test_discovery.py42
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(