From defec7cc7d9f77f96ae08b3dac9652541e08222d Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Fri, 13 Nov 2026 21:34:32 +0100 Subject: refactor(receiver): map received status to enum Store `ReceivedWebmention.status` as a non-native SQLAlchemy enum so model values round-trip as `ReceivedStatus` while remaining portable across database backends. Add a migration that preserves existing text statuses and coverage for upgrades and enum persistence. --- tests/test_cli.py | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) (limited to 'tests/test_cli.py') diff --git a/tests/test_cli.py b/tests/test_cli.py index ac673b4..0d9b357 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -5,6 +5,7 @@ import logging from collections.abc import Iterator from pathlib import Path +from uuid import UUID from unittest.mock import patch import pytest @@ -17,7 +18,7 @@ from sqlalchemy.exc import IntegrityError from webmentions_ssg import create_app, db, migrate from webmentions_ssg.config import TestingConfig -from webmentions_ssg.models import User +from webmentions_ssg.models import ReceivedStatus, ReceivedWebmention, User def test_cli_groups_are_registered(app: Flask) -> None: @@ -273,6 +274,47 @@ def test_upgrade_backfills_portable_digest_for_existing_received_rows( ) +def test_upgrade_converts_received_status_without_losing_rows( + database_app: Flask, +) -> None: + """An existing text status survives the non-native Enum migration.""" + identifier = "0" * 31 + "1" + with database_app.app_context(): + migrate_upgrade(revision="e62b1a7c4d90") + with db.engine.begin() as connection: + connection.execute( + sa.text( + "INSERT INTO received_webmentions " + "(uuid, source, target, url_digest, status, updated_at) " + "VALUES (:uuid, :source, :target, :url_digest, :status, :updated_at)" + ), + { + "uuid": identifier, + "source": "https://source.example/old", + "target": "https://dennisfink.me/target", + "url_digest": "0" * 64, + "status": "verifying", + "updated_at": "2026-01-01 00:00:00", + }, + ) + + migrate_upgrade() + with db.engine.connect() as connection: + columns = { + column["name"]: column + for column in inspect(connection).get_columns("received_webmentions") + } + 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" + + mention = db.session.get(ReceivedWebmention, UUID(hex=identifier)) + assert mention is not None + assert mention.status is ReceivedStatus.VERIFYING + + def test_mail_cli_sends_to_configured_notification_email(app: Flask) -> None: app.config.update( NOTIFICATION_EMAIL="owner@example.com", MAIL_DEFAULT_SENDER="sender@example.com" -- cgit v1.3.1