72b6879f4b
- Refactored max_bot from nested packages to flat module structure - Q2: Extended BotUser model (patronymic, email, org, address, vcf_raw, contact_hash, phone_verified, email_verified, last_interaction, total_conversations, total_tickets) - Q2: VCF parser (FN, N, TEL, EMAIL, ORG, ADR), upsert on re-contact, NLP history context (_get_user_history_context -> YandexGPT) - Q1: Broadcast preview modal with 10s confirmation timer - Q3: CSS var(--white)->var(--bg-card), var(--text)->var(--text-primary) - Q4: bot_settings showNotification(), editable max_bot_id - Q5: Webhook secret passthrough via X-Max-Bot-Api-Secret - Masking sensitive keys, dialog_cleared handler, migrate via _add_column_if_not_exists() - Rate limit (asyncio.sleep 0.5 per 10), dead code removed, conv.intent context in contact.py - Portal pages: bot_consent, bot_kb (edit), bot_settings, bot_test, bot_tickets, portal_settings - Tests: 21/21 passing, added test_yandex_gpt.py, test_email_sender.py - Deploy: deploy_full.sh, schema.sql, seed_knowledge_base.sql
60 lines
2.0 KiB
Python
60 lines
2.0 KiB
Python
import pytest
|
|
from unittest.mock import AsyncMock, patch, MagicMock
|
|
from app.yandex_gpt import YandexGPT
|
|
|
|
|
|
@pytest.fixture
|
|
def gpt():
|
|
return YandexGPT()
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_analyze_intent_question(gpt):
|
|
gpt._load_credentials = AsyncMock(return_value=True)
|
|
|
|
with patch("app.yandex_gpt.YandexGPT._request", new=AsyncMock(return_value="question")):
|
|
result = await gpt.analyze_intent("Что вы делаете?")
|
|
assert result == "question"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_analyze_intent_ticket(gpt):
|
|
gpt._load_credentials = AsyncMock(return_value=True)
|
|
|
|
with patch("app.yandex_gpt.YandexGPT._request", new=AsyncMock(return_value="ticket")):
|
|
result = await gpt.analyze_intent("Хочу заказать аудит")
|
|
assert result == "ticket"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_analyze_intent_unknown(gpt):
|
|
gpt._load_credentials = AsyncMock(return_value=True)
|
|
|
|
with patch("app.yandex_gpt.YandexGPT._request", new=AsyncMock(return_value=None)):
|
|
result = await gpt.analyze_intent("абырвалг")
|
|
assert result == "unknown"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_analyze_intent_unavailable(gpt):
|
|
gpt._load_credentials = AsyncMock(return_value=False)
|
|
result = await gpt.analyze_intent("Что вы делаете?")
|
|
assert result == "unknown"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_generate_answer(gpt):
|
|
gpt._load_credentials = AsyncMock(return_value=True)
|
|
|
|
with patch("app.yandex_gpt.YandexGPT._request", new=AsyncMock(return_value="Мы предоставляем услуги аудита...")):
|
|
result = await gpt.generate_answer("Какие услуги?", "контекст")
|
|
assert result is not None
|
|
assert "аудита" in result
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_generate_answer_unavailable(gpt):
|
|
gpt._load_credentials = AsyncMock(return_value=False)
|
|
result = await gpt.generate_answer("Какие услуги?", "контекст")
|
|
assert result is None
|