feat: GET /audio/devices, POST /audio/combined — PipeWire source management

This commit is contained in:
2026-04-01 20:36:27 +02:00
parent ef4aa2a840
commit 478a1ac9d0
2 changed files with 94 additions and 0 deletions
+33
View File
@@ -97,3 +97,36 @@ def test_login_rejects_wrong_credentials():
with patch("auth.USERS_PATH", users_path):
r = client.post("/login", json={"username": "nobody", "password": "wrong"})
assert r.status_code == 401
def test_audio_devices_returns_list(monkeypatch):
import subprocess
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())
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"
finally:
app.dependency_overrides.pop(current_user, None)
def test_audio_devices_forbidden_for_non_admin():
from main import app
from api.router import current_user
app.dependency_overrides[current_user] = lambda: {"username": "u", "output_dir": "/tmp", "is_admin": False}
try:
client = TestClient(app)
r = client.get("/audio/devices", headers={"Authorization": "Bearer fake"})
assert r.status_code == 403
finally:
app.dependency_overrides.pop(current_user, None)