File size: 2,125 Bytes
8986c3d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from fastapi.testclient import TestClient

from app.main import app


def test_public_space_does_not_require_auth_by_default() -> None:
    with TestClient(app) as client:
        response = client.post(
            "/v1/audio/speech",
            json={"model": "bad-model", "input": "hello", "voice": "alloy"},
        )
    assert response.status_code == 400


def test_invalid_model() -> None:
    with TestClient(app) as client:
        response = client.post(
            "/v1/audio/speech",
            headers={"Authorization": "Bearer changeme"},
            json={"model": "bad-model", "input": "hello", "voice": "alloy"},
        )
    assert response.status_code == 400
    assert response.json()["error"]["param"] == "model"


def test_invalid_voice() -> None:
    with TestClient(app) as client:
        response = client.post(
            "/v1/audio/speech",
            headers={"Authorization": "Bearer changeme"},
            json={"model": "supertonic-2", "input": "hello", "voice": "bad-voice"},
        )
    assert response.status_code == 400
    assert response.json()["error"]["param"] == "voice"


def test_invalid_speed() -> None:
    with TestClient(app) as client:
        response = client.post(
            "/v1/audio/speech",
            headers={"Authorization": "Bearer changeme"},
            json={"model": "supertonic-2", "input": "hello", "voice": "alloy", "speed": 5},
        )
    assert response.status_code == 422


def test_invalid_quality() -> None:
    with TestClient(app) as client:
        response = client.post(
            "/v1/audio/speech",
            headers={"Authorization": "Bearer changeme"},
            json={"model": "supertonic-2", "input": "hello", "voice": "alloy", "quality": "ultra"},
        )
    assert response.status_code == 422


def test_invalid_kokoro_voice() -> None:
    with TestClient(app) as client:
        response = client.post(
            "/v1/audio/speech",
            headers={"Authorization": "Bearer changeme"},
            json={"model": "kokoro", "input": "hello", "voice": "atlas"},
        )
    assert response.status_code == 400