diff options
Diffstat (limited to 'tests/test_cli.py')
| -rw-r--r-- | tests/test_cli.py | 44 |
1 files changed, 43 insertions, 1 deletions
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" |
