A library for testing your bots on aiogram
Project description
aiogram_unittest
aiogram_unittest is a testing library for bots written on aiogram
📚 Simple examples
Simple handler test
Simple bot:
from aiogram import Bot, Dispatcher, types
from aiogram.fsm.context import FSMContext
# Please, keep your bot tokens on environments, this code only example
bot = Bot('123456789:AABBCCDDEEFFaabbccddeeff-1234567890')
dp = Dispatcher()
@dp.message()
async def echo(message: types.Message, state: FSMContext) -> None:
await message.answer(message.text)
if __name__ == '__main__':
dp.run_polling(bot)
Test cases:
import pytest
from bot import echo
from aiogram_tests import Requester
from aiogram_tests.handler import MessageHandler
from aiogram_tests.types.dataset import MESSAGE
@pytest.mark.asyncio
async def test_echo():
request = Requester(request_handler=MessageHandler(echo))
calls = await request.query(message=MESSAGE.as_object(text="Hello, Bot!"))
answer_message = calls.send_messsage.fetchone()
assert answer_message.text == "Hello, Bot!"
▶️ More examples
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
aiogram_tests-1.0.1.tar.gz
(10.3 kB
view hashes)
Built Distribution
Close
Hashes for aiogram_tests-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d4125e1c3d171e29bda9a5526430636478552e104181f893735d07b4481ae4c |
|
MD5 | 15c3bc8b3544d89c1bfb619c6b94f288 |
|
BLAKE2b-256 | 9f2ce0064d2dca078ea945287d9d3306c7a460d5c20dc9e80c12306bf2a82ffd |