52 lines
1.5 KiB
Python
52 lines
1.5 KiB
Python
import pytest
|
|
from fastapi import FastAPI
|
|
from fastapi.testclient import TestClient
|
|
from pydantic import ValidationError
|
|
|
|
from app.speech import SpeechRequest, router
|
|
|
|
|
|
@pytest.fixture
|
|
def client():
|
|
app = FastAPI()
|
|
app.include_router(router)
|
|
return TestClient(app)
|
|
|
|
|
|
@pytest.mark.parametrize("bad", ["loud", "nope", "x-slower", "1.5"])
|
|
def test_rate_invalid_rejected_by_model(bad):
|
|
with pytest.raises(ValidationError):
|
|
SpeechRequest(voice="a", input="текст", rate=bad)
|
|
|
|
|
|
@pytest.mark.parametrize("bad", ["loud", "very-high"])
|
|
def test_pitch_invalid_rejected_by_model(bad):
|
|
with pytest.raises(ValidationError):
|
|
SpeechRequest(voice="a", input="текст", pitch=bad)
|
|
|
|
|
|
@pytest.mark.parametrize("good", ["x-slow", "slow", "medium", "fast", "x-fast"])
|
|
def test_rate_valid_accepted(good):
|
|
assert SpeechRequest(voice="a", input="текст", rate=good).rate == good
|
|
|
|
|
|
@pytest.mark.parametrize("good", ["x-low", "low", "medium", "high", "x-high"])
|
|
def test_pitch_valid_accepted(good):
|
|
assert SpeechRequest(voice="a", input="текст", pitch=good).pitch == good
|
|
|
|
|
|
def test_endpoint_returns_422_for_invalid_rate(client):
|
|
r = client.post(
|
|
"/v1/audio/speech",
|
|
json={"model": "UniosTTS", "voice": "baya", "input": "привет", "rate": "loud"},
|
|
)
|
|
assert r.status_code == 422
|
|
|
|
|
|
def test_endpoint_returns_422_for_invalid_pitch(client):
|
|
r = client.post(
|
|
"/v1/audio/speech",
|
|
json={"model": "UniosTTS", "voice": "baya", "input": "привет", "pitch": "loud"},
|
|
)
|
|
assert r.status_code == 422
|