diff options
| author | Dennis Fink | 2026-11-16 09:27:29 +0100 |
|---|---|---|
| committer | Dennis Fink | 2026-11-16 09:27:29 +0100 |
| commit | 85b10c38f39732421a230d938adddc7805d0e001 (patch) | |
| tree | 396f29962fac45245c6f1486e188ad905588659d /tests/test_net.py | |
| parent | eb404d9a1a328278c92753e65100579e7ad98e48 (diff) | |
| download | webmentions-ssg-85b10c38f39732421a230d938adddc7805d0e001.tar.gz webmentions-ssg-85b10c38f39732421a230d938adddc7805d0e001.zip | |
style(core): reorder module declarations
Group globals and data classes near module imports, keep primary classes
and functions together, and move implementation helpers after their
public callers.
Reorder Alembic setup so configuration happens after the required
helpers are defined, without changing runtime behavior.
Diffstat (limited to 'tests/test_net.py')
| -rw-r--r-- | tests/test_net.py | 62 |
1 files changed, 31 insertions, 31 deletions
diff --git a/tests/test_net.py b/tests/test_net.py index 24785ee..472ae91 100644 --- a/tests/test_net.py +++ b/tests/test_net.py @@ -31,6 +31,37 @@ from webmentions_ssg.net import ( ) +class FakeStream(httpcore.NetworkStream): + """In-memory TCP/TLS stream so HTTP framing and SNI can be tested.""" + + def __init__(self, response: bytes) -> None: + self.response = response + self.writes = bytearray() + self.sni: str | None = None + + def read(self, max_bytes: int, timeout: float | None = None) -> bytes: + part, self.response = self.response[:max_bytes], self.response[max_bytes:] + return part + + def write(self, buffer: bytes, timeout: float | None = None) -> None: + self.writes.extend(buffer) + + def start_tls( + self, + ssl_context, + server_hostname: str | None = None, + timeout: float | None = None, + ) -> httpcore.NetworkStream: + self.sni = server_hostname + return self + + def get_extra_info(self, info: str): + return None + + def close(self) -> None: + pass + + @pytest.mark.parametrize("host", ["127.0.0.1", "169.254.169.254", "::1"]) def test_backend_rejects_private_ip_without_socket( monkeypatch: pytest.MonkeyPatch, host: str @@ -125,37 +156,6 @@ def test_read_limited_body_raises_specific_size_error(mode: str) -> None: read_limited_body(response, 10, label="Source") -class FakeStream(httpcore.NetworkStream): - """In-memory TCP/TLS stream so HTTP framing and SNI can be tested.""" - - def __init__(self, response: bytes) -> None: - self.response = response - self.writes = bytearray() - self.sni: str | None = None - - def read(self, max_bytes: int, timeout: float | None = None) -> bytes: - part, self.response = self.response[:max_bytes], self.response[max_bytes:] - return part - - def write(self, buffer: bytes, timeout: float | None = None) -> None: - self.writes.extend(buffer) - - def start_tls( - self, - ssl_context, - server_hostname: str | None = None, - timeout: float | None = None, - ) -> httpcore.NetworkStream: - self.sni = server_hostname - return self - - def get_extra_info(self, info: str): - return None - - def close(self) -> None: - pass - - @pytest.mark.parametrize("scheme", ["http", "https"]) def test_transport_keeps_original_http_host_and_tls_sni( monkeypatch: pytest.MonkeyPatch, scheme: str |
