Fix startup runtime settings ordering and use effective database path for request DB connections

This commit is contained in:
2026-04-12 20:02:40 +02:00
parent ee880e6296
commit e6df045e5e
3 changed files with 33 additions and 133 deletions

View File

@@ -1,7 +1,7 @@
from __future__ import annotations
from pathlib import Path
from unittest.mock import MagicMock
from unittest.mock import AsyncMock, MagicMock, patch
import aiohttp
import pytest
@@ -12,6 +12,7 @@ from app.config import Settings
from app.dependencies import (
ApplicationContext,
get_app_context,
get_db,
get_http_session,
get_scheduler,
get_settings,
@@ -64,6 +65,25 @@ async def test_app_context_dependency_exposes_shared_resources(test_settings: Se
await session.close()
@pytest.mark.asyncio
async def test_get_db_uses_effective_runtime_database_path(test_settings: Settings) -> None:
"""Database connections should use effective runtime settings when overridden."""
runtime_settings = test_settings.model_copy(update={"database_path": "/tmp/runtime.db"})
mock_connection = MagicMock()
mock_connection.close = AsyncMock()
with patch("app.db.open_db", new=AsyncMock(return_value=mock_connection)) as mock_open_db:
gen = get_db(settings=runtime_settings)
try:
connection = await gen.__anext__()
assert connection is mock_connection
finally:
await gen.aclose()
mock_open_db.assert_awaited_once_with("/tmp/runtime.db")
def test_request_app_state_access_is_only_allowed_in_dependencies() -> None:
app_root = Path(__file__).resolve().parents[1] / "app"
bad_modules: list[str] = []