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:
57
tests/test_voice_audit_repository.py
Normal file
57
tests/test_voice_audit_repository.py
Normal file
@@ -0,0 +1,57 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
|
||||
import pytest
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine
|
||||
|
||||
import app.db.models # noqa: F401
|
||||
from app.db.base import Base
|
||||
from app.db.models import VoiceConfirmationAudit
|
||||
from app.repositories.voice_audits import VoiceAuditRepository
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def db_session() -> AsyncSession:
|
||||
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)
|
||||
session = factory()
|
||||
yield session
|
||||
await session.close()
|
||||
await engine.dispose()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_save_audit_persists_fields(db_session: AsyncSession) -> None:
|
||||
repo = VoiceAuditRepository()
|
||||
opts = json.dumps([{"label": "纱布", "confidence": 0.4}], ensure_ascii=False)
|
||||
async with db_session.begin():
|
||||
await repo.save_audit(
|
||||
db_session,
|
||||
surgery_id="123456",
|
||||
confirmation_id="cid-1",
|
||||
status="recognized",
|
||||
audio_object_key="surgeries/123456/x.wav",
|
||||
audio_content_type="audio/wav",
|
||||
audio_size_bytes=100,
|
||||
audio_sha256="a" * 64,
|
||||
asr_text="纱布",
|
||||
resolved_label="纱布",
|
||||
options_snapshot_json=opts,
|
||||
error_message=None,
|
||||
)
|
||||
async with db_session.begin():
|
||||
res = await db_session.execute(select(VoiceConfirmationAudit))
|
||||
rows = res.scalars().all()
|
||||
assert len(rows) == 1
|
||||
r = rows[0]
|
||||
assert r.surgery_id == "123456"
|
||||
assert r.confirmation_id == "cid-1"
|
||||
assert r.status == "recognized"
|
||||
assert r.asr_text == "纱布"
|
||||
assert r.resolved_label == "纱布"
|
||||
assert r.options_snapshot_json == opts
|
||||
assert r.error_message is None
|
||||
Reference in New Issue
Block a user