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):
|
def test_audio_devices_returns_list(monkeypatch):
|
||||||
import subprocess
|
import sounddevice as sd
|
||||||
from main import app
|
from main import app
|
||||||
from api.router import current_user
|
from api.router import current_user
|
||||||
pactl_output = (
|
fake_devices = [
|
||||||
"1\talsa_input.pci.analog-stereo\tPipeWire\ts32le 2ch 48000Hz\tRUNNING\n"
|
{"name": "Fake Mic", "max_input_channels": 1, "max_output_channels": 0},
|
||||||
"2\talsa_output.pci.analog-stereo.monitor\tPipeWire\ts32le 2ch 48000Hz\tIDLE\n"
|
{"name": "Fake Monitor", "max_input_channels": 2, "max_output_channels": 0},
|
||||||
)
|
{"name": "Fake Speaker", "max_input_channels": 0, "max_output_channels": 2},
|
||||||
monkeypatch.setattr(subprocess, "check_output", lambda *a, **kw: pactl_output.encode())
|
]
|
||||||
|
monkeypatch.setattr(sd, "query_devices", lambda: fake_devices)
|
||||||
app.dependency_overrides[current_user] = lambda: {"username": "u", "output_dir": "/tmp", "is_admin": True}
|
app.dependency_overrides[current_user] = lambda: {"username": "u", "output_dir": "/tmp", "is_admin": True}
|
||||||
try:
|
try:
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
r = client.get("/audio/devices", headers={"Authorization": "Bearer fake"})
|
r = client.get("/audio/devices", headers={"Authorization": "Bearer fake"})
|
||||||
assert r.status_code == 200
|
assert r.status_code == 200
|
||||||
devices = r.json()
|
devices = r.json()
|
||||||
assert len(devices) == 2
|
assert len(devices) == 2 # only input devices
|
||||||
assert devices[0]["name"] == "alsa_input.pci.analog-stereo"
|
assert devices[0]["name"] == "Fake Mic"
|
||||||
finally:
|
finally:
|
||||||
app.dependency_overrides.pop(current_user, None)
|
app.dependency_overrides.pop(current_user, None)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user