aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--tests/tasks/test_receiver.py3
-rw-r--r--tests/test_auth.py4
-rw-r--r--tests/test_cli.py11
-rw-r--r--tests/test_models.py27
-rw-r--r--tests/test_net.py4
-rw-r--r--tests/views/test_session.py4
-rw-r--r--webmentions_ssg/models.py2
-rw-r--r--webmentions_ssg/net.py2
8 files changed, 36 insertions, 21 deletions
diff --git a/tests/tasks/test_receiver.py b/tests/tasks/test_receiver.py
index 51d1bb6..44e8c58 100644
--- a/tests/tasks/test_receiver.py
+++ b/tests/tasks/test_receiver.py
@@ -206,8 +206,7 @@ def test_fetch_source_does_not_mask_unexpected_value_error(
monkeypatch: pytest.MonkeyPatch,
) -> None:
set_stream_response(
- httpx_client,
- httpx.Response(200, request=httpx.Request("GET", SOURCE_URL)),
+ httpx_client, httpx.Response(200, request=httpx.Request("GET", SOURCE_URL))
)
monkeypatch.setattr(
receiver, "read_limited_body", Mock(side_effect=ValueError("unexpected bug"))
diff --git a/tests/test_auth.py b/tests/test_auth.py
index e026e45..bc951b9 100644
--- a/tests/test_auth.py
+++ b/tests/test_auth.py
@@ -22,9 +22,7 @@ def test_user_loader_is_registered(app: Flask) -> None:
assert AUTH._user_callback is load_user
-def test_dummy_password_hash_is_lazily_cached(
- monkeypatch: pytest.MonkeyPatch,
-) -> None:
+def test_dummy_password_hash_is_lazily_cached(monkeypatch: pytest.MonkeyPatch) -> None:
generated_passwords: list[str] = []
def fake_generate_password_hash(password: str) -> str:
diff --git a/tests/test_cli.py b/tests/test_cli.py
index 0d9b357..8fa61d5 100644
--- a/tests/test_cli.py
+++ b/tests/test_cli.py
@@ -5,8 +5,8 @@
import logging
from collections.abc import Iterator
from pathlib import Path
-from uuid import UUID
from unittest.mock import patch
+from uuid import UUID
import pytest
import sqlalchemy as sa
@@ -306,9 +306,12 @@ def test_upgrade_converts_received_status_without_losing_rows(
}
assert isinstance(columns["status"]["type"], sa.String)
assert columns["status"]["type"].length == 9
- assert connection.execute(
- sa.text("SELECT status FROM received_webmentions")
- ).scalar_one() == "verifying"
+ assert (
+ connection.execute(
+ sa.text("SELECT status FROM received_webmentions")
+ ).scalar_one()
+ == "verifying"
+ )
mention = db.session.get(ReceivedWebmention, UUID(hex=identifier))
assert mention is not None
diff --git a/tests/test_models.py b/tests/test_models.py
index b9e7c80..85c216e 100644
--- a/tests/test_models.py
+++ b/tests/test_models.py
@@ -5,11 +5,13 @@
import uuid
from collections.abc import Callable
from datetime import UTC, datetime
+from typing import get_type_hints
import pytest
import sqlalchemy as sa
from flask import Flask
from sqlalchemy.exc import IntegrityError
+from sqlalchemy.orm import Mapped
from webmentions_ssg import db
from webmentions_ssg.models import (
@@ -24,6 +26,19 @@ from webmentions_ssg.models import (
)
+def test_uuid_annotations_and_relationships_resolve() -> None:
+ """Keep UUID columns and forward relationships mapped without future annotations."""
+ for model in (ReceivedWebmention, Source, SentWebmention):
+ assert get_type_hints(model)["uuid"] == Mapped[uuid.UUID]
+ assert sa.inspect(model).columns["uuid"].primary_key
+
+ assert (
+ sa.inspect(Source).relationships["sent_webmentions"].mapper.class_
+ is SentWebmention
+ )
+ assert sa.inspect(SentWebmention).relationships["source"].mapper.class_ is Source
+
+
def test_user_repr() -> None:
user = User(username="admin", password="secret")
assert repr(user) == "<User admin>"
@@ -234,10 +249,13 @@ def test_received_status_round_trips_as_enum(app: Flask) -> None:
db.session.add(mention)
db.session.commit()
- assert db.session.scalar(
- sa.text("SELECT status FROM received_webmentions WHERE uuid = :uuid"),
- {"uuid": identifier.hex},
- ) == "verified"
+ assert (
+ db.session.scalar(
+ sa.text("SELECT status FROM received_webmentions WHERE uuid = :uuid"),
+ {"uuid": identifier.hex},
+ )
+ == "verified"
+ )
db.session.expunge_all()
loaded = db.session.get(ReceivedWebmention, identifier)
@@ -287,7 +305,6 @@ def test_reopen_preserves_delivery_history() -> None:
assert mention.sent_revision == 2
-
def test_resend_requeues_current_revision_without_losing_send_history() -> None:
from webmentions_ssg.models import SentWebmentionStatus
diff --git a/tests/test_net.py b/tests/test_net.py
index 42b9261..4ac138d 100644
--- a/tests/test_net.py
+++ b/tests/test_net.py
@@ -75,9 +75,7 @@ def test_backend_closes_failed_socket_and_tries_next_address(
first.connect.side_effect = TimeoutError("connection timed out")
monkeypatch.setattr(socket, "socket", Mock(side_effect=[first, second]))
- stream = PublicNetworkBackend(NetworkDeadline(5)).connect_tcp(
- "example.com", 443
- )
+ stream = PublicNetworkBackend(NetworkDeadline(5)).connect_tcp("example.com", 443)
assert isinstance(stream, DeadlineStream)
first.close.assert_called_once_with()
diff --git a/tests/views/test_session.py b/tests/views/test_session.py
index d89f98e..1a58f52 100644
--- a/tests/views/test_session.py
+++ b/tests/views/test_session.py
@@ -173,7 +173,9 @@ def test_login_always_checks_password(
assert response.status_code == 302
assert response.headers["Location"].endswith("/login")
expected_hash = (
- real_password_hash if username == "admin" else views_module.dummy_password_hash()
+ real_password_hash
+ if username == "admin"
+ else views_module.dummy_password_hash()
)
assert checked_passwords == [(expected_hash, password or "")]
diff --git a/webmentions_ssg/models.py b/webmentions_ssg/models.py
index ea2de0b..622e3b8 100644
--- a/webmentions_ssg/models.py
+++ b/webmentions_ssg/models.py
@@ -4,8 +4,6 @@
"""Define database models for users and incoming and outgoing Webmentions."""
-from __future__ import annotations
-
import json
from datetime import UTC, datetime
from enum import StrEnum
diff --git a/webmentions_ssg/net.py b/webmentions_ssg/net.py
index 02c7f2b..c9c2bec 100644
--- a/webmentions_ssg/net.py
+++ b/webmentions_ssg/net.py
@@ -256,7 +256,7 @@ def hostname_of(url: str) -> str | None:
"""Return a normalized URL hostname, or None for malformed URLs."""
try:
hostname = urlsplit(url).hostname
- except (TypeError, ValueError):
+ except TypeError, ValueError:
return None
return hostname.rstrip(".") if hostname is not None else None