| 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 | |