Skip to main content

Mocked Telegram Bot API elements for unit tests of a bot based on the pyTelegramBotAPI library.

Project description

Library telemulator3

GitHub Workflow Status GitHub Workflow Status Codacy Badge Codacy Badge

The free, open-source telemulator3 library designed to simplify automatic testing of Telegram bots created using the pyTelegramBotAPI library.

The telemulator3 library partially emulates the Telegram Bot API in unit tests and allows you to create typical scenarios for the interaction of your bot with the Telegram Bot API.

Installation

pip install telemulator3

Usage

Create TeleBot instance and start emulate Telegram API for bot.

from telebot import TeleBot
from telemulator3 import Telemulator

bot = TeleBot('xxx-yyy-zzz', threaded=False)

@bot.message_handler(commands=['start', 'help'])
def send_welcome(message):
    bot.reply_to(message, "Howdy, how are you doing?")

telemul = Telemulator()
telemul.set_tested_bot(bot, username='my_bot', name='My Bot')

At start, there are no registered users in emulated API.

assert not telemul.api.users

Make API user, that represent our bot. It's a first registered user.

mybot = telemul.api.get_me()
assert mybot.is_bot
assert mybot.username == 'my_bot'
assert len(telemul.api.users) == 1

New user open private chat with bot and send /start command. Bot must answer as defined and his answer must be in chat history.

from telemulator3 import send_command

user = telemul.api.create_user('User')
chat = user.private()
send_command(chat, '/start', user)
assert chat.history.contain('Howdy, how are you doing?')

User create group and add bot as member.

group = user.create_group('My group')
group.add_members(user, [mybot])
assert group.history.contain('invite new members:')

And so on.

mybot.leave(group)
assert group.history.contain('My Bot (ID 1) left chat')
# group.history.dump()

Development

git clone git@github.com:vb64/telemulator3
cd telemulator3
make setup PYTHON_BIN=/path/to/python3
make tests

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

telemulator3-1.5.tar.gz (20.3 kB view details)

Uploaded Source

Built Distribution

telemulator3-1.5-py3-none-any.whl (30.5 kB view details)

Uploaded Python 3

File details

Details for the file telemulator3-1.5.tar.gz.

File metadata

  • Download URL: telemulator3-1.5.tar.gz
  • Upload date:
  • Size: 20.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for telemulator3-1.5.tar.gz
Algorithm Hash digest
SHA256 130e40a8ab1ca7f90b631659da306bb6cbfa1d682b664244621a3361dea02f43
MD5 f9e56810ba73e137e5cfa852307ca87d
BLAKE2b-256 4b28a8f0015f0692beb1e51ee067deeac93c0bc40910393dc02822ac09e28288

See more details on using hashes here.

File details

Details for the file telemulator3-1.5-py3-none-any.whl.

File metadata

  • Download URL: telemulator3-1.5-py3-none-any.whl
  • Upload date:
  • Size: 30.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for telemulator3-1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 fde2e854bc174d6408e26069010238848931c3fb272cb00312dec4ba56b106cd
MD5 f081165231d1c13bc945cddb36876eb9
BLAKE2b-256 1a5b58c2fcc235c8f3d45179bca5645682aefdf8c30693a5aa54bfc58c981957

See more details on using hashes here.

Supported by

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