Mocked Telegram Bot API elements for unit tests of a bot based on the pyTelegramBotAPI library.
Project description
Library telemulator3
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
import unittest
from telebot import TeleBot
from telemulator3 import Telemulator, send_command
class TestCase(unittest.TestCase, Telemulator):
def setUp(self):
"""Connect your bot to test suite."""
super().setUp()
self.set_tested_bot(TeleBot('xxx-yyy-zzz', threaded=False))
# Your bot is available via api property.
# Your need to set bot name and username.
self.api.bot.username = 'my_bot'
self.api.bot.name = 'My Bot'
def test_api(self):
"""Play with API calls."""
assert not self.api.users
# create API user for our bot
bot = self.api.get_me()
assert bot.is_bot
assert bot.username == 'my_bot'
# our bot is a first registered user
assert len(self.api.users) == 1
# new user open private chat with bot
user = self.api.create_user('User')
chat = user.private()
send_command(chat, '/start', user)
assert chat.history.contain('/start')
# user create group and add bot as member
group = user.create_group('My group')
group.add_members(user, [bot])
assert group.history.contain('invite new members:')
bot.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.0.1.tar.gz
(20.2 kB
view hashes)
Built Distribution
Close
Hashes for telemulator3-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe54a79e6d5c6d9299fe148bac726b54b44cdf1475129d3e380ad04793ebca7d |
|
MD5 | e6bbf97044c5d525187ca22b28876e5d |
|
BLAKE2b-256 | a97b15c74ad525043b16d205a75428cc51496df37360b82b9a354496e9a1571e |