fix: update audio devices test to mock sounddevice instead of pactl
This commit is contained in:
+9
-8
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user