2019-02-25 13:23:50 +03:00
|
|
|
from asyncio import BaseEventLoop
|
|
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
from aiogram import Bot, types
|
|
|
|
|
from . import FakeTelegram, TOKEN
|
|
|
|
|
|
|
|
|
|
pytestmark = pytest.mark.asyncio
|
|
|
|
|
|
|
|
|
|
|
2021-01-10 21:53:59 +03:00
|
|
|
@pytest.fixture()
|
2022-02-08 03:30:41 +03:00
|
|
|
async def message(bot: Bot):
|
2019-02-25 13:23:50 +03:00
|
|
|
"""
|
|
|
|
|
Message fixture
|
|
|
|
|
:param bot: Telegram bot fixture
|
|
|
|
|
:type bot: Bot
|
|
|
|
|
:param event_loop: asyncio event loop
|
|
|
|
|
:type event_loop: BaseEventLoop
|
|
|
|
|
"""
|
|
|
|
|
from .types.dataset import MESSAGE
|
|
|
|
|
msg = types.Message(**MESSAGE)
|
|
|
|
|
|
2021-01-10 21:53:59 +03:00
|
|
|
async with FakeTelegram(message_data=MESSAGE):
|
2019-02-25 13:23:50 +03:00
|
|
|
_message = await bot.send_message(chat_id=msg.chat.id, text=msg.text)
|
|
|
|
|
|
|
|
|
|
yield _message
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestMiscCases:
|
|
|
|
|
async def test_calling_bot_not_from_context(self, message):
|
|
|
|
|
"""
|
|
|
|
|
Calling any helper method without bot instance in context.
|
|
|
|
|
|
|
|
|
|
:param message: message fixture
|
|
|
|
|
:type message: types.Message
|
|
|
|
|
:return: RuntimeError with reason and help
|
|
|
|
|
"""
|
|
|
|
|
with pytest.raises(RuntimeError):
|
|
|
|
|
await message.edit_text('test_calling_bot_not_from_context')
|