diff options
| author | Dennis Fink | 2026-11-15 21:18:19 +0100 |
|---|---|---|
| committer | Dennis Fink | 2026-11-15 21:18:19 +0100 |
| commit | 9b00526ab79257b65cedd71595848f09ecf84279 (patch) | |
| tree | f9dfc5c0934499d47499bf083bd864f72947958c /tests/test_models.py | |
| parent | 509d93b2976e353d29441a7a7b7e78ca466dc4fd (diff) | |
| download | webmentions-ssg-9b00526ab79257b65cedd71595848f09ecf84279.tar.gz webmentions-ssg-9b00526ab79257b65cedd71595848f09ecf84279.zip | |
refactor(core)!: clarify Webmention domain terminology
Rename ambiguous models, statuses, task modules, fields, and helpers so
names reflect source documents, verification, endpoint discovery, and
delivery state.
Migrate persisted status values and database identifiers without losing
existing Webmention data.
BREAKING CHANGE: persisted status values and database schema names have
changed, and several public Python names have been renamed.
Diffstat (limited to '')
| -rw-r--r-- | tests/test_models.py | 121 |
1 files changed, 66 insertions, 55 deletions
diff --git a/tests/test_models.py b/tests/test_models.py index d2b667c..4e785c7 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -16,28 +16,31 @@ from sqlalchemy.orm import Mapped from webmentions_ssg import db from webmentions_ssg.models import ( - ReceivedStatus, ReceivedWebmention, + ReceivedWebmentionStatus, SentWebmention, - Source, + SourceDocument, User, - received_url_digest, - sent_target_digest, + source_target_digest, + target_digest, uuid7_to_datetime, ) def test_uuid_annotations_and_relationships_resolve() -> None: """Verify that UUID columns and forward relationships map correctly.""" - for model in (ReceivedWebmention, Source, SentWebmention): + for model in (ReceivedWebmention, SourceDocument, 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_ + sa.inspect(SourceDocument).relationships["sent_webmentions"].mapper.class_ is SentWebmention ) - assert sa.inspect(SentWebmention).relationships["source"].mapper.class_ is Source + assert ( + sa.inspect(SentWebmention).relationships["source"].mapper.class_ + is SourceDocument + ) def test_user_repr() -> None: @@ -61,14 +64,16 @@ def test_user_password_is_hashed_and_can_be_checked() -> None: @pytest.mark.parametrize( ("status", "expected"), [ - (ReceivedStatus.RECEIVED, False), - (ReceivedStatus.VERIFYING, False), - (ReceivedStatus.VERIFIED, True), - (ReceivedStatus.FAILED, False), - (ReceivedStatus.DELETED, False), + (ReceivedWebmentionStatus.RECEIVED, False), + (ReceivedWebmentionStatus.VERIFYING, False), + (ReceivedWebmentionStatus.VERIFIED, True), + (ReceivedWebmentionStatus.FAILED, False), + (ReceivedWebmentionStatus.SOURCE_REMOVED, False), ], ) -def test_received_webmention_verified(status: ReceivedStatus, expected: bool) -> None: +def test_received_webmention_verified( + status: ReceivedWebmentionStatus, expected: bool +) -> None: webmention = ReceivedWebmention( uuid=uuid.uuid7(), source="https://source.example/post", @@ -91,7 +96,7 @@ def test_sent_webmention_pending( desired_revision=desired_revision, processed_revision=processed_revision, ) - assert webmention.pending is expected + assert webmention.awaiting_processing is expected def test_sent_webmention_pending_sql_matches_python(app: Flask) -> None: @@ -99,7 +104,7 @@ def test_sent_webmention_pending_sql_matches_python(app: Flask) -> None: with app.app_context(): now = datetime.now(UTC) - source = Source( + source = SourceDocument( path="pending/index.html", url="https://site.example/pending/", content_hash="0" * 32, @@ -119,18 +124,18 @@ def test_sent_webmention_pending_sql_matches_python(app: Flask) -> None: pending_ids = set( db.session.scalars( - sa.select(SentWebmention.uuid).where(SentWebmention.pending) + sa.select(SentWebmention.uuid).where(SentWebmention.awaiting_processing) ) ) for webmention, (_, _, expected) in zip( source.sent_webmentions, cases, strict=True ): - assert webmention.pending is expected + assert webmention.awaiting_processing is expected assert (webmention.uuid in pending_ids) is expected result = db.session.execute( sa.update(SentWebmention) - .where(SentWebmention.pending) + .where(SentWebmention.awaiting_processing) .values(attempt_count=1) ) assert result.rowcount == 3 @@ -156,7 +161,7 @@ def test_uuid7_to_datetime() -> None: id="received-webmention", ), pytest.param( - lambda identifier: Source( + lambda identifier: SourceDocument( uuid=identifier, path="example/index.html", url="https://dennisfink.me/blog/example/", @@ -176,7 +181,9 @@ def test_uuid7_to_datetime() -> None: ], ) def test_created_at_comes_from_uuid7_timestamp( - factory: Callable[[uuid.UUID], ReceivedWebmention | Source | SentWebmention], + factory: Callable[ + [uuid.UUID], ReceivedWebmention | SourceDocument | SentWebmention + ], ) -> None: identifier = uuid.uuid7() model = factory(identifier) @@ -197,7 +204,7 @@ def test_received_webmention_repr() -> None: def test_source_repr() -> None: - source = Source( + source = SourceDocument( path="example/index.html", url="https://dennisfink.me/blog/example/", content_hash="0" * 32, @@ -205,7 +212,7 @@ def test_source_repr() -> None: last_seen_at=datetime.now(UTC), revised_at=datetime.now(UTC), ) - assert repr(source) == "<Source 'https://dennisfink.me/blog/example/'>" + assert repr(source) == "<SourceDocument 'https://dennisfink.me/blog/example/'>" def test_sent_webmention_repr() -> None: @@ -233,9 +240,9 @@ def test_received_status_uses_non_native_enum() -> None: status_type = ReceivedWebmention.__table__.c.status.type assert isinstance(status_type, sa.Enum) - assert status_type.enum_class is ReceivedStatus + assert status_type.enum_class is ReceivedWebmentionStatus assert status_type.native_enum is False - assert status_type.enums == [status.value for status in ReceivedStatus] + assert status_type.enums == [status.value for status in ReceivedWebmentionStatus] def test_received_status_round_trips_as_enum(app: Flask) -> None: @@ -245,7 +252,7 @@ def test_received_status_round_trips_as_enum(app: Flask) -> None: uuid=identifier, source="https://source.example/post", target="https://dennisfink.me/blog/example/", - status=ReceivedStatus.VERIFIED, + status=ReceivedWebmentionStatus.VERIFIED, ) db.session.add(mention) db.session.commit() @@ -261,22 +268,22 @@ def test_received_status_round_trips_as_enum(app: Flask) -> None: db.session.expunge_all() loaded = db.session.get(ReceivedWebmention, identifier) assert loaded is not None - assert loaded.status is ReceivedStatus.VERIFIED + assert loaded.status is ReceivedWebmentionStatus.VERIFIED def test_received_verification_reset_is_reusable_for_atomic_updates() -> None: - from webmentions_ssg.models import ReceivedStatus + from webmentions_ssg.models import ReceivedWebmentionStatus mention = ReceivedWebmention( uuid=uuid.uuid7(), source="https://source.example/post", target="https://dennisfink.me/post", - status=ReceivedStatus.FAILED, + status=ReceivedWebmentionStatus.FAILED, failure_reason="Old error", recovery_attempts=3, ) - assert mention.reset_for_verification() is None - assert mention.status == ReceivedStatus.RECEIVED + assert mention.reopen_verification() is None + assert mention.status == ReceivedWebmentionStatus.RECEIVED assert mention.failure_reason is None assert mention.recovery_attempts == 0 assert mention.updated_at is not None @@ -288,7 +295,7 @@ def test_reopen_preserves_delivery_history() -> None: sent_at = datetime.now(UTC) mention = SentWebmention( target="https://example.com/post", - active=True, + linked=True, desired_revision=2, processed_revision=2, sent_revision=2, @@ -297,9 +304,9 @@ def test_reopen_preserves_delivery_history() -> None: next_retry_at=sent_at, last_sent_at=sent_at, ) - assert mention.reopen(3, False) is None + assert mention.reset_for_revision(3, False) is None assert mention.desired_revision == 3 - assert mention.active is False + assert mention.linked is False assert mention.attempt_count == 0 assert mention.next_retry_at is None assert mention.status == SentWebmentionStatus.SENT @@ -312,31 +319,31 @@ def test_resend_requeues_current_revision_without_losing_send_history() -> None: sent_at = datetime.now(UTC) mention = SentWebmention( target="https://example.com/post", - active=True, + linked=True, desired_revision=3, processed_revision=3, sent_revision=2, status=SentWebmentionStatus.FAILED, failure_reason="Previous failure", - endpoint="https://example.com/webmention", - response_status=HTTPStatus.SERVICE_UNAVAILABLE, + webmention_endpoint="https://example.com/webmention", + endpoint_response_status=HTTPStatus.SERVICE_UNAVAILABLE, status_url="https://example.com/status", attempt_count=3, next_retry_at=sent_at, last_attempted_at=sent_at, last_sent_at=sent_at, ) - assert not mention.pending + assert not mention.awaiting_processing - assert mention.resend() is None + assert mention.clear_result_for_resend() is None assert mention.desired_revision == 3 - assert mention.active is True - assert mention.pending + assert mention.linked is True + assert mention.awaiting_processing assert mention.processed_revision is None assert mention.status is None assert mention.failure_reason is None - assert mention.endpoint is None - assert mention.response_status is None + assert mention.webmention_endpoint is None + assert mention.endpoint_response_status is None assert mention.status_url is None assert mention.attempt_count == 0 assert mention.next_retry_at is None @@ -346,8 +353,8 @@ def test_resend_requeues_current_revision_without_losing_send_history() -> None: def test_received_pair_fingerprint_is_unambiguous() -> None: - assert received_url_digest("a", "bc") != received_url_digest("ab", "c") - assert received_url_digest("a", "b") != received_url_digest("b", "a") + assert source_target_digest("a", "bc") != source_target_digest("ab", "c") + assert source_target_digest("a", "b") != source_target_digest("b", "a") def test_models_hash_url_fields_when_created_or_changed() -> None: @@ -356,16 +363,22 @@ def test_models_hash_url_fields_when_created_or_changed() -> None: source="https://source.example/a", target="https://site.example/b", ) - assert received.url_digest == received_url_digest(received.source, received.target) + assert received.source_target_digest == source_target_digest( + received.source, received.target + ) received.source = "https://source.example/c" - assert received.url_digest == received_url_digest(received.source, received.target) + assert received.source_target_digest == source_target_digest( + received.source, received.target + ) received.target = "https://site.example/d" - assert received.url_digest == received_url_digest(received.source, received.target) + assert received.source_target_digest == source_target_digest( + received.source, received.target + ) sent = SentWebmention(target="https://site.example/a", desired_revision=1) - assert sent.target_digest == sent_target_digest(sent.target) + assert sent.target_digest == target_digest(sent.target) sent.target = "https://site.example/b" - assert sent.target_digest == sent_target_digest(sent.target) + assert sent.target_digest == target_digest(sent.target) def test_long_received_pair_can_be_stored_with_unique_digest(app: Flask) -> None: @@ -380,8 +393,8 @@ def test_long_received_pair_can_be_stored_with_unique_digest(app: Flask) -> None db.session.commit() match = db.session.scalar( sa.select(ReceivedWebmention).where( - ReceivedWebmention.url_digest - == received_url_digest(long_source, long_target) + ReceivedWebmention.source_target_digest + == source_target_digest(long_source, long_target) ) ) assert match is not None @@ -403,7 +416,7 @@ def test_long_sent_targets_enforce_uniqueness_without_indexing_url_text( now = datetime.now(UTC) long_target = "https://destination.example/" + "a" * 4000 with app.app_context(): - source = Source( + source = SourceDocument( path="long/index.html", url="https://example.com/long", content_hash="0" * 32, @@ -416,9 +429,7 @@ def test_long_sent_targets_enforce_uniqueness_without_indexing_url_text( ) db.session.add(source) db.session.commit() - assert source.sent_webmentions[0].target_digest == sent_target_digest( - long_target - ) + assert source.sent_webmentions[0].target_digest == target_digest(long_target) source.sent_webmentions.append( SentWebmention(target=long_target, desired_revision=1) |
