Files
led-controller/tests/test_audio_sse.py
Jimmy ace5770b3a refactor(api): complete fastapi migration and related features
Finish native FastAPI controllers, drop vendored microdot, and add
Wi-Fi driver runtime, beat SSE, simulated BPM, sequence playback
improvements, bridge ESP-NOW sources, UI updates, and tests.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-11 22:55:28 +12:00

35 lines
1.1 KiB
Python

"""Server-sent events for audio/beat status."""
import asyncio
import json
import pytest
@pytest.mark.asyncio
async def test_initial_sse_line_includes_status(monkeypatch):
from util import beat_status_broadcaster as bsb
bsb.configure(
loop=asyncio.get_running_loop(),
status_builder=lambda: {"bpm_simulated": True, "beat_seq": 3},
)
line = await bsb.initial_sse_line()
assert line.startswith("data: ")
payload = json.loads(line[6:])
assert payload["type"] == "status"
assert payload["status"]["beat_seq"] == 3
def test_audio_events_sse_first_chunk(server):
c = server["client"]
with c.stream("GET", "/api/audio/events") as resp:
assert resp.status_code == 200
assert "text/event-stream" in resp.headers.get("content-type", "")
chunk = next(resp.iter_bytes())
text = chunk.decode("utf-8")
assert text.startswith("data: ")
payload = json.loads(text.strip().removeprefix("data: "))
assert payload.get("type") == "status"
assert "bpm_simulated" in payload.get("status", {})