From b4e7e08918948865eb3c6b6fec157c028370ca22 Mon Sep 17 00:00:00 2001 From: "thomas.kopp" Date: Thu, 2 Apr 2026 07:52:34 +0200 Subject: [PATCH] fix: update audio devices test to mock sounddevice instead of pactl --- tests/test_api.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/tests/test_api.py b/tests/test_api.py index 9097c02..fb67b44 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -100,22 +100,23 @@ def test_login_rejects_wrong_credentials(): def test_audio_devices_returns_list(monkeypatch): - import subprocess + import sounddevice as sd from main import app from api.router import current_user - pactl_output = ( - "1\talsa_input.pci.analog-stereo\tPipeWire\ts32le 2ch 48000Hz\tRUNNING\n" - "2\talsa_output.pci.analog-stereo.monitor\tPipeWire\ts32le 2ch 48000Hz\tIDLE\n" - ) - monkeypatch.setattr(subprocess, "check_output", lambda *a, **kw: pactl_output.encode()) + fake_devices = [ + {"name": "Fake Mic", "max_input_channels": 1, "max_output_channels": 0}, + {"name": "Fake Monitor", "max_input_channels": 2, "max_output_channels": 0}, + {"name": "Fake Speaker", "max_input_channels": 0, "max_output_channels": 2}, + ] + monkeypatch.setattr(sd, "query_devices", lambda: fake_devices) app.dependency_overrides[current_user] = lambda: {"username": "u", "output_dir": "/tmp", "is_admin": True} try: client = TestClient(app) r = client.get("/audio/devices", headers={"Authorization": "Bearer fake"}) assert r.status_code == 200 devices = r.json() - assert len(devices) == 2 - assert devices[0]["name"] == "alsa_input.pci.analog-stereo" + assert len(devices) == 2 # only input devices + assert devices[0]["name"] == "Fake Mic" finally: app.dependency_overrides.pop(current_user, None)