Initial commit: VoIdeaAI - voice-first AI idea assistant

This commit is contained in:
2026-05-13 12:51:42 +03:00
commit 688d043dad
421 changed files with 47915 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
"""Integration tests for VoIdeaAI."""
+80
View File
@@ -0,0 +1,80 @@
"""Integration tests for auth API endpoints.
Uses FastAPI TestClient to test the full request-response cycle.
Requires a running database or test DB configured via DATABASE_URL.
"""
from fastapi.testclient import TestClient
from app.main import app
client = TestClient(app)
class TestAuthIntegration:
def test_health(self):
resp = client.get("/health")
assert resp.status_code == 200
data = resp.json()
assert data["status"] == "healthy"
def test_register_validation(self):
resp = client.post(
"/api/v1/auth/register",
json={"email": "bad", "password": "12", "display_name": ""},
)
assert resp.status_code == 422
def test_login_invalid_credentials(self):
resp = client.post(
"/api/v1/auth/login",
json={"email": "nonexistent@test.com", "password": "wrongpass"},
)
assert resp.status_code == 401
assert resp.json()["detail"] == "Invalid credentials"
def test_register_and_login_flow(self):
import uuid
suffix = uuid.uuid4().hex[:8]
email = f"test{suffix}@example.com"
reg_resp = client.post(
"/api/v1/auth/register",
json={
"email": email,
"password": "StrongPass1",
"display_name": "Test User",
},
)
assert reg_resp.status_code == 201
tokens = reg_resp.json()
assert "access_token" in tokens
assert "refresh_token" in tokens
login_resp = client.post(
"/api/v1/auth/login",
json={"email": email, "password": "StrongPass1"},
)
assert login_resp.status_code == 200
assert "access_token" in login_resp.json()
def test_refresh_token(self):
import uuid
suffix = uuid.uuid4().hex[:8]
email = f"refresh{suffix}@example.com"
reg = client.post(
"/api/v1/auth/register",
json={"email": email, "password": "Pass1234", "display_name": "T"},
)
refresh_token = reg.json()["refresh_token"]
refresh_resp = client.post(
"/api/v1/auth/refresh",
json={"refresh_token": refresh_token},
)
assert refresh_resp.status_code == 200
new_tokens = refresh_resp.json()
assert new_tokens["refresh_token"] != refresh_token
+105
View File
@@ -0,0 +1,105 @@
"""Integration tests for voice API endpoints.
Uses FastAPI TestClient. Registers a test user and tests voice chat flow.
"""
from fastapi.testclient import TestClient
from app.main import app
client = TestClient(app)
def _register_user() -> tuple[str, str]:
import uuid
suffix = uuid.uuid4().hex[:8]
email = f"voice{suffix}@example.com"
resp = client.post(
"/api/v1/auth/register",
json={"email": email, "password": "TestPass1", "display_name": "VoiceTester"},
)
assert resp.status_code == 201
data = resp.json()
return data["access_token"], email
class TestVoiceIntegration:
def test_list_role_agents(self):
resp = client.get("/api/v1/voice/agents")
assert resp.status_code == 200
agents = resp.json()
assert len(agents) >= 13
names = [a["name"] for a in agents]
assert "Бизнес-аналитик" in names
assert "Дирижёр" not in names
def test_chat_requires_auth(self):
resp = client.post(
"/api/v1/voice/chat",
json={"text": "hello"},
)
assert resp.status_code in (401, 403)
def test_chat_with_auth(self):
token, _ = _register_user()
resp = client.post(
"/api/v1/voice/chat",
json={"text": "Придумай идею для стартапа"},
headers={"Authorization": f"Bearer {token}"},
)
assert resp.status_code == 200
data = resp.json()
assert "response" in data
assert "agent_name" in data
assert "session_id" in data
assert data["session_id"] != ""
def test_chat_with_session(self):
token, _ = _register_user()
chat1 = client.post(
"/api/v1/voice/chat",
json={"text": "Экология"},
headers={"Authorization": f"Bearer {token}"},
)
session_id = chat1.json()["session_id"]
chat2 = client.post(
"/api/v1/voice/chat",
json={"text": "А какие риски?", "session_id": session_id},
headers={"Authorization": f"Bearer {token}"},
)
assert chat2.status_code == 200
assert chat2.json()["session_id"] == session_id
def test_sessions_list(self):
token, _ = _register_user()
client.post(
"/api/v1/voice/chat",
json={"text": "Тестовая идея"},
headers={"Authorization": f"Bearer {token}"},
)
resp = client.get(
"/api/v1/voice/sessions",
headers={"Authorization": f"Bearer {token}"},
)
assert resp.status_code == 200
sessions = resp.json()
assert len(sessions) >= 1
def test_rate_interaction(self):
token, _ = _register_user()
chat = client.post(
"/api/v1/voice/chat",
json={"text": "Идея для оценки"},
headers={"Authorization": f"Bearer {token}"},
)
interaction_id = chat.json().get("interaction_id")
if not interaction_id:
return
resp = client.post(
"/api/v1/voice/rate",
json={"interaction_id": interaction_id, "rating": 5},
headers={"Authorization": f"Bearer {token}"},
)
assert resp.status_code == 200