Update voice libary key form
This commit is contained in:
@@ -180,11 +180,12 @@ class TestVoiceAPI:
|
||||
encoded = payload["audio_url"].split(",", 1)[1]
|
||||
assert base64.b64decode(encoded) == b"fake-mp3-bytes"
|
||||
|
||||
def test_vendor_credential_persist_and_preview_use_db_key(self, client, monkeypatch):
|
||||
"""Test vendor credential persisted in DB and used by preview endpoint"""
|
||||
def test_voice_credential_persist_and_preview_use_voice_key(self, client, monkeypatch):
|
||||
"""Test per-voice api_key/base_url persisted and used by preview endpoint"""
|
||||
from app.routers import voices as voice_router
|
||||
|
||||
captured_auth = {"value": ""}
|
||||
captured_url = {"value": ""}
|
||||
|
||||
class DummyResponse:
|
||||
status_code = 200
|
||||
@@ -207,22 +208,13 @@ class TestVoiceAPI:
|
||||
def post(self, *args, **kwargs):
|
||||
headers = kwargs.get("headers", {})
|
||||
captured_auth["value"] = headers.get("Authorization", "")
|
||||
if args:
|
||||
captured_url["value"] = args[0]
|
||||
return DummyResponse()
|
||||
|
||||
monkeypatch.delenv("SILICONFLOW_API_KEY", raising=False)
|
||||
monkeypatch.setattr(voice_router.httpx, "Client", DummyClient)
|
||||
|
||||
save_cred = client.put(
|
||||
"/api/voices/vendors/credentials/siliconflow",
|
||||
json={
|
||||
"vendor_name": "SiliconFlow",
|
||||
"api_key": "db-key-123",
|
||||
"base_url": "https://api.siliconflow.cn/v1"
|
||||
},
|
||||
)
|
||||
assert save_cred.status_code == 200
|
||||
assert save_cred.json()["vendor_key"] == "siliconflow"
|
||||
|
||||
create_resp = client.post("/api/voices", json={
|
||||
"id": "anna2",
|
||||
"name": "Anna 2",
|
||||
@@ -231,10 +223,13 @@ class TestVoiceAPI:
|
||||
"language": "zh",
|
||||
"description": "voice",
|
||||
"model": "FunAudioLLM/CosyVoice2-0.5B",
|
||||
"voice_key": "FunAudioLLM/CosyVoice2-0.5B:anna"
|
||||
"voice_key": "FunAudioLLM/CosyVoice2-0.5B:anna",
|
||||
"api_key": "voice-key-123",
|
||||
"base_url": "https://api.siliconflow.cn/v1"
|
||||
})
|
||||
assert create_resp.status_code == 200
|
||||
|
||||
preview_resp = client.post("/api/voices/anna2/preview", json={"text": "hello"})
|
||||
assert preview_resp.status_code == 200
|
||||
assert captured_auth["value"] == "Bearer db-key-123"
|
||||
assert captured_auth["value"] == "Bearer voice-key-123"
|
||||
assert captured_url["value"] == "https://api.siliconflow.cn/v1/audio/speech"
|
||||
|
||||
Reference in New Issue
Block a user