Metadata-Version: 2.1
Name: telemulator3
Version: 1.0
Summary: Mocked Telegram Bot API elements for unit tests of a bot based on the pyTelegramBotAPI library.
Home-page: https://github.com/vb64/telemulator3
Author: Vitaly Bogomolov
Author-email: mail@vitaly-bogomolov.ru
Project-URL: Bug Tracker, https://github.com/vb64/telemulator3/issues
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE

# Library telemulator3

[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/vb64/telemulator3/pep257.yml?label=Pep257&style=plastic&branch=main)](https://github.com/vb64/telemulator3/actions?query=workflow%3Apep257)
[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/vb64/telemulator3/py3.yml?label=Python%203.7-3.11&style=plastic&branch=main)](https://github.com/vb64/telemulator3/actions?query=workflow%3Apy3)
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/fe568012ee1649b89bafbb4de163a0c0)](https://app.codacy.com/gh/vb64/telemulator3/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
[![Codacy Badge](https://app.codacy.com/project/badge/Coverage/fe568012ee1649b89bafbb4de163a0c0)](https://app.codacy.com/gh/vb64/telemulator3/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_coverage)

The free, open-source telemulator3 library designed to simplify automatic testing of Telegram bots created using the [pyTelegramBotAPI library](https://github.com/eternnoir/pyTelegramBotAPI).

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

```bash
pip install telemulator3
```

## Usage

```python
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
```
