aboutsummaryrefslogtreecommitdiff
path: root/tests/test_url_security.py
diff options
context:
space:
mode:
authorDennis Fink2026-08-10 20:00:28 +0200
committerDennis Fink2026-08-10 20:00:28 +0200
commit5b39f70aa14cac635b6084170e9d0bd3f548b911 (patch)
treedaef3fddff0679efb23a42a58743e7c2a3597213 /tests/test_url_security.py
parent8350bef3e3baea6042ed3780a054cc65707e9f8d (diff)
downloadwebmentions-ssg-5b39f70aa14cac635b6084170e9d0bd3f548b911.tar.gz
webmentions-ssg-5b39f70aa14cac635b6084170e9d0bd3f548b911.zip
test: simplify mocks and localize test fixtures
Replace shared HTTPX and DNS fixtures with targeted unittest.mock patches close to the tests that need them. Keep conftest focused on application and client setup, while moving receiver-specific helpers into the receiver test module.
Diffstat (limited to '')
-rw-r--r--tests/test_url_security.py18
1 files changed, 5 insertions, 13 deletions
diff --git a/tests/test_url_security.py b/tests/test_url_security.py
index fba6d7d..b10e6ff 100644
--- a/tests/test_url_security.py
+++ b/tests/test_url_security.py
@@ -1,3 +1,5 @@
+from unittest.mock import Mock, patch
+
import pytest
from webmentions_ssg.url_security import (
@@ -6,14 +8,7 @@ from webmentions_ssg.url_security import (
)
-class FakeAnswers:
- def __init__(self, *addresses: str):
- self._addresses = addresses
-
- def addresses(self):
- return iter(self._addresses)
-
-
+@patch("webmentions_ssg.url_security.dns.resolver.resolve_name")
@pytest.mark.parametrize(
("url", "resolved_addresses"),
[
@@ -29,14 +24,11 @@ class FakeAnswers:
],
)
def test_ensure_public_url_rejects_non_public_addresses(
- monkeypatch: pytest.MonkeyPatch,
+ resolve_name: Mock,
url: str,
resolved_addresses: list[str],
) -> None:
- monkeypatch.setattr(
- "webmentions_ssg.url_security.dns.resolver.resolve_name",
- lambda hostname: FakeAnswers(*resolved_addresses),
- )
+ resolve_name.return_value.addresses.return_value = resolved_addresses
with pytest.raises(NonPublicAddressError):
ensure_public_url(url)