38 lines
1.2 KiB
Python
38 lines
1.2 KiB
Python
import pytest
|
|
from unittest.mock import AsyncMock
|
|
from datetime import datetime
|
|
from src.processor.dto import EnrichedNewsItemDTO
|
|
from src.notifications.telegram import TelegramNotifier
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_telegram_notifier_sends_message():
|
|
# Arrange
|
|
bot_mock = AsyncMock()
|
|
chat_id = "12345"
|
|
notifier = TelegramNotifier(bot=bot_mock, chat_id=chat_id)
|
|
|
|
item = EnrichedNewsItemDTO(
|
|
title="Test Title",
|
|
url="http://example.com",
|
|
content_text="Sample content",
|
|
source="Test Source",
|
|
timestamp=datetime.now(),
|
|
relevance_score=9,
|
|
summary_ru="Тестовое саммари",
|
|
anomalies_detected=["Test Anomaly"],
|
|
category="Test Category"
|
|
)
|
|
|
|
# Act
|
|
await notifier.send_alert(item)
|
|
|
|
# Assert
|
|
bot_mock.send_message.assert_called_once()
|
|
kwargs = bot_mock.send_message.call_args.kwargs
|
|
assert kwargs["chat_id"] == chat_id
|
|
assert kwargs["parse_mode"] == "HTML"
|
|
assert "Test Title" in kwargs["text"]
|
|
assert "Category: Test Category" in kwargs["text"]
|
|
assert "9/10" in kwargs["text"]
|
|
assert "Test Anomaly" in kwargs["text"]
|