Phase 1-2 (PLAN_MASTERBUS_FX_RACK_VST): tests cho render_fx_chain + API fx-render; plan HOÀN THÀNH Phase 0-4
- test_native_render: render_fx_chain builtin gain e2e (bridge --render-fx) - test_plugin_api: POST /api/v1/plugins/fx-render builtin gain - PLAN_MASTERBUS_FX_RACK_VST.md: cap nhat trang thai cac phase (0-4 da implement tu cac commit truoc + phan nay)
This commit is contained in:
@@ -30,6 +30,47 @@ def get_admin_token():
|
||||
|
||||
|
||||
class TestPluginAPI:
|
||||
def test_fx_render_builtin_gain(self):
|
||||
"""POST /api/v1/plugins/fx-render với builtin gain (bridge --render-fx),
|
||||
không cần VST — output WAV mới trong PROCESSED_DIR."""
|
||||
import numpy as np
|
||||
import soundfile as sf
|
||||
from app.core import native_render
|
||||
from app.config import settings
|
||||
exe = native_render.find_bridge_exe()
|
||||
if not exe:
|
||||
pytest.skip("bridge exe missing")
|
||||
token = get_admin_token()
|
||||
if not token:
|
||||
pytest.skip("no admin token")
|
||||
h = {"Authorization": f"Bearer {token}"}
|
||||
sr = 44100
|
||||
t = np.linspace(0, 0.5, int(sr * 0.5), endpoint=False)
|
||||
data = (0.05 * np.sin(2 * np.pi * 440 * t)).astype(np.float32)
|
||||
os.makedirs(settings.PROCESSED_DIR, exist_ok=True)
|
||||
inp = os.path.join(settings.PROCESSED_DIR, "fx_api_in_test.wav")
|
||||
sf.write(inp, data, sr, subtype="FLOAT")
|
||||
try:
|
||||
resp = client.post("/api/v1/plugins/fx-render", headers=h, json={
|
||||
"input_file_id": "fx_api_in_test.wav",
|
||||
"fx_chain": [{"type": "builtin", "id": "gain", "params": {"db": 6.0}}],
|
||||
"sample_rate": sr,
|
||||
})
|
||||
assert resp.status_code == 200, resp.text[-500:]
|
||||
body = resp.json()
|
||||
assert body["success"] is True
|
||||
assert os.path.isfile(body["path"])
|
||||
d, _ = sf.read(body["path"], dtype="float32", always_2d=True)
|
||||
assert float(np.max(np.abs(d))) > 0.07 # ~2x 0.05
|
||||
finally:
|
||||
client.cookies.clear() # không làm hỏng test requires_auth kế tiếp
|
||||
for f in (inp, os.path.join(settings.PROCESSED_DIR, "fx_api_out_test.wav")):
|
||||
if os.path.exists(f):
|
||||
try:
|
||||
os.remove(f)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def test_list_plugins_requires_auth(self):
|
||||
resp = client.get("/api/v1/plugins/available")
|
||||
assert resp.status_code in (401, 403)
|
||||
|
||||
Reference in New Issue
Block a user