Files
New-planet-ai-agent/tests/test_schedule_generator.py

90 lines
2.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Тесты для генератора расписаний."""
import pytest
from unittest.mock import AsyncMock
from agents.gigachat_client import GigaChatClient
from agents.schedule_generator import ScheduleGenerator
from models.gigachat_types import GigaChatMessage, GigaChatResponse, GigaChatUsage, GigaChatChoice
from services.token_manager import TokenManager
@pytest.fixture
def mock_gigachat():
"""Фикстура для мокового GigaChat клиента."""
client = AsyncMock(spec=GigaChatClient)
return client
@pytest.fixture
def schedule_generator(mock_gigachat):
"""Фикстура для ScheduleGenerator."""
return ScheduleGenerator(gigachat=mock_gigachat)
@pytest.mark.asyncio
async def test_generate_schedule(schedule_generator, mock_gigachat):
"""Тест генерации расписания."""
mock_response_json = """
{
"title": "Расписание на 2025-12-16",
"tasks": [
{
"title": "Утренняя зарядка",
"description": "Сделай зарядку",
"duration_minutes": 15,
"category": "утренняя_рутина"
},
{
"title": "Завтрак",
"description": "Позавтракай",
"duration_minutes": 20,
"category": "утренняя_рутина"
}
]
}
"""
mock_gigachat.chat.return_value = mock_response_json
schedule = await schedule_generator.generate(
child_age=7,
preferences=["рисование", "прогулка"],
date="2025-12-16",
)
assert schedule.title == "Расписание на 2025-12-16"
assert len(schedule.tasks) == 2
assert schedule.tasks[0].title == "Утренняя зарядка"
assert schedule.tasks[0].duration_minutes == 15
@pytest.mark.asyncio
async def test_generate_schedule_with_markdown(schedule_generator, mock_gigachat):
"""Тест генерации с markdown в ответе."""
mock_response_json = """
```json
{
"title": "Тестовое расписание",
"tasks": [
{
"title": "Тест",
"duration_minutes": 10,
"category": "обучение"
}
]
}
```
"""
mock_gigachat.chat.return_value = mock_response_json
schedule = await schedule_generator.generate(
child_age=5,
preferences=[],
date="2025-12-17",
)
assert schedule.title == "Тестовое расписание"
assert len(schedule.tasks) == 1