A library for unittesting 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, executor
# Please, keep your bot tokens on environments, this code only example
bot = Bot('123456789:AABBCCDDEEFFaabbccddeeff-1234567890')
dp = Dispatcher(bot)
@dp.message_handler()
async def echo(message: types.Message):
await message.answer(message.text)
if __name__ == '__main__':
executor.start_polling(dp)
Test cases:
import unittest
from bot import echo
from aiogram_unittest import Requester
from aiogram_unittest.handler import MessageHandler
from aiogram_unittest.types.dataset import MESSAGE
class TestBot(unittest.IsolatedAsyncioTestCase):
async def test_echo(self):
request = Requester(request_handler=MessageHandler(echo))
calls = await request.query(message=MESSAGE.as_object(text="Hello, Bot!"))
answer_message = calls.send_messsage.fetchone()
self.assertEqual(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_unittest-0.0.1.tar.gz
(13.6 kB
view details)
Built Distribution
File details
Details for the file aiogram_unittest-0.0.1.tar.gz
.
File metadata
- Download URL: aiogram_unittest-0.0.1.tar.gz
- Upload date:
- Size: 13.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d5fa33bf406b60eab26a885e33e55fb7b5aaa64829ed4c95ee9e99a40de7c25e |
|
MD5 | 77d3c7328e59fbcf686211d42cd1f835 |
|
BLAKE2b-256 | b2c1b846ba831676ea537ffd4ee621a1de73996b146883dc7ee605936751131e |
File details
Details for the file aiogram_unittest-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: aiogram_unittest-0.0.1-py3-none-any.whl
- Upload date:
- Size: 14.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3267979b1249f6d915c2affe053aecf1b2d631ff057dce9bf0218506426f41e9 |
|
MD5 | b41a70d27b7ce234b1db7fcf121a1091 |
|
BLAKE2b-256 | eda720c49ed9a7560958c8a8384d5db448b91d1db27b57f2f999f06b713bcc23 |