Fix setup persistence and load persisted runtime configuration
This commit is contained in:
@@ -143,6 +143,28 @@ class TestPostSetup:
|
||||
assert response.status_code == 201
|
||||
|
||||
|
||||
class TestPostSetupRuntimeState:
|
||||
async def test_updates_runtime_settings_after_setup(
|
||||
self, app_and_client: tuple[object, AsyncClient]
|
||||
) -> None:
|
||||
"""App state should reflect setup settings immediately after setup."""
|
||||
app, client = app_and_client
|
||||
payload = {
|
||||
"master_password": "supersecret123",
|
||||
"database_path": "bangui.db",
|
||||
"fail2ban_socket": "/tmp/persisted.sock",
|
||||
"timezone": "Europe/Berlin",
|
||||
"session_duration_minutes": 90,
|
||||
}
|
||||
|
||||
response = await client.post("/api/setup", json=payload)
|
||||
assert response.status_code == 201
|
||||
assert app.state.settings.database_path == payload["database_path"]
|
||||
assert app.state.settings.fail2ban_socket == payload["fail2ban_socket"]
|
||||
assert app.state.settings.timezone == payload["timezone"]
|
||||
assert app.state.settings.session_duration_minutes == payload["session_duration_minutes"]
|
||||
|
||||
|
||||
class TestSetupRedirectMiddleware:
|
||||
"""Verify that the setup-redirect middleware enforces setup-first."""
|
||||
|
||||
@@ -316,8 +338,9 @@ class TestLifespanDatabaseDirectoryCreation:
|
||||
patch("app.tasks.blocklist_import.register"),
|
||||
patch("app.tasks.geo_cache_flush.register"),
|
||||
patch("app.tasks.geo_re_resolve.register"),
|
||||
patch("app.main.AsyncIOScheduler", return_value=mock_scheduler),
|
||||
patch("app.main.ensure_jail_configs"),
|
||||
patch("app.tasks.history_sync.register"),
|
||||
patch("app.startup.AsyncIOScheduler", return_value=mock_scheduler),
|
||||
patch("app.startup.ensure_jail_configs"),
|
||||
):
|
||||
async with _lifespan(app):
|
||||
assert nested_db.parent.exists(), (
|
||||
@@ -359,8 +382,9 @@ class TestLifespanDatabaseDirectoryCreation:
|
||||
patch("app.tasks.blocklist_import.register"),
|
||||
patch("app.tasks.geo_cache_flush.register"),
|
||||
patch("app.tasks.geo_re_resolve.register"),
|
||||
patch("app.main.AsyncIOScheduler", return_value=mock_scheduler),
|
||||
patch("app.main.ensure_jail_configs"),
|
||||
patch("app.tasks.history_sync.register"),
|
||||
patch("app.startup.AsyncIOScheduler", return_value=mock_scheduler),
|
||||
patch("app.startup.ensure_jail_configs"),
|
||||
):
|
||||
# Should not raise FileExistsError or similar.
|
||||
async with _lifespan(app):
|
||||
@@ -409,8 +433,9 @@ class TestLifespanSetupCache:
|
||||
patch("app.tasks.blocklist_import.register"),
|
||||
patch("app.tasks.geo_cache_flush.register"),
|
||||
patch("app.tasks.geo_re_resolve.register"),
|
||||
patch("app.main.AsyncIOScheduler", return_value=mock_scheduler),
|
||||
patch("app.main.ensure_jail_configs"),
|
||||
patch("app.tasks.history_sync.register"),
|
||||
patch("app.startup.AsyncIOScheduler", return_value=mock_scheduler),
|
||||
patch("app.startup.ensure_jail_configs"),
|
||||
):
|
||||
async with _lifespan(app):
|
||||
assert app.state.setup_complete_cached is True
|
||||
|
||||
Reference in New Issue
Block a user