generated from john/python-template
Continue GC code review and cleanup
This commit is contained in:
+23
-16
@@ -7,18 +7,19 @@ from fastapi import FastAPI
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from transcription.app import create_app
|
||||
from transcription.config import Settings
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
class TestAppFactory:
|
||||
"""Verify FastAPI app factory wiring."""
|
||||
|
||||
def test_create_app_returns_fastapi_instance(self):
|
||||
def test_create_app_returns_fastapi_instance(self, monkeypatch):
|
||||
"""create_app returns a FastAPI application instance."""
|
||||
monkeypatch.setattr("transcription.app.register_pages", lambda _app: None)
|
||||
app = create_app()
|
||||
assert isinstance(app, FastAPI)
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
class TestAppLifespan:
|
||||
"""Verify startup and shutdown lifecycle behavior."""
|
||||
@@ -28,6 +29,7 @@ class TestAppLifespan:
|
||||
calls = []
|
||||
|
||||
monkeypatch.setattr("transcription.app.configure_logging", lambda _settings: calls.append("logging"))
|
||||
monkeypatch.setattr("transcription.app.register_pages", lambda _app: None)
|
||||
|
||||
async def _create_all(**_kwargs):
|
||||
calls.append("schema")
|
||||
@@ -56,12 +58,14 @@ class TestAppLifespan:
|
||||
|
||||
monkeypatch.setattr("transcription.app.worker_consumer_lifespan", _worker_lifespan)
|
||||
|
||||
class _Settings:
|
||||
should_bootstrap_schema = True
|
||||
upload_dir = tmp_path / "uploads"
|
||||
prompt_dir = tmp_path / "prompts"
|
||||
|
||||
monkeypatch.setattr("transcription.app.get_settings", lambda: _Settings())
|
||||
settings = Settings(
|
||||
openrouter_api_key="test-key",
|
||||
environment="test",
|
||||
bootstrap_schema_on_startup=True,
|
||||
upload_dir=tmp_path / "uploads",
|
||||
prompt_dir=tmp_path / "prompts",
|
||||
)
|
||||
monkeypatch.setattr("transcription.app.get_settings", lambda: settings)
|
||||
|
||||
app = create_app()
|
||||
with TestClient(app):
|
||||
@@ -73,14 +77,15 @@ class TestAppLifespan:
|
||||
assert "worker_start" in calls
|
||||
assert "worker_stop" in calls
|
||||
assert "dispose_db" in calls
|
||||
assert _Settings.upload_dir.exists()
|
||||
assert _Settings.prompt_dir.exists()
|
||||
assert settings.upload_dir.exists()
|
||||
assert settings.prompt_dir.exists()
|
||||
|
||||
def test_shutdown_stops_worker_resources(self, monkeypatch, tmp_path):
|
||||
"""Shutdown signals and stops worker resources cleanly."""
|
||||
calls = []
|
||||
|
||||
monkeypatch.setattr("transcription.app.configure_logging", lambda _settings: calls.append("logging"))
|
||||
monkeypatch.setattr("transcription.app.register_pages", lambda _app: None)
|
||||
|
||||
async def _create_all(**_kwargs):
|
||||
calls.append("schema")
|
||||
@@ -109,12 +114,14 @@ class TestAppLifespan:
|
||||
|
||||
monkeypatch.setattr("transcription.app.worker_consumer_lifespan", _worker_lifespan)
|
||||
|
||||
class _Settings:
|
||||
should_bootstrap_schema = True
|
||||
upload_dir = tmp_path / "uploads"
|
||||
prompt_dir = tmp_path / "prompts"
|
||||
|
||||
monkeypatch.setattr("transcription.app.get_settings", lambda: _Settings())
|
||||
settings = Settings(
|
||||
openrouter_api_key="test-key",
|
||||
environment="test",
|
||||
bootstrap_schema_on_startup=True,
|
||||
upload_dir=tmp_path / "uploads",
|
||||
prompt_dir=tmp_path / "prompts",
|
||||
)
|
||||
monkeypatch.setattr("transcription.app.get_settings", lambda: settings)
|
||||
|
||||
app = create_app()
|
||||
with TestClient(app):
|
||||
|
||||
Reference in New Issue
Block a user