46 lines
1.4 KiB
Python
46 lines
1.4 KiB
Python
import pytest
|
|
from unittest.mock import AsyncMock, MagicMock
|
|
from aiogram.types import Message
|
|
|
|
from src.bot.handlers import command_start_handler, command_help_handler, command_latest_handler
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_command_start_handler():
|
|
message = AsyncMock()
|
|
message.from_user = MagicMock()
|
|
message.from_user.full_name = "Test User"
|
|
message.answer = AsyncMock()
|
|
|
|
await command_start_handler(message)
|
|
|
|
message.answer.assert_called_once()
|
|
args, kwargs = message.answer.call_args
|
|
assert "Welcome" in args[0] or "Trend-Scout" in args[0]
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_command_help_handler():
|
|
message = AsyncMock()
|
|
message.answer = AsyncMock()
|
|
|
|
await command_help_handler(message)
|
|
|
|
message.answer.assert_called_once()
|
|
args, kwargs = message.answer.call_args
|
|
assert "/start" in args[0]
|
|
assert "/latest" in args[0]
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_command_latest_handler():
|
|
message = AsyncMock()
|
|
message.answer = AsyncMock()
|
|
|
|
await command_latest_handler(message)
|
|
|
|
message.answer.assert_called_once()
|
|
args, kwargs = message.answer.call_args
|
|
response_text = args[0]
|
|
|
|
assert "Relevance:" in response_text or "Score:" in response_text or "10" in response_text
|
|
assert "Anomalies:" in response_text or "detected" in response_text.lower()
|
|
assert "Example Domain" in response_text
|