feat: surgery pipeline API, video inference, voice confirm, and tests
- Add FastAPI routes for surgery start/end, results, pending confirmation (WAV upload), and health checks. - Implement RTSP/Hikvision capture, consumable classification, session manager, MinIO/Baidu voice resolution, and DB persistence. - Add documentation (client API, video backends, staging checklist) and sample camera/RTSP config. - Add pytest suite (API contract, session manager, voice, repositories, pipeline persistence) and httpx dev dependency. - Replace deprecated HTTP_422_UNPROCESSABLE_ENTITY with HTTP_422_UNPROCESSABLE_CONTENT. - Fix SurgeryPipeline DB reads to use an explicit transaction with autobegin disabled. Made-with: Cursor
This commit is contained in:
74
tests/conftest.py
Normal file
74
tests/conftest.py
Normal file
@@ -0,0 +1,74 @@
|
||||
"""Shared test fixtures (SQLite memory DB, AsyncSessionLocal monkeypatch)."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
from collections.abc import AsyncGenerator, Generator
|
||||
|
||||
import pytest
|
||||
import pytest_asyncio
|
||||
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine
|
||||
|
||||
import app.db.models # noqa: F401 # register ORM tables on Base.metadata
|
||||
from app.db.base import Base
|
||||
|
||||
|
||||
@pytest_asyncio.fixture
|
||||
async def sqlite_session_factory() -> AsyncGenerator[async_sessionmaker[AsyncSession], None]:
|
||||
"""In-memory SQLite + create_all; yields async_sessionmaker."""
|
||||
engine = create_async_engine("sqlite+aiosqlite:///:memory:")
|
||||
async with engine.begin() as conn:
|
||||
await conn.run_sync(Base.metadata.create_all)
|
||||
factory = async_sessionmaker(
|
||||
engine,
|
||||
class_=AsyncSession,
|
||||
expire_on_commit=False,
|
||||
autoflush=False,
|
||||
autobegin=False,
|
||||
)
|
||||
yield factory
|
||||
await engine.dispose()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def patched_async_session_local(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> Generator[async_sessionmaker[AsyncSession], None, None]:
|
||||
"""
|
||||
Replace AsyncSessionLocal in modules that open DB sessions, for sync tests
|
||||
(e.g. TestClient) that use asyncio.run internally.
|
||||
"""
|
||||
engine = create_async_engine("sqlite+aiosqlite:///:memory:")
|
||||
|
||||
async def _init() -> None:
|
||||
async with engine.begin() as conn:
|
||||
await conn.run_sync(Base.metadata.create_all)
|
||||
|
||||
asyncio.run(_init())
|
||||
factory = async_sessionmaker(
|
||||
engine,
|
||||
class_=AsyncSession,
|
||||
expire_on_commit=False,
|
||||
autoflush=False,
|
||||
autobegin=False,
|
||||
)
|
||||
|
||||
monkeypatch.setattr(
|
||||
"app.services.video.session_manager.AsyncSessionLocal",
|
||||
factory,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
"app.services.surgery_pipeline.AsyncSessionLocal",
|
||||
factory,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
"app.services.voice_resolution.AsyncSessionLocal",
|
||||
factory,
|
||||
)
|
||||
|
||||
yield factory
|
||||
|
||||
async def _dispose() -> None:
|
||||
await engine.dispose()
|
||||
|
||||
asyncio.run(_dispose())
|
||||
Reference in New Issue
Block a user