aboutsummaryrefslogtreecommitdiff
path: root/tests/test_init.py
diff options
context:
space:
mode:
authorDennis Fink2026-11-19 21:18:37 +0100
committerDennis Fink2026-11-19 21:18:37 +0100
commiteb11fb64e9cad6fbda2065362189653416d98577 (patch)
tree0bc5737b1c273ea6f04adc015154565c385dc719 /tests/test_init.py
parent88f54d9a7699944b7d56f978e724b1c0b54dde98 (diff)
downloadwebmentions-ssg-eb11fb64e9cad6fbda2065362189653416d98577.tar.gz
webmentions-ssg-eb11fb64e9cad6fbda2065362189653416d98577.zip
test: expand failure and migration coverage
Add regression coverage for malformed input, lost task claims, moderation races, network failures, serializer validation, and production configuration guards. Exercise migration downgrade, backfill, and autogeneration paths plus additional receiver and sender edge cases.
Diffstat (limited to '')
-rw-r--r--tests/test_init.py58
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/test_init.py b/tests/test_init.py
index 0966b19..373af01 100644
--- a/tests/test_init.py
+++ b/tests/test_init.py
@@ -8,6 +8,7 @@ import subprocess
import sys
from pathlib import Path
+import pytest
from flask import Flask
from sqlalchemy import create_engine
@@ -207,3 +208,60 @@ def test_sqlite_connect_listener_does_not_touch_other_dbapis() -> None:
# Non-SQLite DB-API connections bypass the listener completely.
set_sqlite_pragmas(object(), object())
+
+
+@pytest.mark.parametrize("development", [False, True])
+def test_create_app_selects_default_configuration_from_environment(
+ monkeypatch: pytest.MonkeyPatch, development: bool
+) -> None:
+ import webmentions_ssg as package
+
+ class DefaultTestConfig(TestingConfig):
+ LOG_FILE = str(Path.cwd() / "testing" / "default-config-test.log")
+
+ class DevelopmentTestConfig(DefaultTestConfig):
+ CONFIG_SELECTION = "development"
+
+ class ProductionTestConfig(DefaultTestConfig):
+ CONFIG_SELECTION = "production"
+
+ monkeypatch.setattr(package, "DevelopmentConfig", DevelopmentTestConfig)
+ monkeypatch.setattr(package, "ProductionConfig", ProductionTestConfig)
+ if development:
+ monkeypatch.setenv("WEBMENTIONS_SSG_DEV", "true")
+ else:
+ monkeypatch.delenv("WEBMENTIONS_SSG_DEV", raising=False)
+
+ application = create_app()
+ assert application.config["CONFIG_SELECTION"] == (
+ "development" if development else "production"
+ )
+
+
+def test_sqlite_connect_rejects_journal_mode_that_cannot_be_applied(
+ app: Flask, monkeypatch: pytest.MonkeyPatch
+) -> None:
+ from unittest.mock import Mock
+
+ from webmentions_ssg import extensions
+
+ cursor = Mock()
+ cursor.fetchall.return_value = [(0, "main", "/tmp/test-file.sqlite")]
+ cursor.fetchone.side_effect = [("DELETE",), ("DELETE",)]
+
+ class FakeConnection:
+ def __init__(self) -> None:
+ self.autocommit = False
+
+ def cursor(self) -> Mock:
+ return cursor
+
+ connection = FakeConnection()
+ with app.app_context(), monkeypatch.context() as patcher:
+ patcher.setattr(extensions.sqlite3, "Connection", FakeConnection)
+ with pytest.raises(RuntimeError, match="journal_mode WAL was not applied"):
+ extensions.set_sqlite_pragmas(connection, None)
+
+ assert connection.autocommit is False
+ cursor.close.assert_called_once_with()
+ cursor.execute.assert_any_call("PRAGMA journal_mode = WAL")