Files
operating-room-monitor-server/backend/tests/test_rtsp_preview_api.py
Kevin e92dc1a6d9 Add HLS browser preview for live RTSP demo and real camera URLs.
MediaMTX pulls site-config RTSP into HLS with API proxying for hls.js on the demo client; simulated realtime keeps local file previews only. Also add optional JPEG frame capture and document Docker HLS host settings.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-22 14:44:28 +08:00

44 lines
1.3 KiB
Python

"""Demo RTSP 预览帧 API。"""
from __future__ import annotations
from unittest.mock import patch
import pytest
from fastapi import FastAPI
from fastapi.testclient import TestClient
from app.api import router as api_router
from app.config import Settings
@pytest.fixture
def preview_client(tmp_path) -> TestClient:
site = tmp_path / "site.json"
site.write_text(
'{"video_rtsp_urls":{"or-cam-01":"rtsp://test/c1"},'
'"voice_or_room_bindings":[]}',
encoding="utf-8",
)
app = FastAPI()
app.include_router(api_router)
with patch("app.api.settings", Settings(or_site_config_json_file=str(site))):
yield TestClient(app)
def test_rtsp_preview_frame_ok(preview_client: TestClient) -> None:
fake_jpeg = b"\xff\xd8\xff\xd9"
with patch(
"app.api.capture_rtsp_jpeg_frame",
return_value=fake_jpeg,
):
r = preview_client.get("/internal/demo/rtsp-preview/or-cam-01/frame.jpg")
assert r.status_code == 200
assert r.headers["content-type"].startswith("image/jpeg")
assert r.content == fake_jpeg
def test_rtsp_preview_unknown_camera(preview_client: TestClient) -> None:
r = preview_client.get("/internal/demo/rtsp-preview/unknown-cam/frame.jpg")
assert r.status_code == 404