diff options
| author | Dennis Fink | 2026-11-12 22:56:07 +0100 |
|---|---|---|
| committer | Dennis Fink | 2026-11-12 22:56:07 +0100 |
| commit | a10b29ac98ba535a5c2f9697c54265edd2c84a78 (patch) | |
| tree | f116a58be6e241a11d283683070ebb18c96aa8e4 /tests/test_cli.py | |
| parent | 1db6b47f88dde5538efa433328987c70eab74d70 (diff) | |
| download | webmentions-ssg-a10b29ac98ba535a5c2f9697c54265edd2c84a78.tar.gz webmentions-ssg-a10b29ac98ba535a5c2f9697c54265edd2c84a78.zip | |
refactor(core): use lowercase extension names
Rename shared Flask extension singletons to conventional lowercase names
and update imports throughout the application and tests to remove
redundant aliases.
Diffstat (limited to 'tests/test_cli.py')
| -rw-r--r-- | tests/test_cli.py | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/tests/test_cli.py b/tests/test_cli.py index f6b7051..e6214f2 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -15,7 +15,7 @@ from flask_migrate import upgrade as migrate_upgrade from sqlalchemy import inspect from sqlalchemy.exc import IntegrityError -from webmentions_ssg import DATABASE, MIGRATE, create_app +from webmentions_ssg import create_app, db, migrate from webmentions_ssg.config import TestingConfig from webmentions_ssg.models import User @@ -37,13 +37,13 @@ def database_app(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> Iterator[Fl yield app with app.app_context(): - DATABASE.session.remove() - DATABASE.engine.dispose() + db.session.remove() + db.engine.dispose() def _script_directory() -> ScriptDirectory: """Open the migration scripts configured for this application.""" - return ScriptDirectory(str(MIGRATE.directory)) + return ScriptDirectory(str(migrate.directory)) def _head_revision(app: Flask) -> str: @@ -54,7 +54,7 @@ def _head_revision(app: Flask) -> str: def _database_revision(app: Flask) -> str: - with app.app_context(), DATABASE.engine.connect() as connection: + with app.app_context(), db.engine.connect() as connection: return connection.execute( sa.text("SELECT version_num FROM alembic_version") ).scalar_one() @@ -86,7 +86,7 @@ def test_create_db_builds_schema_and_records_latest_migration( assert _database_revision(database_app) == _head_revision(database_app) with database_app.app_context(): - inspector = inspect(DATABASE.engine) + inspector = inspect(db.engine) table_names = set(inspector.get_table_names()) columns = { column["name"] for column in inspector.get_columns("sent_webmentions") @@ -118,7 +118,7 @@ def test_create_db_refuses_existing_database_without_modifying_it( def test_create_db_refuses_unversioned_existing_tables(database_app: Flask) -> None: - with database_app.app_context(), DATABASE.engine.begin() as connection: + with database_app.app_context(), db.engine.begin() as connection: connection.execute(sa.text("CREATE TABLE legacy_data (id INTEGER PRIMARY KEY)")) result = database_app.test_cli_runner().invoke(args=["db", "create-db"]) @@ -126,8 +126,8 @@ def test_create_db_refuses_unversioned_existing_tables(database_app: Flask) -> N assert result.exit_code != 0 assert "already contains tables" in result.output with database_app.app_context(): - assert "legacy_data" in inspect(DATABASE.engine).get_table_names() - assert "alembic_version" not in inspect(DATABASE.engine).get_table_names() + assert "legacy_data" in inspect(db.engine).get_table_names() + assert "alembic_version" not in inspect(db.engine).get_table_names() def test_upgrade_requires_an_initialized_database(database_app: Flask) -> None: @@ -138,7 +138,7 @@ def test_upgrade_requires_an_initialized_database(database_app: Flask) -> None: def test_upgrade_refuses_unversioned_existing_database(database_app: Flask) -> None: - with database_app.app_context(), DATABASE.engine.begin() as connection: + with database_app.app_context(), db.engine.begin() as connection: connection.execute(sa.text("CREATE TABLE legacy_data (id INTEGER PRIMARY KEY)")) result = database_app.test_cli_runner().invoke(args=["db", "upgrade"]) @@ -146,7 +146,7 @@ def test_upgrade_refuses_unversioned_existing_database(database_app: Flask) -> N assert result.exit_code != 0 assert "No Flask-Migrate revision table" in result.output with database_app.app_context(): - assert "legacy_data" in inspect(DATABASE.engine).get_table_names() + assert "legacy_data" in inspect(db.engine).get_table_names() def test_upgrade_applies_pending_migrations_and_preserves_data( @@ -159,7 +159,7 @@ def test_upgrade_applies_pending_migrations_and_preserves_data( assert base_revision != _head_revision(database_app) migrate_upgrade(revision=base_revision) - with DATABASE.engine.begin() as connection: + with db.engine.begin() as connection: connection.execute( sa.text( "INSERT INTO users (username, password_hash) " @@ -174,7 +174,7 @@ def test_upgrade_applies_pending_migrations_and_preserves_data( assert "Database upgraded" in result.output assert _database_revision(database_app) == _head_revision(database_app) - with database_app.app_context(), DATABASE.engine.connect() as connection: + with database_app.app_context(), db.engine.connect() as connection: assert ( connection.execute( sa.text("SELECT password_hash FROM users WHERE username = :username"), @@ -233,7 +233,7 @@ def test_upgrade_backfills_portable_digest_for_existing_received_rows( with database_app.app_context(): migrate_upgrade(revision="c0272f25ce17") - with DATABASE.engine.begin() as connection: + with db.engine.begin() as connection: connection.execute( sa.text( "INSERT INTO received_webmentions " @@ -249,7 +249,7 @@ def test_upgrade_backfills_portable_digest_for_existing_received_rows( }, ) migrate_upgrade() - with DATABASE.engine.connect() as connection: + with db.engine.connect() as connection: result = connection.execute( sa.text( "SELECT source, target, status, url_digest " @@ -278,7 +278,7 @@ def test_mail_cli_sends_to_configured_notification_email(app: Flask) -> None: NOTIFICATION_EMAIL="owner@example.com", MAIL_DEFAULT_SENDER="sender@example.com" ) - with patch("webmentions_ssg.MAIL.send") as send: + with patch("webmentions_ssg.mail.send") as send: result = app.test_cli_runner().invoke(args=["mail", "test"]) assert result.exit_code == 0, result.output @@ -296,7 +296,7 @@ def test_mail_cli_overrides_configured_recipient(app: Flask) -> None: NOTIFICATION_EMAIL="owner@example.com", MAIL_DEFAULT_SENDER="sender@example.com" ) - with patch("webmentions_ssg.MAIL.send") as send: + with patch("webmentions_ssg.mail.send") as send: result = app.test_cli_runner().invoke( args=["mail", "test", "--to", "other@example.com"] ) @@ -309,7 +309,7 @@ def test_mail_cli_overrides_configured_recipient(app: Flask) -> None: def test_mail_cli_requires_recipient(app: Flask) -> None: app.config.update(NOTIFICATION_EMAIL=None, MAIL_DEFAULT_SENDER="sender@example.com") - with patch("webmentions_ssg.MAIL.send") as send: + with patch("webmentions_ssg.mail.send") as send: result = app.test_cli_runner().invoke(args=["mail", "test"]) assert result.exit_code != 0 @@ -320,7 +320,7 @@ def test_mail_cli_requires_recipient(app: Flask) -> None: def test_mail_cli_requires_default_sender(app: Flask) -> None: app.config.update(NOTIFICATION_EMAIL="owner@example.com", MAIL_DEFAULT_SENDER=None) - with patch("webmentions_ssg.MAIL.send") as send: + with patch("webmentions_ssg.mail.send") as send: result = app.test_cli_runner().invoke(args=["mail", "test"]) assert result.exit_code != 0 @@ -334,7 +334,7 @@ def test_mail_cli_reports_smtp_failure(app: Flask) -> None: ) with patch( - "webmentions_ssg.MAIL.send", side_effect=ConnectionError("SMTP unavailable") + "webmentions_ssg.mail.send", side_effect=ConnectionError("SMTP unavailable") ) as send: result = app.test_cli_runner().invoke(args=["mail", "test"]) @@ -346,13 +346,13 @@ def test_mail_cli_reports_smtp_failure(app: Flask) -> None: def _add_user(app: Flask, username: str, password: str = "original") -> None: """Persist a user using the same model as the CLI.""" with app.app_context(): - DATABASE.session.add(User(username=username, password=password)) - DATABASE.session.commit() + db.session.add(User(username=username, password=password)) + db.session.commit() def _get_user(app: Flask, username: str) -> User | None: with app.app_context(): - return DATABASE.session.scalar(sa.select(User).where(User.username == username)) + return db.session.scalar(sa.select(User).where(User.username == username)) def test_users_cli_help_lists_management_commands(app: Flask) -> None: @@ -584,8 +584,8 @@ def test_users_cli_create_rolls_back_on_duplicate_race(app: Flask) -> None: with app.app_context(): with ( - patch.object(DATABASE.session, "commit", side_effect=database_error), - patch.object(DATABASE.session, "rollback") as rollback, + patch.object(db.session, "commit", side_effect=database_error), + patch.object(db.session, "rollback") as rollback, ): result = app.test_cli_runner().invoke( args=[ |
