Add voice_confirmation_client (poll, TTS MP3 playback, mic WAV resolve), PyInstaller spec, start/build helpers, and API unit tests. Pending manual testing: end-to-end on OR workstations and packaged exe. Made-with: Cursor
49 lines
1.5 KiB
Python
49 lines
1.5 KiB
Python
"""Core HTTP client tests (no PySide6)."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import httpx
|
|
import pytest
|
|
|
|
from voice_confirmation_client.core.api import ConfirmationApiClient
|
|
|
|
|
|
def test_post_resolve_url_encoding(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
captured: dict = {}
|
|
|
|
def handler(request: httpx.Request) -> httpx.Response:
|
|
captured["url"] = str(request.url)
|
|
return httpx.Response(200, json={"status": "accepted"})
|
|
|
|
transport = httpx.MockTransport(handler)
|
|
client = ConfirmationApiClient("http://example.test:8080")
|
|
client._client = httpx.Client(transport=transport) # noqa: SLF001
|
|
|
|
st, body = client.post_resolve("123456", "c/id+here", b"RIFF....", "voice.wav")
|
|
assert st == 200
|
|
assert isinstance(body, dict)
|
|
assert body.get("status") == "accepted"
|
|
assert captured["url"].endswith(
|
|
"/client/surgeries/123456/pending-confirmation/c%2Fid%2Bhere/resolve"
|
|
)
|
|
|
|
client.close()
|
|
|
|
|
|
def test_parse_pending() -> None:
|
|
client = ConfirmationApiClient("http://localhost")
|
|
raw = {
|
|
"surgery_id": "123456",
|
|
"confirmation_id": "abc",
|
|
"prompt_text": "请确认",
|
|
"prompt_audio_mp3_base64": "AA",
|
|
"options": [{"label": "纱布", "confidence": 0.4}],
|
|
"model_top1_label": "x",
|
|
"model_top1_confidence": 0.41,
|
|
"created_at": "2026-01-01T00:00:00+00:00",
|
|
}
|
|
p = client.parse_pending(raw)
|
|
assert p.confirmation_id == "abc"
|
|
assert p.prompt_text == "请确认"
|
|
client.close()
|