ptbtest.mockbot module

This module provides a class for a Mockbot

class ptbtest.mockbot.Mockbot(username='MockBot', **kwargs)

Bases: telegram.base.TelegramObject

The Mockbot is a fake telegram-bot that does not require a token or a connection to the telegram servers. It’s used to mimmick all methods of python-telegram-bot instance, but never contact the telegram servers. All methods as described in telegram.Bot are functional and described here are only the special methods added for testing functionality

sent_messages

[dict<sent message>] – A list of every message sent with this bot.

It will contain the data dict usually passed to the methods actually sending data to telegram. With an added field named method which will contain the method used to send this message to the server.

Examples

A call to sendMessage(1, "hello") will return the following:

{'text': 'hello', 'chat_id': 1, 'method': 'sendMessage'}

A call to editMessageText(text="test 2", inline_message_id=404, disable_web_page_preview=True):

{'inline_message_id': 404, 'text': 'test 2', 'method': 'editMessageText', 'disable_web_page_preview': True}
Parameters:username (Optional[str]) – Username for this bot. Defaults to ‘MockBot’
insertUpdate(update)

This inserts an update into the the bot’s storage. these will be retreived on a call to getUpdates which is used by the telegram.Updater. This way the updater can function without any modifications.

Parameters:update (telegram.Update) – The update to insert in the queue.
reset()

Resets the sent_messages property to an empty list.