diff options
| author | Dennis Fink | 2026-11-13 21:45:19 +0100 |
|---|---|---|
| committer | Dennis Fink | 2026-11-13 21:48:58 +0100 |
| commit | 4c50f6be754c7a474c5abc2cde7412041289f754 (patch) | |
| tree | aae7ef7a8522a581de7fa66536c294ba9e6f6bc8 /tests/test_models.py | |
| parent | 497de85e7f2b91dc9e8ac546e9c1e41f9b6ae43f (diff) | |
| download | webmentions-ssg-4c50f6be754c7a474c5abc2cde7412041289f754.tar.gz webmentions-ssg-4c50f6be754c7a474c5abc2cde7412041289f754.zip | |
refactor(core): remove postponed model annotations
Drop `from __future__ import annotations` now that UUID names no longer
shadow the module namespace, and add coverage that mapped UUID and
relationship annotations resolve correctly at runtime.
Apply minor Python 3.14 syntax and formatting cleanup across tests and
networking.
Diffstat (limited to 'tests/test_models.py')
| -rw-r--r-- | tests/test_models.py | 27 |
1 files changed, 22 insertions, 5 deletions
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 |
