ptbtest.mockbot module¶
This module provides a class for a Mockbot
- class ptbtest.mockbot.Mockbot(username='MockBot', **kwargs)¶
Bases:
TelegramObjectThe Mockbot is a fake telegram-bot that does not require a token or a connection to Telegram’s servers. It’s used to mimmick all methods of a
python-telegram-botinstance, without a single network connection. All methods described intelegram.Botare functional and here are described only the special methods added for testing functionality.- Parameters
username (Optional[str]) – Username for this bot. Defaults to ‘MockBot’.
- static de_json(data, bot)¶
Converts JSON data to a Telegram object.
- Parameters
data (dict[
str, …]) – The JSON data.bot (
telegram.Bot, optional) –The bot associated with this object. Defaults to
None, in which case shortcut methods will not be available.Changed in version 21.4: :paramref:`bot` is now optional and defaults to
None
- Returns
The Telegram object.
- property first_name¶
Return the bot’s first name as a string.
- get_me(**kwargs)¶
Return a bot, a
telegram.Userinstance.- Parameters
**kwargs – A dictionary with arguments for the bot
- Returns
An user or a bot with the supplied arguments.
- Return type
- get_updates(offset=None, limit=100, timeout=0, network_delay=None, read_latency=2.0, **kwargs)¶
Retrieve the updates contained in the bot’s storage.
- property id¶
Return the bot’s ID.
- insert_update(update)¶
Inserts an update into the bot’s storage. These will be retrieved on a call to
get_updateswhich is used by thetelegram.Updater. This way the updater can function without any modifications.- Parameters
update (telegram.Update) – The update to insert in the queue.
- property last_name¶
Return the bot’s last name as a string.
- property name¶
Return the username handle as a string.
- reset()¶
Resets the
sent_messagesproperty to an empty list.
- property sent_messages¶
A list of every message sent with this bot.
It contains the data dict usually passed to the methods that actually send data to Telegram, with an added field named
methodwhich will contain the method used to send this message to the server.Examples
A call to
send_message(1, "hello")will return the following
{'text': 'hello', 'chat_id': 1, 'method': 'send_message'}A call to
edit_message_text(text="test 2", inline_message_id=404, disable_web_page_preview=True):results in
{'inline_message_id': 404, 'text': 'test 2', 'method': 'edit_message_text', 'disable_web_page_preview': True}
- to_dict()¶
Gives representation of object as
dict.Changed in version 20.0:
Now includes all entries of
api_kwargs.Attributes whose values are empty sequences are no longer included.
- Parameters
recursive (
bool, optional) –If
True, will convert any TelegramObjects (if found) in the attributes to a dictionary. Else, preserves it as an object itself. Defaults toTrue.New in version 20.0.
- Returns
dict
- property updates¶
Contains a list of updates received by the bot.
- property username¶
Return the bot’s username as a string.