-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_api.py
37 lines (32 loc) · 1.41 KB
/
test_api.py
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
from fastapi.testclient import TestClient
from main import app
import pytest
client = TestClient(app)
def test_generate_content():
response = client.post(
"/generate_content",
json={"prompt": "Test prompt", "content_type": "general", "voice": "alloy", "high_quality": False}
)
assert response.status_code == 200
assert response.headers["Content-Type"] == "audio/mpeg"
assert "Content-Disposition" in response.headers
assert response.headers["Content-Disposition"] == "attachment; filename=generated_content.mp3"
def test_generate_content_invalid_input():
response = client.post(
"/generate_content",
json={"prompt": "", "content_type": "invalid_type", "voice": "invalid_voice", "high_quality": "not_a_boolean"}
)
assert response.status_code == 422 # Unprocessable Entity
@pytest.mark.parametrize("content_type", ["blog", "poem", "story"])
def test_generate_content_different_types(content_type):
response = client.post(
"/generate_content",
json={"prompt": f"Test {content_type}", "content_type": content_type, "voice": "alloy", "high_quality": False}
)
assert response.status_code == 200
def test_generate_content_high_quality():
response = client.post(
"/generate_content",
json={"prompt": "Test high quality", "content_type": "general", "voice": "alloy", "high_quality": True}
)
assert response.status_code == 200