aboutsummaryrefslogtreecommitdiff
path: root/tests/test_net.py
diff options
context:
space:
mode:
authorDennis Fink2026-11-13 21:20:40 +0100
committerDennis Fink2026-11-13 21:20:40 +0100
commita285fdf29e59c3b957247ea9241943c7202e9a28 (patch)
tree17ceeb703de23af1e67081d99a8864bbe353fb46 /tests/test_net.py
parent78ecd8bc227bdcbbd0e45eea025f7223252ed0da (diff)
downloadwebmentions-ssg-a285fdf29e59c3b957247ea9241943c7202e9a28.tar.gz
webmentions-ssg-a285fdf29e59c3b957247ea9241943c7202e9a28.zip
refactor(core): consolidate repeated helper logic
Centralize SQL row counts, hostname parsing, and content-type normalization so tasks, forms, and scanners share consistent implementations. Simplify periodic task registration and admin lookups with table-driven setup and Flask-SQLAlchemy's built-in 404 helper.
Diffstat (limited to 'tests/test_net.py')
-rw-r--r--tests/test_net.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/test_net.py b/tests/test_net.py
index 8e0744c..42b9261 100644
--- a/tests/test_net.py
+++ b/tests/test_net.py
@@ -21,6 +21,8 @@ from webmentions_ssg.net import (
PublicNetworkBackend,
ResponseTooLargeError,
UnsafeAddressError,
+ content_type_of,
+ hostname_of,
is_http_url,
is_public_address,
public_addresses,
@@ -333,3 +335,34 @@ def test_temporary_http_status(app: Flask, status: int, expected: bool) -> None:
from webmentions_ssg.tasks import discovery
assert discovery.is_temporary_status(status) is expected
+
+
+@pytest.mark.parametrize(
+ ("url", "expected"),
+ [
+ pytest.param("https://EXAMPLE.com./path", "example.com", id="trailing-dot"),
+ pytest.param("http://[2001:db8::1]/", "2001:db8::1", id="ipv6"),
+ pytest.param("https:///path", None, id="missing-host"),
+ pytest.param("http://[::1", None, id="malformed-ipv6"),
+ ],
+)
+def test_hostname_of(url: str, expected: str | None) -> None:
+ assert hostname_of(url) == expected
+
+
+@pytest.mark.parametrize(
+ ("headers", "expected"),
+ [
+ pytest.param({}, "", id="missing"),
+ pytest.param(
+ {"Content-Type": " Text/HTML ; charset=UTF-8"}, "text/html", id="params"
+ ),
+ pytest.param(
+ {"content-type": "APPLICATION/XHTML+XML"},
+ "application/xhtml+xml",
+ id="case",
+ ),
+ ],
+)
+def test_content_type_of(headers: dict[str, str], expected: str) -> None:
+ assert content_type_of(httpx.Headers(headers)) == expected