aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDennis Fink2026-11-12 22:56:07 +0100
committerDennis Fink2026-11-12 22:56:07 +0100
commita10b29ac98ba535a5c2f9697c54265edd2c84a78 (patch)
treef116a58be6e241a11d283683070ebb18c96aa8e4 /tests
parent1db6b47f88dde5538efa433328987c70eab74d70 (diff)
downloadwebmentions-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 '')
-rw-r--r--tests/conftest.py3
-rw-r--r--tests/tasks/test_consumer.py6
-rw-r--r--tests/tasks/test_notifications.py2
-rw-r--r--tests/tasks/test_receiver.py2
-rw-r--r--tests/tasks/test_retention.py2
-rw-r--r--tests/tasks/test_scanner.py2
-rw-r--r--tests/tasks/test_sender.py2
-rw-r--r--tests/test_auth.py2
-rw-r--r--tests/test_cli.py50
-rw-r--r--tests/test_config.py8
-rw-r--r--tests/test_init.py4
-rw-r--r--tests/test_models.py2
-rw-r--r--tests/views/helpers.py2
-rw-r--r--tests/views/test_admin.py2
-rw-r--r--tests/views/test_endpoint.py2
-rw-r--r--tests/views/test_session.py2
16 files changed, 46 insertions, 47 deletions
diff --git a/tests/conftest.py b/tests/conftest.py
index 3064393..d4336b0 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -8,8 +8,7 @@ import pytest
from flask import Flask
from flask.testing import FlaskClient
-from webmentions_ssg import DATABASE as db
-from webmentions_ssg import create_app
+from webmentions_ssg import create_app, db
from webmentions_ssg.config import TestingConfig
diff --git a/tests/tasks/test_consumer.py b/tests/tasks/test_consumer.py
index 7604691..1563cdd 100644
--- a/tests/tasks/test_consumer.py
+++ b/tests/tasks/test_consumer.py
@@ -10,7 +10,7 @@ from unittest.mock import Mock
import pytest
from flask import Flask
-from webmentions_ssg import HUEY
+from webmentions_ssg import huey
def test_consumer_registers_scanner_digest_reaper_and_retention(
@@ -34,12 +34,12 @@ def test_consumer_registers_scanner_digest_reaper_and_retention(
periodic_task = Mock(side_effect=register)
monkeypatch.setattr(webmentions_ssg, "create_app", Mock(return_value=app))
- monkeypatch.setattr(HUEY, "periodic_task", periodic_task)
+ monkeypatch.setattr(huey, "periodic_task", periodic_task)
consumer = importlib.import_module("webmentions_ssg.tasks.consumer")
from webmentions_ssg.tasks import notifications, receiver, retention, scanner
- assert consumer.huey is HUEY.huey
+ assert consumer.huey is huey.huey
assert periodic_task.call_count == 4
assert registered_tasks == [
scanner.scan_sources,
diff --git a/tests/tasks/test_notifications.py b/tests/tasks/test_notifications.py
index f523d82..0254b19 100644
--- a/tests/tasks/test_notifications.py
+++ b/tests/tasks/test_notifications.py
@@ -10,7 +10,7 @@ from unittest.mock import patch
import pytest
from flask import Flask
-from webmentions_ssg import DATABASE as db
+from webmentions_ssg import db
from webmentions_ssg.models import ReceivedWebmention
diff --git a/tests/tasks/test_receiver.py b/tests/tasks/test_receiver.py
index 5441eb7..133ab56 100644
--- a/tests/tasks/test_receiver.py
+++ b/tests/tasks/test_receiver.py
@@ -13,7 +13,7 @@ import pytest
import sqlalchemy as sa
from flask import Flask
-from webmentions_ssg import DATABASE as db
+from webmentions_ssg import db
from webmentions_ssg.models import ReceivedWebmention
from webmentions_ssg.net import AddressResolutionError
diff --git a/tests/tasks/test_retention.py b/tests/tasks/test_retention.py
index 3f421f9..9e08837 100644
--- a/tests/tasks/test_retention.py
+++ b/tests/tasks/test_retention.py
@@ -10,7 +10,7 @@ from datetime import UTC, datetime, timedelta
import sqlalchemy as sa
from flask import Flask
-from webmentions_ssg import DATABASE as db
+from webmentions_ssg import db
from webmentions_ssg.models import ReceivedWebmention
from webmentions_ssg.tasks.retention import purge_old_received_webmentions
diff --git a/tests/tasks/test_scanner.py b/tests/tasks/test_scanner.py
index c46a274..d11b3f2 100644
--- a/tests/tasks/test_scanner.py
+++ b/tests/tasks/test_scanner.py
@@ -16,7 +16,7 @@ from flask import Flask
from huey.exceptions import RetryTask
from pytest import MonkeyPatch
-from webmentions_ssg import DATABASE as db
+from webmentions_ssg import db
from webmentions_ssg.models import SentWebmention, SentWebmentionStatus, Source
from webmentions_ssg.tasks import source_parser
diff --git a/tests/tasks/test_sender.py b/tests/tasks/test_sender.py
index c2f6e02..94523e5 100644
--- a/tests/tasks/test_sender.py
+++ b/tests/tasks/test_sender.py
@@ -12,7 +12,7 @@ import httpx
import pytest
from flask import Flask
-from webmentions_ssg import DATABASE as db
+from webmentions_ssg import db
from webmentions_ssg.models import SentWebmention, SentWebmentionStatus, Source
SOURCE_URL = "https://dennisfink.me/blog/example/"
diff --git a/tests/test_auth.py b/tests/test_auth.py
index 3b87923..008382a 100644
--- a/tests/test_auth.py
+++ b/tests/test_auth.py
@@ -7,7 +7,7 @@
import pytest
from flask import Flask
-from webmentions_ssg import DATABASE as db
+from webmentions_ssg import db
from webmentions_ssg.auth import AUTH, is_safe_next_url, load_user
from webmentions_ssg.models import User
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=[
diff --git a/tests/test_config.py b/tests/test_config.py
index 599c930..4a59236 100644
--- a/tests/test_config.py
+++ b/tests/test_config.py
@@ -12,7 +12,7 @@ from flask_limiter.util import get_remote_address
from wtforms import Field, ValidationError
from wtforms.form import BaseForm
-from webmentions_ssg import LIMITER, create_app
+from webmentions_ssg import create_app, limiter
from webmentions_ssg.config import (
DefaultConfig,
DevelopmentConfig,
@@ -235,7 +235,7 @@ def test_production_rejects_ephemeral_or_discarding_huey_queue(
def test_production_prefers_explicit_huey_url_over_legacy_option(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
- monkeypatch.setattr(LIMITER, "init_app", lambda app: None)
+ monkeypatch.setattr(limiter, "init_app", lambda app: None)
config_path = tmp_path / "production.cfg"
config_path.write_text("# Configuration inherited from subclass.\n")
@@ -300,7 +300,7 @@ def test_production_uses_persistent_configured_secret(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
# The test concerns secret-key persistence, not Redis initialization.
- monkeypatch.setattr(LIMITER, "init_app", lambda app: None)
+ monkeypatch.setattr(limiter, "init_app", lambda app: None)
config_file = tmp_path / "production.cfg"
key = "a-fixed-key-with-32-plus-random-characters"
config_file.write_text(f"SECRET_KEY = {key!r}\n")
@@ -325,7 +325,7 @@ def test_production_accepts_environment_secret_override(
key = "another-long-persistent-secret-for-a-deployment"
monkeypatch.setenv("WEBMENTIONS_SSG_SECRET_KEY", key)
# Avoid requiring the optional Redis dependency for this configuration test.
- monkeypatch.setattr(LIMITER, "init_app", lambda app: None)
+ monkeypatch.setattr(limiter, "init_app", lambda app: None)
class EnvConfiguredProduction(ProductionConfig):
CONFIG_FILE = str(config_file)
diff --git a/tests/test_init.py b/tests/test_init.py
index 0a37786..7112654 100644
--- a/tests/test_init.py
+++ b/tests/test_init.py
@@ -6,13 +6,13 @@
from flask import Flask
-from webmentions_ssg import HUEY, VERSION
+from webmentions_ssg import VERSION, huey
from webmentions_ssg.net import is_http_url
def test_create_app_registers_blueprint_and_extensions(app: Flask) -> None:
assert "root" in app.blueprints
- assert app.extensions["huey"] is HUEY
+ assert app.extensions["huey"] is huey
assert app.jinja_env.filters["is_http_url"] is is_http_url
diff --git a/tests/test_models.py b/tests/test_models.py
index 26439b9..b1eed94 100644
--- a/tests/test_models.py
+++ b/tests/test_models.py
@@ -11,7 +11,7 @@ import sqlalchemy as sa
from flask import Flask
from sqlalchemy.exc import IntegrityError
-from webmentions_ssg import DATABASE as db
+from webmentions_ssg import db
from webmentions_ssg.models import (
ReceivedWebmention,
SentWebmention,
diff --git a/tests/views/helpers.py b/tests/views/helpers.py
index b32a066..da98aa6 100644
--- a/tests/views/helpers.py
+++ b/tests/views/helpers.py
@@ -11,7 +11,7 @@ import pytest
from flask import Flask
from flask.testing import FlaskClient
-from webmentions_ssg import DATABASE as db
+from webmentions_ssg import db
from webmentions_ssg.models import (
ReceivedWebmention,
SentWebmention,
diff --git a/tests/views/test_admin.py b/tests/views/test_admin.py
index 26a13f8..1499f64 100644
--- a/tests/views/test_admin.py
+++ b/tests/views/test_admin.py
@@ -11,7 +11,7 @@ import pytest
from flask import Flask
from flask.testing import FlaskClient
-from webmentions_ssg import DATABASE as db
+from webmentions_ssg import db
from webmentions_ssg.models import ReceivedWebmention, SentWebmention, User
from .helpers import (
diff --git a/tests/views/test_endpoint.py b/tests/views/test_endpoint.py
index 652250f..72efa47 100644
--- a/tests/views/test_endpoint.py
+++ b/tests/views/test_endpoint.py
@@ -13,7 +13,7 @@ from flask import Flask
from flask.testing import FlaskClient
from sqlalchemy.exc import IntegrityError
-from webmentions_ssg import DATABASE as db
+from webmentions_ssg import db
from webmentions_ssg.models import ReceivedWebmention
from .helpers import (
diff --git a/tests/views/test_session.py b/tests/views/test_session.py
index 6a96032..0c4de9f 100644
--- a/tests/views/test_session.py
+++ b/tests/views/test_session.py
@@ -8,7 +8,7 @@ import pytest
from flask import Flask
from flask.testing import FlaskClient
-from webmentions_ssg import DATABASE as db
+from webmentions_ssg import db
from webmentions_ssg.models import User
from .helpers import log_in, mock_login_form