Files
site_aegisone/max_bot/tests/test_email_sender.py
T
angel 72b6879f4b v1.7.0: refactor max_bot to flat structure, add VCF+UserModel+NLP history context, portal pages and proxy fixes
- 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
2026-05-29 02:30:30 +03:00

58 lines
1.7 KiB
Python

import pytest
import os
from unittest.mock import patch, MagicMock
from app.email_sender import EmailSender
@pytest.fixture
def sender():
return EmailSender()
def test_send_debug_mode(sender):
with patch("os.name", "nt"):
result = sender.send("test@test.com", "Test", "Body", "from@test.com")
assert result is True
log_path = os.path.join(os.path.dirname(__file__), "..", "logs", "emails.log")
if os.path.isfile(log_path):
with open(log_path, "r", encoding="utf-8") as f:
content = f.read()
assert "test@test.com" in content
assert "Test" in content
os.remove(log_path)
def test_send_linux_mode(sender):
mock_proc = MagicMock()
mock_proc.returncode = 0
with patch("os.name", "posix"), \
patch("subprocess.run", return_value=mock_proc):
result = sender.send("test@test.com", "Test", "Body", "from@test.com")
assert result is True
def test_send_with_default_from(sender):
with patch("app.email_sender.config_reader") as mock_config:
mock_config.get_mail_from.return_value = "no-reply@aegisone.ru"
result = sender.send("test@test.com", "Test", "Body")
assert result is True
def test_send_ticket_escalation(sender):
with patch.object(sender, "send", return_value=True) as mock_send:
result = sender.send_ticket_escalation(
to="support@aegisone.ru",
subject="Test",
user_info="ID: 123",
contact="+79990000000",
inquiry="Need help",
history="Client: Hello",
)
assert result is True
mock_send.assert_called_once()
args = mock_send.call_args[0]
assert "ID: 123" in args[2]
assert "Need help" in args[2]