26 lines
1.2 KiB
Python
26 lines
1.2 KiB
Python
import unittest
|
|
from fastapi import HTTPException
|
|
from services.dashscope_voice import VoiceRequest, enrollment_payload
|
|
|
|
|
|
class VoiceEnrollmentTests(unittest.TestCase):
|
|
def request(self, **changes):
|
|
return VoiceRequest.model_validate({"apiUrl": "wss://dashscope.aliyuncs.com/api-ws/v1/inference", "model": "cosyvoice-v3-plus", "action": "create_voice", "audio": "data:audio/wav;base64,UklGRg==", **changes})
|
|
|
|
def test_creation_and_region(self):
|
|
url, payload = enrollment_payload(self.request())
|
|
self.assertEqual(url, "https://dashscope.aliyuncs.com/api/v1/services/audio/tts/customization")
|
|
self.assertEqual(payload["input"]["target_model"], "cosyvoice-v3-plus")
|
|
|
|
def test_no_credentials_to_arbitrary_host(self):
|
|
with self.assertRaises(HTTPException):
|
|
enrollment_payload(self.request(apiUrl="https://evil.example"))
|
|
|
|
def test_query_needs_id(self):
|
|
with self.assertRaises(HTTPException):
|
|
enrollment_payload(self.request(action="query_voice"))
|
|
|
|
def test_invalid_audio(self):
|
|
with self.assertRaises(HTTPException):
|
|
enrollment_payload(self.request(audio="data:audio/wav;base64,???"))
|