/
gr.ev.vl
/
TestGen
Обзор
Документация
Войти
/
gr.ev.vl
/
TestGen
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master2
backend/tests/integration/api/test_generation_api.py
108 строк
4 KB
gr.ev.vl
Initial commit
06 июн 2026, 02:41
06 июн 2026, 02:41
02fb1fb
Код
Авторство
О чём код?
""" Интеграционные тесты API генерации с GigaChat. """ import logging import pytest from httpx import AsyncClient logger = logging.getLogger("test.integration.api.generation") class TestGenerationAPI: """Тесты эндпоинтов генерации (GigaChat).""" @pytest.mark.asyncio async def test_generate_questions_requires_subtopic(self, client: AsyncClient, auth_headers): """Генерация вопросов через GigaChat.""" logger.info("Тест: генерация вопросов (GigaChat)") # Создаём курс course_resp = await client.post("/api/v1/courses", json={ "code": "GIGA01", "name": "GigaChat Test", "semester": 1, }, headers=auth_headers) course_id = course_resp.json()["id"] # Тема topic_resp = await client.post(f"/api/v1/courses/{course_id}/topics", json={ "name": "GigaChat Topic", }, headers=auth_headers) topic_id = topic_resp.json()["id"] # Подтема subtopic_resp = await client.post(f"/api/v1/topics/{topic_id}/subtopics", json={ "name": "GigaChat Subtopic", }, headers=auth_headers) subtopic_id = subtopic_resp.json()["id"] # Запуск генерации с GigaChat response = await client.post("/api/v1/generation/questions", json={ "subtopic_id": subtopic_id, "count": 3, "model": "GigaChat", # ← GigaChat модель }, headers=auth_headers) logger.info(f"Response: status={response.status_code}") assert response.status_code == 202, f"Ожидался 202, получен {response.status_code}: {response.text}" data = response.json() assert "run_id" in data assert data["status"] == "pending" logger.info(f"✓ Генерация запущена: {data['run_id']}") @pytest.mark.asyncio async def test_generate_questions_validation(self, client: AsyncClient, auth_headers): """Валидация параметров генерации.""" logger.info("Тест: валидация параметров") response = await client.post("/api/v1/generation/questions", json={ "subtopic_id": "not-a-uuid", "count": 100, "model": "GigaChat", }, headers=auth_headers) assert response.status_code == 422 logger.info("✓ 422 получен") @pytest.mark.asyncio async def test_generate_questions_without_auth(self, client: AsyncClient): """Генерация без аутентификации.""" logger.info("Тест: без аутентификации") response = await client.post("/api/v1/generation/questions", json={ "subtopic_id": "00000000-0000-0000-0000-000000000000", "count": 5, "model": "GigaChat", }) assert response.status_code == 401 logger.info("✓ 401 получен") @pytest.mark.asyncio async def test_generate_misconceptions(self, client: AsyncClient, auth_headers): """Генерация заблуждений через GigaChat.""" logger.info("Тест: генерация заблуждений (GigaChat)") # Создаём структуру course_resp = await client.post("/api/v1/courses", json={ "code": "GIGA02", "name": "Misconceptions Test", "semester": 1, }, headers=auth_headers) course_id = course_resp.json()["id"] topic_resp = await client.post(f"/api/v1/courses/{course_id}/topics", json={ "name": "Misconceptions Topic", }, headers=auth_headers) topic_id = topic_resp.json()["id"] subtopic_resp = await client.post(f"/api/v1/topics/{topic_id}/subtopics", json={ "name": "Misconceptions Subtopic", }, headers=auth_headers) subtopic_id = subtopic_resp.json()["id"] response = await client.post("/api/v1/generation/misconceptions", json={ "subtopic_id": subtopic_id, "count": 10, "model": "GigaChat", }, headers=auth_headers) assert response.status_code == 202 logger.info(f"✓ Заблуждения генерируются: {response.json()['run_id']}")