Skip to main content

A library for testing your bots on aiogram

Project description

Aiogram Tests

aiogram_tests is a testing library for bots written on aiogram

📦 Installation

pip install aiogram-testing

The import name stays aiogram_tests:

from aiogram_tests import MockedRequester

📚 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 MockedRequester
from aiogram_tests.handler import MessageHandler
from aiogram_tests.types.dataset import MESSAGE


@pytest.mark.asyncio
async def test_echo():
    request = MockedRequester(MessageHandler(echo))
    calls = await request.query(message=MESSAGE.as_object(text="Hello, Bot!"))
    answer_message = calls.send_message.fetchone()
    assert answer_message.text == "Hello, Bot!"

▶️ More examples

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aiogram_testing-1.1.0.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aiogram_testing-1.1.0-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

File details

Details for the file aiogram_testing-1.1.0.tar.gz.

File metadata

  • Download URL: aiogram_testing-1.1.0.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for aiogram_testing-1.1.0.tar.gz
Algorithm Hash digest
SHA256 37f8d83177cb783b9b438f5d88d8004767cab4805dd0fa5b07df2ffe145883fa
MD5 ea867912aefdd890cf0c79aca1ffaf56
BLAKE2b-256 9349703a3be9c1e8ba047ac2d5a03d45ca824c57acbe02fd338b1d6850c2022c

See more details on using hashes here.

Provenance

The following attestation bundles were made for aiogram_testing-1.1.0.tar.gz:

Publisher: release.yml on k0te1ch/aiogram_tests

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file aiogram_testing-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: aiogram_testing-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for aiogram_testing-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 46b56d08a7f0890ecb5e846b63f18a607c956d6c3a3a3b5fd173c2c2db5e5780
MD5 fea7323dd89553043481f67d139fb5e8
BLAKE2b-256 8d63eb5d30dc9d0c89ca4f5f187d1820160d3e6861792f20988649fec756b9bf

See more details on using hashes here.

Provenance

The following attestation bundles were made for aiogram_testing-1.1.0-py3-none-any.whl:

Publisher: release.yml on k0te1ch/aiogram_tests

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page