Introduce TelegramObject.set/get_bot (#2712)

This commit is contained in:
Zisis Pavloudis 2021-10-21 12:17:12 +03:00 committed by Hinrich Mahler
parent 0e60d56f53
commit 6f9e733f58
42 changed files with 669 additions and 587 deletions

View file

@ -114,5 +114,6 @@ The following wonderful people contributed directly or indirectly to this projec
- `wjt <https://github.com/wjt>`_
- `zeroone2numeral2 <https://github.com/zeroone2numeral2>`_
- `zeshuaro <https://github.com/zeshuaro>`_
- `zpavloudis <https://github.com/zpavloudis>`_
Please add yourself here alphabetically when you submit your first pull request.

View file

@ -60,7 +60,7 @@ show_error_codes = True
ignore_errors = True
# Disable strict optional for telegram objects with class methods
# We don't want to clutter the code with 'if self.bot is None: raise RuntimeError()'
# We don't want to clutter the code with 'if self.text is None: raise RuntimeError()'
[mypy-telegram._callbackquery,telegram._chat,telegram._message,telegram._user,telegram._files.*,telegram._inline.inlinequery,telegram._payment.precheckoutquery,telegram._payment.shippingquery,telegram._passport.passportdata,telegram._passport.credentials,telegram._passport.passportfile,telegram.ext.filters,telegram._chatjoinrequest]
strict_optional = False

View file

@ -151,7 +151,7 @@ class Bot(TelegramObject):
'base_url',
'base_file_url',
'private_key',
'_bot',
'_bot_user',
'_request',
'logger',
)
@ -169,7 +169,7 @@ class Bot(TelegramObject):
self.base_url = base_url + self.token
self.base_file_url = base_file_url + self.token
self._bot: Optional[User] = None
self._bot_user: Optional[User] = None
self._request = request or Request()
self.private_key = None
self.logger = logging.getLogger(__name__)
@ -326,9 +326,9 @@ class Bot(TelegramObject):
@property
def bot(self) -> User:
""":class:`telegram.User`: User instance for the bot as returned by :meth:`get_me`."""
if self._bot is None:
self._bot = self.get_me()
return self._bot
if self._bot_user is None:
self._bot_user = self.get_me()
return self._bot_user
@property
def id(self) -> int: # pylint: disable=invalid-name
@ -396,9 +396,9 @@ class Bot(TelegramObject):
"""
result = self._post('getMe', timeout=timeout, api_kwargs=api_kwargs)
self._bot = User.de_json(result, self) # type: ignore[return-value, arg-type]
self._bot_user = User.de_json(result, self) # type: ignore[return-value, arg-type]
return self._bot # type: ignore[return-value]
return self._bot_user # type: ignore[return-value]
@_log
def send_message(

View file

@ -93,7 +93,6 @@ class CallbackQuery(TelegramObject):
"""
__slots__ = (
'bot',
'game_short_name',
'message',
'chat_instance',
@ -125,7 +124,7 @@ class CallbackQuery(TelegramObject):
self.inline_message_id = inline_message_id
self.game_short_name = game_short_name
self.bot = bot
self.set_bot(bot)
self._id_attrs = (self.id,)
@ -162,7 +161,7 @@ class CallbackQuery(TelegramObject):
:obj:`bool`: On success, :obj:`True` is returned.
"""
return self.bot.answer_callback_query(
return self.get_bot().answer_callback_query(
callback_query_id=self.id,
text=text,
show_alert=show_alert,
@ -200,7 +199,7 @@ class CallbackQuery(TelegramObject):
"""
if self.inline_message_id:
return self.bot.edit_message_text(
return self.get_bot().edit_message_text(
inline_message_id=self.inline_message_id,
text=text,
parse_mode=parse_mode,
@ -250,7 +249,7 @@ class CallbackQuery(TelegramObject):
"""
if self.inline_message_id:
return self.bot.edit_message_caption(
return self.get_bot().edit_message_caption(
caption=caption,
inline_message_id=self.inline_message_id,
reply_markup=reply_markup,
@ -303,7 +302,7 @@ class CallbackQuery(TelegramObject):
"""
if self.inline_message_id:
return self.bot.edit_message_reply_markup(
return self.get_bot().edit_message_reply_markup(
reply_markup=reply_markup,
inline_message_id=self.inline_message_id,
timeout=timeout,
@ -342,7 +341,7 @@ class CallbackQuery(TelegramObject):
"""
if self.inline_message_id:
return self.bot.edit_message_media(
return self.get_bot().edit_message_media(
inline_message_id=self.inline_message_id,
media=media,
reply_markup=reply_markup,
@ -391,7 +390,7 @@ class CallbackQuery(TelegramObject):
"""
if self.inline_message_id:
return self.bot.edit_message_live_location(
return self.get_bot().edit_message_live_location(
inline_message_id=self.inline_message_id,
latitude=latitude,
longitude=longitude,
@ -444,7 +443,7 @@ class CallbackQuery(TelegramObject):
"""
if self.inline_message_id:
return self.bot.stop_message_live_location(
return self.get_bot().stop_message_live_location(
inline_message_id=self.inline_message_id,
reply_markup=reply_markup,
timeout=timeout,
@ -485,7 +484,7 @@ class CallbackQuery(TelegramObject):
"""
if self.inline_message_id:
return self.bot.set_game_score(
return self.get_bot().set_game_score(
inline_message_id=self.inline_message_id,
user_id=user_id,
score=score,
@ -528,7 +527,7 @@ class CallbackQuery(TelegramObject):
"""
if self.inline_message_id:
return self.bot.get_game_high_scores(
return self.get_bot().get_game_high_scores(
inline_message_id=self.inline_message_id,
user_id=user_id,
timeout=timeout,

View file

@ -169,7 +169,6 @@ class Chat(TelegramObject):
'id',
'type',
'last_name',
'bot',
'sticker_set_name',
'slow_mode_delay',
'location',
@ -255,7 +254,7 @@ class Chat(TelegramObject):
self.linked_chat_id = linked_chat_id
self.location = location
self.bot = bot
self.set_bot(bot)
self._id_attrs = (self.id,)
@property
@ -313,7 +312,7 @@ class Chat(TelegramObject):
:obj:`bool`: On success, :obj:`True` is returned.
"""
return self.bot.leave_chat(
return self.get_bot().leave_chat(
chat_id=self.id,
timeout=timeout,
api_kwargs=api_kwargs,
@ -336,7 +335,7 @@ class Chat(TelegramObject):
and no administrators were appointed, only the creator will be returned.
"""
return self.bot.get_chat_administrators(
return self.get_bot().get_chat_administrators(
chat_id=self.id,
timeout=timeout,
api_kwargs=api_kwargs,
@ -355,7 +354,7 @@ class Chat(TelegramObject):
Returns:
:obj:`int`
"""
return self.bot.get_chat_member_count(
return self.get_bot().get_chat_member_count(
chat_id=self.id,
timeout=timeout,
api_kwargs=api_kwargs,
@ -377,7 +376,7 @@ class Chat(TelegramObject):
:class:`telegram.ChatMember`
"""
return self.bot.get_chat_member(
return self.get_bot().get_chat_member(
chat_id=self.id,
user_id=user_id,
timeout=timeout,
@ -402,7 +401,7 @@ class Chat(TelegramObject):
Returns:
:obj:`bool`: On success, :obj:`True` is returned.
"""
return self.bot.ban_chat_member(
return self.get_bot().ban_chat_member(
chat_id=self.id,
user_id=user_id,
timeout=timeout,
@ -430,7 +429,7 @@ class Chat(TelegramObject):
:obj:`bool`: On success, :obj:`True` is returned.
"""
return self.bot.ban_chat_sender_chat(
return self.get_bot().ban_chat_sender_chat(
chat_id=self.id, sender_chat_id=sender_chat_id, timeout=timeout, api_kwargs=api_kwargs
)
@ -453,7 +452,7 @@ class Chat(TelegramObject):
:obj:`bool`: On success, :obj:`True` is returned.
"""
return self.bot.ban_chat_sender_chat(
return self.get_bot().ban_chat_sender_chat(
chat_id=chat_id, sender_chat_id=self.id, timeout=timeout, api_kwargs=api_kwargs
)
@ -476,7 +475,7 @@ class Chat(TelegramObject):
:obj:`bool`: On success, :obj:`True` is returned.
"""
return self.bot.unban_chat_sender_chat(
return self.get_bot().unban_chat_sender_chat(
chat_id=self.id, sender_chat_id=sender_chat_id, timeout=timeout, api_kwargs=api_kwargs
)
@ -499,7 +498,7 @@ class Chat(TelegramObject):
:obj:`bool`: On success, :obj:`True` is returned.
"""
return self.bot.unban_chat_sender_chat(
return self.get_bot().unban_chat_sender_chat(
chat_id=chat_id, sender_chat_id=self.id, timeout=timeout, api_kwargs=api_kwargs
)
@ -520,7 +519,7 @@ class Chat(TelegramObject):
:obj:`bool`: On success, :obj:`True` is returned.
"""
return self.bot.unban_chat_member(
return self.get_bot().unban_chat_member(
chat_id=self.id,
user_id=user_id,
timeout=timeout,
@ -558,7 +557,7 @@ class Chat(TelegramObject):
:obj:`bool`: On success, :obj:`True` is returned.
"""
return self.bot.promote_chat_member(
return self.get_bot().promote_chat_member(
chat_id=self.id,
user_id=user_id,
can_change_info=can_change_info,
@ -597,7 +596,7 @@ class Chat(TelegramObject):
:obj:`bool`: On success, :obj:`True` is returned.
"""
return self.bot.restrict_chat_member(
return self.get_bot().restrict_chat_member(
chat_id=self.id,
user_id=user_id,
permissions=permissions,
@ -623,7 +622,7 @@ class Chat(TelegramObject):
:obj:`bool`: On success, :obj:`True` is returned.
"""
return self.bot.set_chat_permissions(
return self.get_bot().set_chat_permissions(
chat_id=self.id,
permissions=permissions,
timeout=timeout,
@ -648,7 +647,7 @@ class Chat(TelegramObject):
:obj:`bool`: On success, :obj:`True` is returned.
"""
return self.bot.set_chat_administrator_custom_title(
return self.get_bot().set_chat_administrator_custom_title(
chat_id=self.id,
user_id=user_id,
custom_title=custom_title,
@ -676,7 +675,7 @@ class Chat(TelegramObject):
:obj:`bool`: On success, :obj:`True` is returned.
"""
return self.bot.pin_chat_message(
return self.get_bot().pin_chat_message(
chat_id=self.id,
message_id=message_id,
disable_notification=disable_notification,
@ -703,7 +702,7 @@ class Chat(TelegramObject):
:obj:`bool`: On success, :obj:`True` is returned.
"""
return self.bot.unpin_chat_message(
return self.get_bot().unpin_chat_message(
chat_id=self.id,
timeout=timeout,
api_kwargs=api_kwargs,
@ -728,7 +727,7 @@ class Chat(TelegramObject):
:obj:`bool`: On success, :obj:`True` is returned.
"""
return self.bot.unpin_all_chat_messages(
return self.get_bot().unpin_all_chat_messages(
chat_id=self.id,
timeout=timeout,
api_kwargs=api_kwargs,
@ -758,7 +757,7 @@ class Chat(TelegramObject):
:class:`telegram.Message`: On success, instance representing the message posted.
"""
return self.bot.send_message(
return self.get_bot().send_message(
chat_id=self.id,
text=text,
parse_mode=parse_mode,
@ -795,7 +794,7 @@ class Chat(TelegramObject):
List[:class:`telegram.Message`]: On success, instance representing the message posted.
"""
return self.bot.send_media_group(
return self.get_bot().send_media_group(
chat_id=self.id,
media=media,
disable_notification=disable_notification,
@ -822,7 +821,7 @@ class Chat(TelegramObject):
:obj:`bool`: On success, :obj:`True` is returned.
"""
return self.bot.send_chat_action(
return self.get_bot().send_chat_action(
chat_id=self.id,
action=action,
timeout=timeout,
@ -857,7 +856,7 @@ class Chat(TelegramObject):
:class:`telegram.Message`: On success, instance representing the message posted.
"""
return self.bot.send_photo(
return self.get_bot().send_photo(
chat_id=self.id,
photo=photo,
caption=caption,
@ -898,7 +897,7 @@ class Chat(TelegramObject):
:class:`telegram.Message`: On success, instance representing the message posted.
"""
return self.bot.send_contact(
return self.get_bot().send_contact(
chat_id=self.id,
phone_number=phone_number,
first_name=first_name,
@ -943,7 +942,7 @@ class Chat(TelegramObject):
:class:`telegram.Message`: On success, instance representing the message posted.
"""
return self.bot.send_audio(
return self.get_bot().send_audio(
chat_id=self.id,
audio=audio,
duration=duration,
@ -990,7 +989,7 @@ class Chat(TelegramObject):
:class:`telegram.Message`: On success, instance representing the message posted.
"""
return self.bot.send_document(
return self.get_bot().send_document(
chat_id=self.id,
document=document,
filename=filename,
@ -1029,7 +1028,7 @@ class Chat(TelegramObject):
:class:`telegram.Message`: On success, instance representing the message posted.
"""
return self.bot.send_dice(
return self.get_bot().send_dice(
chat_id=self.id,
disable_notification=disable_notification,
reply_to_message_id=reply_to_message_id,
@ -1062,7 +1061,7 @@ class Chat(TelegramObject):
:class:`telegram.Message`: On success, instance representing the message posted.
"""
return self.bot.send_game(
return self.get_bot().send_game(
chat_id=self.id,
game_short_name=game_short_name,
disable_notification=disable_notification,
@ -1123,7 +1122,7 @@ class Chat(TelegramObject):
:class:`telegram.Message`: On success, instance representing the message posted.
"""
return self.bot.send_invoice(
return self.get_bot().send_invoice(
chat_id=self.id,
title=title,
description=description,
@ -1182,7 +1181,7 @@ class Chat(TelegramObject):
:class:`telegram.Message`: On success, instance representing the message posted.
"""
return self.bot.send_location(
return self.get_bot().send_location(
chat_id=self.id,
latitude=latitude,
longitude=longitude,
@ -1229,7 +1228,7 @@ class Chat(TelegramObject):
:class:`telegram.Message`: On success, instance representing the message posted.
"""
return self.bot.send_animation(
return self.get_bot().send_animation(
chat_id=self.id,
animation=animation,
duration=duration,
@ -1270,7 +1269,7 @@ class Chat(TelegramObject):
:class:`telegram.Message`: On success, instance representing the message posted.
"""
return self.bot.send_sticker(
return self.get_bot().send_sticker(
chat_id=self.id,
sticker=sticker,
disable_notification=disable_notification,
@ -1311,7 +1310,7 @@ class Chat(TelegramObject):
:class:`telegram.Message`: On success, instance representing the message posted.
"""
return self.bot.send_venue(
return self.get_bot().send_venue(
chat_id=self.id,
latitude=latitude,
longitude=longitude,
@ -1361,7 +1360,7 @@ class Chat(TelegramObject):
:class:`telegram.Message`: On success, instance representing the message posted.
"""
return self.bot.send_video(
return self.get_bot().send_video(
chat_id=self.id,
video=video,
duration=duration,
@ -1407,7 +1406,7 @@ class Chat(TelegramObject):
:class:`telegram.Message`: On success, instance representing the message posted.
"""
return self.bot.send_video_note(
return self.get_bot().send_video_note(
chat_id=self.id,
video_note=video_note,
duration=duration,
@ -1449,7 +1448,7 @@ class Chat(TelegramObject):
:class:`telegram.Message`: On success, instance representing the message posted.
"""
return self.bot.send_voice(
return self.get_bot().send_voice(
chat_id=self.id,
voice=voice,
duration=duration,
@ -1499,7 +1498,7 @@ class Chat(TelegramObject):
:class:`telegram.Message`: On success, instance representing the message posted.
"""
return self.bot.send_poll(
return self.get_bot().send_poll(
chat_id=self.id,
question=question,
options=options,
@ -1547,7 +1546,7 @@ class Chat(TelegramObject):
:class:`telegram.Message`: On success, instance representing the message posted.
"""
return self.bot.copy_message(
return self.get_bot().copy_message(
chat_id=self.id,
from_chat_id=from_chat_id,
message_id=message_id,
@ -1588,7 +1587,7 @@ class Chat(TelegramObject):
:class:`telegram.Message`: On success, instance representing the message posted.
"""
return self.bot.copy_message(
return self.get_bot().copy_message(
from_chat_id=self.id,
chat_id=chat_id,
message_id=message_id,
@ -1622,7 +1621,7 @@ class Chat(TelegramObject):
:obj:`str`: New invite link on success.
"""
return self.bot.export_chat_invite_link(
return self.get_bot().export_chat_invite_link(
chat_id=self.id, timeout=timeout, api_kwargs=api_kwargs
)
@ -1652,7 +1651,7 @@ class Chat(TelegramObject):
:class:`telegram.ChatInviteLink`
"""
return self.bot.create_chat_invite_link(
return self.get_bot().create_chat_invite_link(
chat_id=self.id,
expire_date=expire_date,
member_limit=member_limit,
@ -1688,7 +1687,7 @@ class Chat(TelegramObject):
:class:`telegram.ChatInviteLink`
"""
return self.bot.edit_chat_invite_link(
return self.get_bot().edit_chat_invite_link(
chat_id=self.id,
invite_link=invite_link,
expire_date=expire_date,
@ -1718,7 +1717,7 @@ class Chat(TelegramObject):
:class:`telegram.ChatInviteLink`
"""
return self.bot.revoke_chat_invite_link(
return self.get_bot().revoke_chat_invite_link(
chat_id=self.id, invite_link=invite_link, timeout=timeout, api_kwargs=api_kwargs
)
@ -1741,7 +1740,7 @@ class Chat(TelegramObject):
:obj:`bool`: On success, :obj:`True` is returned.
"""
return self.bot.approve_chat_join_request(
return self.get_bot().approve_chat_join_request(
chat_id=self.id, user_id=user_id, timeout=timeout, api_kwargs=api_kwargs
)
@ -1764,6 +1763,6 @@ class Chat(TelegramObject):
:obj:`bool`: On success, :obj:`True` is returned.
"""
return self.bot.decline_chat_join_request(
return self.get_bot().decline_chat_join_request(
chat_id=self.id, user_id=user_id, timeout=timeout, api_kwargs=api_kwargs
)

View file

@ -68,7 +68,6 @@ class ChatJoinRequest(TelegramObject):
'date',
'bio',
'invite_link',
'bot',
)
def __init__(
@ -90,7 +89,7 @@ class ChatJoinRequest(TelegramObject):
self.bio = bio
self.invite_link = invite_link
self.bot = bot
self.set_bot(bot)
self._id_attrs = (self.chat, self.from_user, self.date)
@classmethod
@ -133,7 +132,7 @@ class ChatJoinRequest(TelegramObject):
:obj:`bool`: On success, :obj:`True` is returned.
"""
return self.bot.approve_chat_join_request(
return self.get_bot().approve_chat_join_request(
chat_id=self.chat.id, user_id=self.from_user.id, timeout=timeout, api_kwargs=api_kwargs
)
@ -154,6 +153,6 @@ class ChatJoinRequest(TelegramObject):
:obj:`bool`: On success, :obj:`True` is returned.
"""
return self.bot.decline_chat_join_request(
return self.get_bot().decline_chat_join_request(
chat_id=self.chat.id, user_id=self.from_user.id, timeout=timeout, api_kwargs=api_kwargs
)

View file

@ -61,7 +61,7 @@ class _BaseMedium(TelegramObject):
self.file_unique_id = str(file_unique_id)
# Optionals
self.file_size = file_size
self.bot = bot
self.set_bot(bot)
self._id_attrs = (self.file_unique_id,)
@ -79,4 +79,6 @@ class _BaseMedium(TelegramObject):
:class:`telegram.error.TelegramError`
"""
return self.bot.get_file(file_id=self.file_id, timeout=timeout, api_kwargs=api_kwargs)
return self.get_bot().get_file(
file_id=self.file_id, timeout=timeout, api_kwargs=api_kwargs
)

View file

@ -67,7 +67,6 @@ class ChatPhoto(TelegramObject):
__slots__ = (
'big_file_unique_id',
'bot',
'small_file_id',
'small_file_unique_id',
'big_file_id',
@ -87,7 +86,7 @@ class ChatPhoto(TelegramObject):
self.big_file_id = big_file_id
self.big_file_unique_id = big_file_unique_id
self.bot = bot
self.set_bot(bot)
self._id_attrs = (
self.small_file_unique_id,
@ -109,7 +108,7 @@ class ChatPhoto(TelegramObject):
:class:`telegram.error.TelegramError`
"""
return self.bot.get_file(
return self.get_bot().get_file(
file_id=self.small_file_id, timeout=timeout, api_kwargs=api_kwargs
)
@ -128,4 +127,6 @@ class ChatPhoto(TelegramObject):
:class:`telegram.error.TelegramError`
"""
return self.bot.get_file(file_id=self.big_file_id, timeout=timeout, api_kwargs=api_kwargs)
return self.get_bot().get_file(
file_id=self.big_file_id, timeout=timeout, api_kwargs=api_kwargs
)

View file

@ -69,7 +69,6 @@ class File(TelegramObject):
"""
__slots__ = (
'bot',
'file_id',
'file_size',
'file_unique_id',
@ -92,7 +91,7 @@ class File(TelegramObject):
# Optionals
self.file_size = file_size
self.file_path = file_path
self.bot = bot
self.set_bot(bot)
self._credentials: Optional['FileCredentials'] = None
self._id_attrs = (self.file_unique_id,)
@ -147,7 +146,7 @@ class File(TelegramObject):
if local_file:
buf = path.read_bytes()
else:
buf = self.bot.request.retrieve(url)
buf = self.get_bot().request.retrieve(url)
if self._credentials:
buf = decrypt(
b64decode(self._credentials.secret), b64decode(self._credentials.hash), buf
@ -168,7 +167,7 @@ class File(TelegramObject):
else:
filename = Path.cwd() / self.file_id
buf = self.bot.request.retrieve(url, timeout=timeout)
buf = self.get_bot().request.retrieve(url, timeout=timeout)
if self._credentials:
buf = decrypt(
b64decode(self._credentials.secret), b64decode(self._credentials.hash), buf
@ -201,7 +200,7 @@ class File(TelegramObject):
if is_local_file(self.file_path):
buf.extend(Path(self.file_path).read_bytes())
else:
buf.extend(self.bot.request.retrieve(self._get_encoded_url()))
buf.extend(self.get_bot().request.retrieve(self._get_encoded_url()))
return buf
def set_credentials(self, credentials: 'FileCredentials') -> None:

View file

@ -71,7 +71,7 @@ class InlineQuery(TelegramObject):
"""
__slots__ = ('bot', 'location', 'chat_type', 'id', 'offset', 'from_user', 'query')
__slots__ = ('location', 'chat_type', 'id', 'offset', 'from_user', 'query')
def __init__(
self,
@ -94,7 +94,7 @@ class InlineQuery(TelegramObject):
self.location = location
self.chat_type = chat_type
self.bot = bot
self.set_bot(bot)
self._id_attrs = (self.id,)
@classmethod
@ -150,7 +150,7 @@ class InlineQuery(TelegramObject):
"""
if current_offset and auto_pagination:
raise ValueError('current_offset and auto_pagination are mutually exclusive!')
return self.bot.answer_inline_query(
return self.get_bot().answer_inline_query(
inline_query_id=self.id,
current_offset=self.offset if auto_pagination else current_offset,
results=results,

View file

@ -367,7 +367,6 @@ class Message(TelegramObject):
'media_group_id',
'caption',
'video',
'bot',
'entities',
'via_bot',
'new_chat_members',
@ -535,7 +534,7 @@ class Message(TelegramObject):
self.voice_chat_ended = voice_chat_ended
self.voice_chat_participants_invited = voice_chat_participants_invited
self.reply_markup = reply_markup
self.bot = bot
self.set_bot(bot)
self._effective_attachment = DEFAULT_NONE
@ -719,8 +718,10 @@ class Message(TelegramObject):
else:
# Unfortunately we need some ExtBot logic here because it's hard to move shortcut
# logic into ExtBot
if hasattr(self.bot, 'defaults') and self.bot.defaults: # type: ignore[union-attr]
default_quote = self.bot.defaults.quote # type: ignore[union-attr]
if hasattr(self.get_bot(), 'defaults') and self.get_bot().defaults: # type: ignore
default_quote = (
self.get_bot().defaults.quote # type: ignore[union-attr, attr-defined]
)
else:
default_quote = None
if (default_quote is None and self.chat.type != Chat.PRIVATE) or default_quote:
@ -760,7 +761,7 @@ class Message(TelegramObject):
"""
reply_to_message_id = self._quote(quote, reply_to_message_id)
return self.bot.send_message(
return self.get_bot().send_message(
chat_id=self.chat_id,
text=text,
parse_mode=parse_mode,
@ -816,7 +817,7 @@ class Message(TelegramObject):
:class:`telegram.Message`: On success, instance representing the message posted.
"""
reply_to_message_id = self._quote(quote, reply_to_message_id)
return self.bot.send_message(
return self.get_bot().send_message(
chat_id=self.chat_id,
text=text,
parse_mode=ParseMode.MARKDOWN,
@ -868,7 +869,7 @@ class Message(TelegramObject):
:class:`telegram.Message`: On success, instance representing the message posted.
"""
reply_to_message_id = self._quote(quote, reply_to_message_id)
return self.bot.send_message(
return self.get_bot().send_message(
chat_id=self.chat_id,
text=text,
parse_mode=ParseMode.MARKDOWN_V2,
@ -920,7 +921,7 @@ class Message(TelegramObject):
:class:`telegram.Message`: On success, instance representing the message posted.
"""
reply_to_message_id = self._quote(quote, reply_to_message_id)
return self.bot.send_message(
return self.get_bot().send_message(
chat_id=self.chat_id,
text=text,
parse_mode=ParseMode.HTML,
@ -967,7 +968,7 @@ class Message(TelegramObject):
:class:`telegram.error.TelegramError`
"""
reply_to_message_id = self._quote(quote, reply_to_message_id)
return self.bot.send_media_group(
return self.get_bot().send_media_group(
chat_id=self.chat_id,
media=media,
disable_notification=disable_notification,
@ -1011,7 +1012,7 @@ class Message(TelegramObject):
"""
reply_to_message_id = self._quote(quote, reply_to_message_id)
return self.bot.send_photo(
return self.get_bot().send_photo(
chat_id=self.chat_id,
photo=photo,
caption=caption,
@ -1064,7 +1065,7 @@ class Message(TelegramObject):
"""
reply_to_message_id = self._quote(quote, reply_to_message_id)
return self.bot.send_audio(
return self.get_bot().send_audio(
chat_id=self.chat_id,
audio=audio,
duration=duration,
@ -1119,7 +1120,7 @@ class Message(TelegramObject):
"""
reply_to_message_id = self._quote(quote, reply_to_message_id)
return self.bot.send_document(
return self.get_bot().send_document(
chat_id=self.chat_id,
document=document,
filename=filename,
@ -1174,7 +1175,7 @@ class Message(TelegramObject):
"""
reply_to_message_id = self._quote(quote, reply_to_message_id)
return self.bot.send_animation(
return self.get_bot().send_animation(
chat_id=self.chat_id,
animation=animation,
duration=duration,
@ -1223,7 +1224,7 @@ class Message(TelegramObject):
"""
reply_to_message_id = self._quote(quote, reply_to_message_id)
return self.bot.send_sticker(
return self.get_bot().send_sticker(
chat_id=self.chat_id,
sticker=sticker,
disable_notification=disable_notification,
@ -1273,7 +1274,7 @@ class Message(TelegramObject):
"""
reply_to_message_id = self._quote(quote, reply_to_message_id)
return self.bot.send_video(
return self.get_bot().send_video(
chat_id=self.chat_id,
video=video,
duration=duration,
@ -1327,7 +1328,7 @@ class Message(TelegramObject):
"""
reply_to_message_id = self._quote(quote, reply_to_message_id)
return self.bot.send_video_note(
return self.get_bot().send_video_note(
chat_id=self.chat_id,
video_note=video_note,
duration=duration,
@ -1377,7 +1378,7 @@ class Message(TelegramObject):
"""
reply_to_message_id = self._quote(quote, reply_to_message_id)
return self.bot.send_voice(
return self.get_bot().send_voice(
chat_id=self.chat_id,
voice=voice,
duration=duration,
@ -1429,7 +1430,7 @@ class Message(TelegramObject):
"""
reply_to_message_id = self._quote(quote, reply_to_message_id)
return self.bot.send_location(
return self.get_bot().send_location(
chat_id=self.chat_id,
latitude=latitude,
longitude=longitude,
@ -1484,7 +1485,7 @@ class Message(TelegramObject):
"""
reply_to_message_id = self._quote(quote, reply_to_message_id)
return self.bot.send_venue(
return self.get_bot().send_venue(
chat_id=self.chat_id,
latitude=latitude,
longitude=longitude,
@ -1537,7 +1538,7 @@ class Message(TelegramObject):
"""
reply_to_message_id = self._quote(quote, reply_to_message_id)
return self.bot.send_contact(
return self.get_bot().send_contact(
chat_id=self.chat_id,
phone_number=phone_number,
first_name=first_name,
@ -1593,7 +1594,7 @@ class Message(TelegramObject):
"""
reply_to_message_id = self._quote(quote, reply_to_message_id)
return self.bot.send_poll(
return self.get_bot().send_poll(
chat_id=self.chat_id,
question=question,
options=options,
@ -1645,7 +1646,7 @@ class Message(TelegramObject):
"""
reply_to_message_id = self._quote(quote, reply_to_message_id)
return self.bot.send_dice(
return self.get_bot().send_dice(
chat_id=self.chat_id,
disable_notification=disable_notification,
reply_to_message_id=reply_to_message_id,
@ -1675,7 +1676,7 @@ class Message(TelegramObject):
:obj:`bool`: On success, :obj:`True` is returned.
"""
return self.bot.send_chat_action(
return self.get_bot().send_chat_action(
chat_id=self.chat_id,
action=action,
timeout=timeout,
@ -1713,7 +1714,7 @@ class Message(TelegramObject):
"""
reply_to_message_id = self._quote(quote, reply_to_message_id)
return self.bot.send_game(
return self.get_bot().send_game(
chat_id=self.chat_id,
game_short_name=game_short_name,
disable_notification=disable_notification,
@ -1784,7 +1785,7 @@ class Message(TelegramObject):
"""
reply_to_message_id = self._quote(quote, reply_to_message_id)
return self.bot.send_invoice(
return self.get_bot().send_invoice(
chat_id=self.chat_id,
title=title,
description=description,
@ -1846,7 +1847,7 @@ class Message(TelegramObject):
:class:`telegram.Message`: On success, instance representing the message forwarded.
"""
return self.bot.forward_message(
return self.get_bot().forward_message(
chat_id=chat_id,
from_chat_id=self.chat_id,
message_id=self.message_id,
@ -1884,7 +1885,7 @@ class Message(TelegramObject):
:class:`telegram.MessageId`: On success, returns the MessageId of the sent message.
"""
return self.bot.copy_message(
return self.get_bot().copy_message(
chat_id=chat_id,
from_chat_id=self.chat_id,
message_id=self.message_id,
@ -1939,7 +1940,7 @@ class Message(TelegramObject):
"""
reply_to_message_id = self._quote(quote, reply_to_message_id)
return self.bot.copy_message(
return self.get_bot().copy_message(
chat_id=self.chat_id,
from_chat_id=from_chat_id,
message_id=message_id,
@ -1984,7 +1985,7 @@ class Message(TelegramObject):
edited Message is returned, otherwise ``True`` is returned.
"""
return self.bot.edit_message_text(
return self.get_bot().edit_message_text(
chat_id=self.chat_id,
message_id=self.message_id,
text=text,
@ -2026,7 +2027,7 @@ class Message(TelegramObject):
edited Message is returned, otherwise ``True`` is returned.
"""
return self.bot.edit_message_caption(
return self.get_bot().edit_message_caption(
chat_id=self.chat_id,
message_id=self.message_id,
caption=caption,
@ -2065,7 +2066,7 @@ class Message(TelegramObject):
edited Message is returned, otherwise ``True`` is returned.
"""
return self.bot.edit_message_media(
return self.get_bot().edit_message_media(
media=media,
chat_id=self.chat_id,
message_id=self.message_id,
@ -2100,7 +2101,7 @@ class Message(TelegramObject):
:class:`telegram.Message`: On success, if edited message is sent by the bot, the
edited Message is returned, otherwise ``True`` is returned.
"""
return self.bot.edit_message_reply_markup(
return self.get_bot().edit_message_reply_markup(
chat_id=self.chat_id,
message_id=self.message_id,
reply_markup=reply_markup,
@ -2140,7 +2141,7 @@ class Message(TelegramObject):
:class:`telegram.Message`: On success, if edited message is sent by the bot, the
edited Message is returned, otherwise :obj:`True` is returned.
"""
return self.bot.edit_message_live_location(
return self.get_bot().edit_message_live_location(
chat_id=self.chat_id,
message_id=self.message_id,
latitude=latitude,
@ -2180,7 +2181,7 @@ class Message(TelegramObject):
:class:`telegram.Message`: On success, if edited message is sent by the bot, the
edited Message is returned, otherwise :obj:`True` is returned.
"""
return self.bot.stop_message_live_location(
return self.get_bot().stop_message_live_location(
chat_id=self.chat_id,
message_id=self.message_id,
reply_markup=reply_markup,
@ -2216,7 +2217,7 @@ class Message(TelegramObject):
:class:`telegram.Message`: On success, if edited message is sent by the bot, the
edited Message is returned, otherwise :obj:`True` is returned.
"""
return self.bot.set_game_score(
return self.get_bot().set_game_score(
chat_id=self.chat_id,
message_id=self.message_id,
user_id=user_id,
@ -2252,7 +2253,7 @@ class Message(TelegramObject):
Returns:
List[:class:`telegram.GameHighScore`]
"""
return self.bot.get_game_high_scores(
return self.get_bot().get_game_high_scores(
chat_id=self.chat_id,
message_id=self.message_id,
user_id=user_id,
@ -2279,7 +2280,7 @@ class Message(TelegramObject):
:obj:`bool`: On success, :obj:`True` is returned.
"""
return self.bot.delete_message(
return self.get_bot().delete_message(
chat_id=self.chat_id,
message_id=self.message_id,
timeout=timeout,
@ -2306,7 +2307,7 @@ class Message(TelegramObject):
returned.
"""
return self.bot.stop_poll(
return self.get_bot().stop_poll(
chat_id=self.chat_id,
message_id=self.message_id,
reply_markup=reply_markup,
@ -2333,7 +2334,7 @@ class Message(TelegramObject):
:obj:`bool`: On success, :obj:`True` is returned.
"""
return self.bot.pin_chat_message(
return self.get_bot().pin_chat_message(
chat_id=self.chat_id,
message_id=self.message_id,
disable_notification=disable_notification,
@ -2359,7 +2360,7 @@ class Message(TelegramObject):
:obj:`bool`: On success, :obj:`True` is returned.
"""
return self.bot.unpin_chat_message(
return self.get_bot().unpin_chat_message(
chat_id=self.chat_id,
message_id=self.message_id,
timeout=timeout,

View file

@ -136,7 +136,6 @@ class EncryptedCredentials(TelegramObject):
__slots__ = (
'hash',
'secret',
'bot',
'data',
'_decrypted_secret',
'_decrypted_data',
@ -150,7 +149,7 @@ class EncryptedCredentials(TelegramObject):
self._id_attrs = (self.data, self.hash, self.secret)
self.bot = bot
self.set_bot(bot)
self._decrypted_secret = None
self._decrypted_data: Optional['Credentials'] = None
@ -176,7 +175,7 @@ class EncryptedCredentials(TelegramObject):
# is the default for OAEP, the algorithm is the default for PHP which is what
# Telegram's backend servers run.
try:
self._decrypted_secret = self.bot.private_key.decrypt(
self._decrypted_secret = self.get_bot().private_key.decrypt(
b64decode(self.secret),
OAEP(mgf=MGF1(algorithm=SHA1()), algorithm=SHA1(), label=None), # skipcq
)
@ -199,7 +198,7 @@ class EncryptedCredentials(TelegramObject):
if self._decrypted_data is None:
self._decrypted_data = Credentials.de_json(
decrypt_json(self.decrypted_secret, b64decode(self.hash), b64decode(self.data)),
self.bot,
self.get_bot(),
)
return self._decrypted_data

View file

@ -55,7 +55,6 @@ class PersonalDetails(TelegramObject):
'last_name',
'country_code',
'gender',
'bot',
'middle_name_native',
'birth_date',
)
@ -87,7 +86,7 @@ class PersonalDetails(TelegramObject):
self.last_name_native = last_name_native
self.middle_name_native = middle_name_native
self.bot = bot
self.set_bot(bot)
class ResidentialAddress(TelegramObject):
@ -109,7 +108,6 @@ class ResidentialAddress(TelegramObject):
'country_code',
'street_line2',
'street_line1',
'bot',
'state',
)
@ -132,7 +130,7 @@ class ResidentialAddress(TelegramObject):
self.country_code = country_code
self.post_code = post_code
self.bot = bot
self.set_bot(bot)
class IdDocumentData(TelegramObject):
@ -144,10 +142,10 @@ class IdDocumentData(TelegramObject):
expiry_date (:obj:`str`): Optional. Date of expiry, in DD.MM.YYYY format.
"""
__slots__ = ('document_no', 'bot', 'expiry_date')
__slots__ = ('document_no', 'expiry_date')
def __init__(self, document_no: str, expiry_date: str, bot: 'Bot' = None, **_kwargs: Any):
self.document_no = document_no
self.expiry_date = expiry_date
self.bot = bot
self.set_bot(bot)

View file

@ -126,7 +126,6 @@ class EncryptedPassportElement(TelegramObject):
'email',
'hash',
'phone_number',
'bot',
'reverse_side',
'front_side',
'data',
@ -172,7 +171,7 @@ class EncryptedPassportElement(TelegramObject):
self.selfie,
)
self.bot = bot
self.set_bot(bot)
@classmethod
def de_json(cls, data: Optional[JSONDict], bot: 'Bot') -> Optional['EncryptedPassportElement']:

View file

@ -51,7 +51,7 @@ class PassportData(TelegramObject):
"""
__slots__ = ('bot', 'credentials', 'data', '_decrypted_data')
__slots__ = ('credentials', 'data', '_decrypted_data')
def __init__(
self,
@ -63,7 +63,7 @@ class PassportData(TelegramObject):
self.data = data
self.credentials = credentials
self.bot = bot
self.set_bot(bot)
self._decrypted_data: Optional[List[EncryptedPassportElement]] = None
self._id_attrs = tuple([x.type for x in data] + [credentials.hash])
@ -101,7 +101,7 @@ class PassportData(TelegramObject):
if self._decrypted_data is None:
self._decrypted_data = [
EncryptedPassportElement.de_json_decrypted(
element.to_dict(), self.bot, self.decrypted_credentials
element.to_dict(), self.get_bot(), self.decrypted_credentials
)
for element in self.data
]

View file

@ -60,7 +60,6 @@ class PassportFile(TelegramObject):
__slots__ = (
'file_date',
'bot',
'file_id',
'file_size',
'_credentials',
@ -83,7 +82,7 @@ class PassportFile(TelegramObject):
self.file_size = file_size
self.file_date = file_date
# Optionals
self.bot = bot
self.set_bot(bot)
self._credentials = credentials
self._id_attrs = (self.file_unique_id,)
@ -154,6 +153,8 @@ class PassportFile(TelegramObject):
:class:`telegram.error.TelegramError`
"""
file = self.bot.get_file(file_id=self.file_id, timeout=timeout, api_kwargs=api_kwargs)
file = self.get_bot().get_file(
file_id=self.file_id, timeout=timeout, api_kwargs=api_kwargs
)
file.set_credentials(self._credentials)
return file

View file

@ -68,7 +68,6 @@ class PreCheckoutQuery(TelegramObject):
"""
__slots__ = (
'bot',
'invoice_payload',
'shipping_option_id',
'currency',
@ -98,7 +97,7 @@ class PreCheckoutQuery(TelegramObject):
self.shipping_option_id = shipping_option_id
self.order_info = order_info
self.bot = bot
self.set_bot(bot)
self._id_attrs = (self.id,)
@ -130,7 +129,7 @@ class PreCheckoutQuery(TelegramObject):
:meth:`telegram.Bot.answer_pre_checkout_query`.
"""
return self.bot.answer_pre_checkout_query(
return self.get_bot().answer_pre_checkout_query(
pre_checkout_query_id=self.id,
ok=ok,
error_message=error_message,

View file

@ -54,7 +54,7 @@ class ShippingQuery(TelegramObject):
"""
__slots__ = ('bot', 'invoice_payload', 'shipping_address', 'id', 'from_user')
__slots__ = ('invoice_payload', 'shipping_address', 'id', 'from_user')
def __init__(
self,
@ -70,7 +70,7 @@ class ShippingQuery(TelegramObject):
self.invoice_payload = invoice_payload
self.shipping_address = shipping_address
self.bot = bot
self.set_bot(bot)
self._id_attrs = (self.id,)
@ -103,7 +103,7 @@ class ShippingQuery(TelegramObject):
:meth:`telegram.Bot.answer_shipping_query`.
"""
return self.bot.answer_shipping_query(
return self.get_bot().answer_shipping_query(
shipping_query_id=self.id,
ok=ok,
shipping_options=shipping_options,

View file

@ -41,9 +41,13 @@ class TelegramObject:
# https://www.python.org/dev/peps/pep-0526/#class-and-instance-variable-annotations
if TYPE_CHECKING:
_id_attrs: Tuple[object, ...]
_bot: Optional['Bot']
# Adding slots reduces memory usage & allows for faster attribute access.
# Only instance variables should be added to __slots__.
__slots__ = ('_id_attrs',)
__slots__ = (
'_id_attrs',
'_bot',
)
# pylint: disable=unused-argument
def __new__(cls, *args: object, **kwargs: object) -> 'TelegramObject':
@ -51,6 +55,7 @@ class TelegramObject:
# w/o calling __init__ in all of the subclasses. This is what we also do in BaseFilter.
instance = super().__new__(cls)
instance._id_attrs = ()
instance._bot = None
return instance
def __str__(self) -> str:
@ -137,6 +142,35 @@ class TelegramObject:
data['from'] = data.pop('from_user', None)
return data
def get_bot(self) -> 'Bot':
"""Returns the :class:`telegram.Bot` instance associated with this object.
.. seealso:: :meth: `set_bot`
.. versionadded: 14.0
Raises:
RuntimeError: If no :class:`telegram.Bot` instance was set for this object.
"""
if self._bot is None:
raise RuntimeError(
'This object has no bot associated with it. \
Shortcuts cannot be used.'
)
return self._bot
def set_bot(self, bot: Optional['Bot']) -> None:
"""Sets the :class:`telegram.Bot` instance associated with this object.
.. seealso:: :meth: `get_bot`
.. versionadded: 14.0
Arguments:
bot (:class:`telegram.Bot` | :obj:`None`): The bot instance.
"""
self._bot = bot
def __eq__(self, other: object) -> bool:
# pylint: disable=no-member
if isinstance(other, self.__class__):

View file

@ -105,7 +105,6 @@ class User(TelegramObject):
'can_join_groups',
'supports_inline_queries',
'id',
'bot',
'language_code',
)
@ -134,7 +133,7 @@ class User(TelegramObject):
self.can_join_groups = can_join_groups
self.can_read_all_group_messages = can_read_all_group_messages
self.supports_inline_queries = supports_inline_queries
self.bot = bot
self.set_bot(bot)
self._id_attrs = (self.id,)
@ -181,7 +180,7 @@ class User(TelegramObject):
:meth:`telegram.Bot.get_user_profile_photos`.
"""
return self.bot.get_user_profile_photos(
return self.get_bot().get_user_profile_photos(
user_id=self.id,
offset=offset,
limit=limit,
@ -268,7 +267,7 @@ class User(TelegramObject):
:obj:`bool`: On success, :obj:`True` is returned.
"""
return self.bot.pin_chat_message(
return self.get_bot().pin_chat_message(
chat_id=self.id,
message_id=message_id,
disable_notification=disable_notification,
@ -294,7 +293,7 @@ class User(TelegramObject):
:obj:`bool`: On success, :obj:`True` is returned.
"""
return self.bot.unpin_chat_message(
return self.get_bot().unpin_chat_message(
chat_id=self.id,
timeout=timeout,
api_kwargs=api_kwargs,
@ -319,7 +318,7 @@ class User(TelegramObject):
:obj:`bool`: On success, :obj:`True` is returned.
"""
return self.bot.unpin_all_chat_messages(
return self.get_bot().unpin_all_chat_messages(
chat_id=self.id,
timeout=timeout,
api_kwargs=api_kwargs,
@ -349,7 +348,7 @@ class User(TelegramObject):
:class:`telegram.Message`: On success, instance representing the message posted.
"""
return self.bot.send_message(
return self.get_bot().send_message(
chat_id=self.id,
text=text,
parse_mode=parse_mode,
@ -389,7 +388,7 @@ class User(TelegramObject):
:class:`telegram.Message`: On success, instance representing the message posted.
"""
return self.bot.send_photo(
return self.get_bot().send_photo(
chat_id=self.id,
photo=photo,
caption=caption,
@ -427,7 +426,7 @@ class User(TelegramObject):
List[:class:`telegram.Message`:] On success, instance representing the message posted.
"""
return self.bot.send_media_group(
return self.get_bot().send_media_group(
chat_id=self.id,
media=media,
disable_notification=disable_notification,
@ -467,7 +466,7 @@ class User(TelegramObject):
:class:`telegram.Message`: On success, instance representing the message posted.
"""
return self.bot.send_audio(
return self.get_bot().send_audio(
chat_id=self.id,
audio=audio,
duration=duration,
@ -503,7 +502,7 @@ class User(TelegramObject):
:obj:`True`: On success.
"""
return self.bot.send_chat_action(
return self.get_bot().send_chat_action(
chat_id=self.id,
action=action,
timeout=timeout,
@ -538,7 +537,7 @@ class User(TelegramObject):
:class:`telegram.Message`: On success, instance representing the message posted.
"""
return self.bot.send_contact(
return self.get_bot().send_contact(
chat_id=self.id,
phone_number=phone_number,
first_name=first_name,
@ -575,7 +574,7 @@ class User(TelegramObject):
:class:`telegram.Message`: On success, instance representing the message posted.
"""
return self.bot.send_dice(
return self.get_bot().send_dice(
chat_id=self.id,
disable_notification=disable_notification,
reply_to_message_id=reply_to_message_id,
@ -614,7 +613,7 @@ class User(TelegramObject):
:class:`telegram.Message`: On success, instance representing the message posted.
"""
return self.bot.send_document(
return self.get_bot().send_document(
chat_id=self.id,
document=document,
filename=filename,
@ -653,7 +652,7 @@ class User(TelegramObject):
:class:`telegram.Message`: On success, instance representing the message posted.
"""
return self.bot.send_game(
return self.get_bot().send_game(
chat_id=self.id,
game_short_name=game_short_name,
disable_notification=disable_notification,
@ -714,7 +713,7 @@ class User(TelegramObject):
:class:`telegram.Message`: On success, instance representing the message posted.
"""
return self.bot.send_invoice(
return self.get_bot().send_invoice(
chat_id=self.id,
title=title,
description=description,
@ -773,7 +772,7 @@ class User(TelegramObject):
:class:`telegram.Message`: On success, instance representing the message posted.
"""
return self.bot.send_location(
return self.get_bot().send_location(
chat_id=self.id,
latitude=latitude,
longitude=longitude,
@ -820,7 +819,7 @@ class User(TelegramObject):
:class:`telegram.Message`: On success, instance representing the message posted.
"""
return self.bot.send_animation(
return self.get_bot().send_animation(
chat_id=self.id,
animation=animation,
duration=duration,
@ -861,7 +860,7 @@ class User(TelegramObject):
:class:`telegram.Message`: On success, instance representing the message posted.
"""
return self.bot.send_sticker(
return self.get_bot().send_sticker(
chat_id=self.id,
sticker=sticker,
disable_notification=disable_notification,
@ -903,7 +902,7 @@ class User(TelegramObject):
:class:`telegram.Message`: On success, instance representing the message posted.
"""
return self.bot.send_video(
return self.get_bot().send_video(
chat_id=self.id,
video=video,
duration=duration,
@ -953,7 +952,7 @@ class User(TelegramObject):
:class:`telegram.Message`: On success, instance representing the message posted.
"""
return self.bot.send_venue(
return self.get_bot().send_venue(
chat_id=self.id,
latitude=latitude,
longitude=longitude,
@ -998,7 +997,7 @@ class User(TelegramObject):
:class:`telegram.Message`: On success, instance representing the message posted.
"""
return self.bot.send_video_note(
return self.get_bot().send_video_note(
chat_id=self.id,
video_note=video_note,
duration=duration,
@ -1040,7 +1039,7 @@ class User(TelegramObject):
:class:`telegram.Message`: On success, instance representing the message posted.
"""
return self.bot.send_voice(
return self.get_bot().send_voice(
chat_id=self.id,
voice=voice,
duration=duration,
@ -1090,7 +1089,7 @@ class User(TelegramObject):
:class:`telegram.Message`: On success, instance representing the message posted.
"""
return self.bot.send_poll(
return self.get_bot().send_poll(
chat_id=self.id,
question=question,
options=options,
@ -1138,7 +1137,7 @@ class User(TelegramObject):
:class:`telegram.Message`: On success, instance representing the message posted.
"""
return self.bot.copy_message(
return self.get_bot().copy_message(
chat_id=self.id,
from_chat_id=from_chat_id,
message_id=message_id,
@ -1179,7 +1178,7 @@ class User(TelegramObject):
:class:`telegram.Message`: On success, instance representing the message posted.
"""
return self.bot.copy_message(
return self.get_bot().copy_message(
from_chat_id=self.id,
chat_id=chat_id,
message_id=message_id,
@ -1214,7 +1213,7 @@ class User(TelegramObject):
:obj:`bool`: On success, :obj:`True` is returned.
"""
return self.bot.approve_chat_join_request(
return self.get_bot().approve_chat_join_request(
user_id=self.id, chat_id=chat_id, timeout=timeout, api_kwargs=api_kwargs
)
@ -1237,6 +1236,6 @@ class User(TelegramObject):
:obj:`bool`: On success, :obj:`True` is returned.
"""
return self.bot.decline_chat_join_request(
return self.get_bot().decline_chat_join_request(
user_id=self.id, chat_id=chat_id, timeout=timeout, api_kwargs=api_kwargs
)

View file

@ -127,16 +127,16 @@ class CommandHandler(Handler[Update, CCT]):
and message.entities[0].type == MessageEntity.BOT_COMMAND
and message.entities[0].offset == 0
and message.text
and message.bot
and message.get_bot()
):
command = message.text[1 : message.entities[0].length]
args = message.text.split()[1:]
command_parts = command.split('@')
command_parts.append(message.bot.username)
command_parts.append(message.get_bot().username)
if not (
command_parts[0].lower() in self.command
and command_parts[1].lower() == message.bot.username.lower()
and command_parts[1].lower() == message.get_bot().username.lower()
):
return None

View file

@ -313,10 +313,10 @@ class TestAnimation:
return kwargs['file_id'] == animation.file_id
assert check_shortcut_signature(Animation.get_file, Bot.get_file, ['file_id'], [])
assert check_shortcut_call(animation.get_file, animation.bot, 'get_file')
assert check_defaults_handling(animation.get_file, animation.bot)
assert check_shortcut_call(animation.get_file, animation.get_bot(), 'get_file')
assert check_defaults_handling(animation.get_file, animation.get_bot())
monkeypatch.setattr(animation.bot, 'get_file', make_assertion)
monkeypatch.setattr(animation.get_bot(), 'get_file', make_assertion)
assert animation.get_file()
def test_equality(self):

View file

@ -288,10 +288,10 @@ class TestAudio:
return kwargs['file_id'] == audio.file_id
assert check_shortcut_signature(Audio.get_file, Bot.get_file, ['file_id'], [])
assert check_shortcut_call(audio.get_file, audio.bot, 'get_file')
assert check_defaults_handling(audio.get_file, audio.bot)
assert check_shortcut_call(audio.get_file, audio.get_bot(), 'get_file')
assert check_defaults_handling(audio.get_file, audio.get_bot())
monkeypatch.setattr(audio.bot, 'get_file', make_assertion)
monkeypatch.setattr(audio._bot, 'get_file', make_assertion)
assert audio.get_file()
def test_equality(self, audio):

View file

@ -257,6 +257,8 @@ class TestBot:
'parse_data',
'get_updates',
'getUpdates',
'get_bot',
'set_bot',
]
],
)

View file

@ -35,7 +35,7 @@ def callback_query(bot, request):
)
if request.param == 'message':
cbq.message = TestCallbackQuery.message
cbq.message.bot = bot
cbq.message.set_bot(bot)
else:
cbq.inline_message_id = TestCallbackQuery.inline_message_id
return cbq
@ -121,11 +121,11 @@ class TestCallbackQuery:
CallbackQuery.answer, Bot.answer_callback_query, ['callback_query_id'], []
)
assert check_shortcut_call(
callback_query.answer, callback_query.bot, 'answer_callback_query'
callback_query.answer, callback_query.get_bot(), 'answer_callback_query'
)
assert check_defaults_handling(callback_query.answer, callback_query.bot)
assert check_defaults_handling(callback_query.answer, callback_query.get_bot())
monkeypatch.setattr(callback_query.bot, 'answer_callback_query', make_assertion)
monkeypatch.setattr(callback_query.get_bot(), 'answer_callback_query', make_assertion)
# TODO: PEP8
assert callback_query.answer()
@ -143,14 +143,14 @@ class TestCallbackQuery:
)
assert check_shortcut_call(
callback_query.edit_message_text,
callback_query.bot,
callback_query.get_bot(),
'edit_message_text',
skip_params=self.skip_params(callback_query),
shortcut_kwargs=self.shortcut_kwargs(callback_query),
)
assert check_defaults_handling(callback_query.edit_message_text, callback_query.bot)
assert check_defaults_handling(callback_query.edit_message_text, callback_query.get_bot())
monkeypatch.setattr(callback_query.bot, 'edit_message_text', make_assertion)
monkeypatch.setattr(callback_query.get_bot(), 'edit_message_text', make_assertion)
assert callback_query.edit_message_text(text='test')
assert callback_query.edit_message_text('test')
@ -168,14 +168,16 @@ class TestCallbackQuery:
)
assert check_shortcut_call(
callback_query.edit_message_caption,
callback_query.bot,
callback_query.get_bot(),
'edit_message_caption',
skip_params=self.skip_params(callback_query),
shortcut_kwargs=self.shortcut_kwargs(callback_query),
)
assert check_defaults_handling(callback_query.edit_message_caption, callback_query.bot)
assert check_defaults_handling(
callback_query.edit_message_caption, callback_query.get_bot()
)
monkeypatch.setattr(callback_query.bot, 'edit_message_caption', make_assertion)
monkeypatch.setattr(callback_query.get_bot(), 'edit_message_caption', make_assertion)
assert callback_query.edit_message_caption(caption='new caption')
assert callback_query.edit_message_caption('new caption')
@ -193,16 +195,16 @@ class TestCallbackQuery:
)
assert check_shortcut_call(
callback_query.edit_message_reply_markup,
callback_query.bot,
callback_query.get_bot(),
'edit_message_reply_markup',
skip_params=self.skip_params(callback_query),
shortcut_kwargs=self.shortcut_kwargs(callback_query),
)
assert check_defaults_handling(
callback_query.edit_message_reply_markup, callback_query.bot
callback_query.edit_message_reply_markup, callback_query.get_bot()
)
monkeypatch.setattr(callback_query.bot, 'edit_message_reply_markup', make_assertion)
monkeypatch.setattr(callback_query.get_bot(), 'edit_message_reply_markup', make_assertion)
assert callback_query.edit_message_reply_markup(reply_markup=[['1', '2']])
assert callback_query.edit_message_reply_markup([['1', '2']])
@ -220,14 +222,14 @@ class TestCallbackQuery:
)
assert check_shortcut_call(
callback_query.edit_message_media,
callback_query.bot,
callback_query.get_bot(),
'edit_message_media',
skip_params=self.skip_params(callback_query),
shortcut_kwargs=self.shortcut_kwargs(callback_query),
)
assert check_defaults_handling(callback_query.edit_message_media, callback_query.bot)
assert check_defaults_handling(callback_query.edit_message_media, callback_query.get_bot())
monkeypatch.setattr(callback_query.bot, 'edit_message_media', make_assertion)
monkeypatch.setattr(callback_query.get_bot(), 'edit_message_media', make_assertion)
assert callback_query.edit_message_media(media=[['1', '2']])
assert callback_query.edit_message_media([['1', '2']])
@ -246,16 +248,16 @@ class TestCallbackQuery:
)
assert check_shortcut_call(
callback_query.edit_message_live_location,
callback_query.bot,
callback_query.get_bot(),
'edit_message_live_location',
skip_params=self.skip_params(callback_query),
shortcut_kwargs=self.shortcut_kwargs(callback_query),
)
assert check_defaults_handling(
callback_query.edit_message_live_location, callback_query.bot
callback_query.edit_message_live_location, callback_query.get_bot()
)
monkeypatch.setattr(callback_query.bot, 'edit_message_live_location', make_assertion)
monkeypatch.setattr(callback_query.get_bot(), 'edit_message_live_location', make_assertion)
assert callback_query.edit_message_live_location(latitude=1, longitude=2)
assert callback_query.edit_message_live_location(1, 2)
@ -272,16 +274,16 @@ class TestCallbackQuery:
)
assert check_shortcut_call(
callback_query.stop_message_live_location,
callback_query.bot,
callback_query.get_bot(),
'stop_message_live_location',
skip_params=self.skip_params(callback_query),
shortcut_kwargs=self.shortcut_kwargs(callback_query),
)
assert check_defaults_handling(
callback_query.stop_message_live_location, callback_query.bot
callback_query.stop_message_live_location, callback_query.get_bot()
)
monkeypatch.setattr(callback_query.bot, 'stop_message_live_location', make_assertion)
monkeypatch.setattr(callback_query.get_bot(), 'stop_message_live_location', make_assertion)
assert callback_query.stop_message_live_location()
def test_set_game_score(self, monkeypatch, callback_query):
@ -299,14 +301,14 @@ class TestCallbackQuery:
)
assert check_shortcut_call(
callback_query.set_game_score,
callback_query.bot,
callback_query.get_bot(),
'set_game_score',
skip_params=self.skip_params(callback_query),
shortcut_kwargs=self.shortcut_kwargs(callback_query),
)
assert check_defaults_handling(callback_query.set_game_score, callback_query.bot)
assert check_defaults_handling(callback_query.set_game_score, callback_query.get_bot())
monkeypatch.setattr(callback_query.bot, 'set_game_score', make_assertion)
monkeypatch.setattr(callback_query.get_bot(), 'set_game_score', make_assertion)
assert callback_query.set_game_score(user_id=1, score=2)
assert callback_query.set_game_score(1, 2)
@ -324,14 +326,16 @@ class TestCallbackQuery:
)
assert check_shortcut_call(
callback_query.get_game_high_scores,
callback_query.bot,
callback_query.get_bot(),
'get_game_high_scores',
skip_params=self.skip_params(callback_query),
shortcut_kwargs=self.shortcut_kwargs(callback_query),
)
assert check_defaults_handling(callback_query.get_game_high_scores, callback_query.bot)
assert check_defaults_handling(
callback_query.get_game_high_scores, callback_query.get_bot()
)
monkeypatch.setattr(callback_query.bot, 'get_game_high_scores', make_assertion)
monkeypatch.setattr(callback_query.get_bot(), 'get_game_high_scores', make_assertion)
assert callback_query.get_game_high_scores(user_id=1)
assert callback_query.get_game_high_scores(1)
@ -351,11 +355,11 @@ class TestCallbackQuery:
[],
)
assert check_shortcut_call(
callback_query.delete_message, callback_query.bot, 'delete_message'
callback_query.delete_message, callback_query.get_bot(), 'delete_message'
)
assert check_defaults_handling(callback_query.delete_message, callback_query.bot)
assert check_defaults_handling(callback_query.delete_message, callback_query.get_bot())
monkeypatch.setattr(callback_query.bot, 'delete_message', make_assertion)
monkeypatch.setattr(callback_query.get_bot(), 'delete_message', make_assertion)
assert callback_query.delete_message()
def test_pin_message(self, monkeypatch, callback_query):
@ -372,11 +376,11 @@ class TestCallbackQuery:
[],
)
assert check_shortcut_call(
callback_query.pin_message, callback_query.bot, 'pin_chat_message'
callback_query.pin_message, callback_query.get_bot(), 'pin_chat_message'
)
assert check_defaults_handling(callback_query.pin_message, callback_query.bot)
assert check_defaults_handling(callback_query.pin_message, callback_query.get_bot())
monkeypatch.setattr(callback_query.bot, 'pin_chat_message', make_assertion)
monkeypatch.setattr(callback_query.get_bot(), 'pin_chat_message', make_assertion)
assert callback_query.pin_message()
def test_unpin_message(self, monkeypatch, callback_query):
@ -394,13 +398,13 @@ class TestCallbackQuery:
)
assert check_shortcut_call(
callback_query.unpin_message,
callback_query.bot,
callback_query.get_bot(),
'unpin_chat_message',
shortcut_kwargs=['message_id', 'chat_id'],
)
assert check_defaults_handling(callback_query.unpin_message, callback_query.bot)
assert check_defaults_handling(callback_query.unpin_message, callback_query.get_bot())
monkeypatch.setattr(callback_query.bot, 'unpin_chat_message', make_assertion)
monkeypatch.setattr(callback_query.get_bot(), 'unpin_chat_message', make_assertion)
assert callback_query.unpin_message()
def test_copy_message(self, monkeypatch, callback_query):
@ -419,10 +423,12 @@ class TestCallbackQuery:
['message_id', 'from_chat_id'],
[],
)
assert check_shortcut_call(callback_query.copy_message, callback_query.bot, 'copy_message')
assert check_defaults_handling(callback_query.copy_message, callback_query.bot)
assert check_shortcut_call(
callback_query.copy_message, callback_query.get_bot(), 'copy_message'
)
assert check_defaults_handling(callback_query.copy_message, callback_query.get_bot())
monkeypatch.setattr(callback_query.bot, 'copy_message', make_assertion)
monkeypatch.setattr(callback_query.get_bot(), 'copy_message', make_assertion)
assert callback_query.copy_message(1)
def test_equality(self):

View file

@ -152,10 +152,10 @@ class TestChat:
return id_ and action
assert check_shortcut_signature(chat.send_action, Bot.send_chat_action, ['chat_id'], [])
assert check_shortcut_call(chat.send_action, chat.bot, 'send_chat_action')
assert check_defaults_handling(chat.send_action, chat.bot)
assert check_shortcut_call(chat.send_action, chat.get_bot(), 'send_chat_action')
assert check_defaults_handling(chat.send_action, chat.get_bot())
monkeypatch.setattr(chat.bot, 'send_chat_action', make_assertion)
monkeypatch.setattr(chat.get_bot(), 'send_chat_action', make_assertion)
assert chat.send_action(action=ChatAction.TYPING)
assert chat.send_action(action=ChatAction.TYPING)
@ -164,10 +164,10 @@ class TestChat:
return kwargs['chat_id'] == chat.id
assert check_shortcut_signature(Chat.leave, Bot.leave_chat, ['chat_id'], [])
assert check_shortcut_call(chat.leave, chat.bot, 'leave_chat')
assert check_defaults_handling(chat.leave, chat.bot)
assert check_shortcut_call(chat.leave, chat.get_bot(), 'leave_chat')
assert check_defaults_handling(chat.leave, chat.get_bot())
monkeypatch.setattr(chat.bot, 'leave_chat', make_assertion)
monkeypatch.setattr(chat.get_bot(), 'leave_chat', make_assertion)
assert chat.leave()
def test_get_administrators(self, monkeypatch, chat):
@ -177,10 +177,12 @@ class TestChat:
assert check_shortcut_signature(
Chat.get_administrators, Bot.get_chat_administrators, ['chat_id'], []
)
assert check_shortcut_call(chat.get_administrators, chat.bot, 'get_chat_administrators')
assert check_defaults_handling(chat.get_administrators, chat.bot)
assert check_shortcut_call(
chat.get_administrators, chat.get_bot(), 'get_chat_administrators'
)
assert check_defaults_handling(chat.get_administrators, chat.get_bot())
monkeypatch.setattr(chat.bot, 'get_chat_administrators', make_assertion)
monkeypatch.setattr(chat.get_bot(), 'get_chat_administrators', make_assertion)
assert chat.get_administrators()
def test_get_member_count(self, monkeypatch, chat):
@ -190,10 +192,10 @@ class TestChat:
assert check_shortcut_signature(
Chat.get_member_count, Bot.get_chat_member_count, ['chat_id'], []
)
assert check_shortcut_call(chat.get_member_count, chat.bot, 'get_chat_member_count')
assert check_defaults_handling(chat.get_member_count, chat.bot)
assert check_shortcut_call(chat.get_member_count, chat.get_bot(), 'get_chat_member_count')
assert check_defaults_handling(chat.get_member_count, chat.get_bot())
monkeypatch.setattr(chat.bot, 'get_chat_member_count', make_assertion)
monkeypatch.setattr(chat.get_bot(), 'get_chat_member_count', make_assertion)
assert chat.get_member_count()
def test_get_member(self, monkeypatch, chat):
@ -203,10 +205,10 @@ class TestChat:
return chat_id and user_id
assert check_shortcut_signature(Chat.get_member, Bot.get_chat_member, ['chat_id'], [])
assert check_shortcut_call(chat.get_member, chat.bot, 'get_chat_member')
assert check_defaults_handling(chat.get_member, chat.bot)
assert check_shortcut_call(chat.get_member, chat.get_bot(), 'get_chat_member')
assert check_defaults_handling(chat.get_member, chat.get_bot())
monkeypatch.setattr(chat.bot, 'get_chat_member', make_assertion)
monkeypatch.setattr(chat.get_bot(), 'get_chat_member', make_assertion)
assert chat.get_member(user_id=42)
def test_ban_member(self, monkeypatch, chat):
@ -217,10 +219,10 @@ class TestChat:
return chat_id and user_id and until
assert check_shortcut_signature(Chat.ban_member, Bot.ban_chat_member, ['chat_id'], [])
assert check_shortcut_call(chat.ban_member, chat.bot, 'ban_chat_member')
assert check_defaults_handling(chat.ban_member, chat.bot)
assert check_shortcut_call(chat.ban_member, chat.get_bot(), 'ban_chat_member')
assert check_defaults_handling(chat.ban_member, chat.get_bot())
monkeypatch.setattr(chat.bot, 'ban_chat_member', make_assertion)
monkeypatch.setattr(chat.get_bot(), 'ban_chat_member', make_assertion)
assert chat.ban_member(user_id=42, until_date=43)
def test_ban_sender_chat(self, monkeypatch, chat):
@ -232,10 +234,10 @@ class TestChat:
assert check_shortcut_signature(
Chat.ban_sender_chat, Bot.ban_chat_sender_chat, ['chat_id'], []
)
assert check_shortcut_call(chat.ban_sender_chat, chat.bot, 'ban_chat_sender_chat')
assert check_defaults_handling(chat.ban_sender_chat, chat.bot)
assert check_shortcut_call(chat.ban_sender_chat, chat.get_bot(), 'ban_chat_sender_chat')
assert check_defaults_handling(chat.ban_sender_chat, chat.get_bot())
monkeypatch.setattr(chat.bot, 'ban_chat_sender_chat', make_assertion)
monkeypatch.setattr(chat.get_bot(), 'ban_chat_sender_chat', make_assertion)
assert chat.ban_sender_chat(42)
def test_ban_chat(self, monkeypatch, chat):
@ -247,10 +249,10 @@ class TestChat:
assert check_shortcut_signature(
Chat.ban_chat, Bot.ban_chat_sender_chat, ['sender_chat_id'], []
)
assert check_shortcut_call(chat.ban_chat, chat.bot, 'ban_chat_sender_chat')
assert check_defaults_handling(chat.ban_chat, chat.bot)
assert check_shortcut_call(chat.ban_chat, chat.get_bot(), 'ban_chat_sender_chat')
assert check_defaults_handling(chat.ban_chat, chat.get_bot())
monkeypatch.setattr(chat.bot, 'ban_chat_sender_chat', make_assertion)
monkeypatch.setattr(chat.get_bot(), 'ban_chat_sender_chat', make_assertion)
assert chat.ban_chat(42)
@pytest.mark.parametrize('only_if_banned', [True, False, None])
@ -262,10 +264,10 @@ class TestChat:
return chat_id and user_id and o_i_b
assert check_shortcut_signature(Chat.unban_member, Bot.unban_chat_member, ['chat_id'], [])
assert check_shortcut_call(chat.unban_member, chat.bot, 'unban_chat_member')
assert check_defaults_handling(chat.unban_member, chat.bot)
assert check_shortcut_call(chat.unban_member, chat.get_bot(), 'unban_chat_member')
assert check_defaults_handling(chat.unban_member, chat.get_bot())
monkeypatch.setattr(chat.bot, 'unban_chat_member', make_assertion)
monkeypatch.setattr(chat.get_bot(), 'unban_chat_member', make_assertion)
assert chat.unban_member(user_id=42, only_if_banned=only_if_banned)
def test_unban_sender_chat(self, monkeypatch, chat):
@ -277,10 +279,12 @@ class TestChat:
assert check_shortcut_signature(
Chat.unban_sender_chat, Bot.unban_chat_sender_chat, ['chat_id'], []
)
assert check_shortcut_call(chat.unban_sender_chat, chat.bot, 'unban_chat_sender_chat')
assert check_defaults_handling(chat.unban_sender_chat, chat.bot)
assert check_shortcut_call(
chat.unban_sender_chat, chat.get_bot(), 'unban_chat_sender_chat'
)
assert check_defaults_handling(chat.unban_sender_chat, chat.get_bot())
monkeypatch.setattr(chat.bot, 'unban_chat_sender_chat', make_assertion)
monkeypatch.setattr(chat.get_bot(), 'unban_chat_sender_chat', make_assertion)
assert chat.unban_sender_chat(42)
def test_unban_chat(self, monkeypatch, chat):
@ -292,10 +296,10 @@ class TestChat:
assert check_shortcut_signature(
Chat.unban_chat, Bot.ban_chat_sender_chat, ['sender_chat_id'], []
)
assert check_shortcut_call(chat.unban_chat, chat.bot, 'unban_chat_sender_chat')
assert check_defaults_handling(chat.unban_chat, chat.bot)
assert check_shortcut_call(chat.unban_chat, chat.get_bot(), 'unban_chat_sender_chat')
assert check_defaults_handling(chat.unban_chat, chat.get_bot())
monkeypatch.setattr(chat.bot, 'unban_chat_sender_chat', make_assertion)
monkeypatch.setattr(chat.get_bot(), 'unban_chat_sender_chat', make_assertion)
assert chat.unban_chat(42)
@pytest.mark.parametrize('is_anonymous', [True, False, None])
@ -309,10 +313,10 @@ class TestChat:
assert check_shortcut_signature(
Chat.promote_member, Bot.promote_chat_member, ['chat_id'], []
)
assert check_shortcut_call(chat.promote_member, chat.bot, 'promote_chat_member')
assert check_defaults_handling(chat.promote_member, chat.bot)
assert check_shortcut_call(chat.promote_member, chat.get_bot(), 'promote_chat_member')
assert check_defaults_handling(chat.promote_member, chat.get_bot())
monkeypatch.setattr(chat.bot, 'promote_chat_member', make_assertion)
monkeypatch.setattr(chat.get_bot(), 'promote_chat_member', make_assertion)
assert chat.promote_member(user_id=42, is_anonymous=is_anonymous)
def test_restrict_member(self, monkeypatch, chat):
@ -327,10 +331,10 @@ class TestChat:
assert check_shortcut_signature(
Chat.restrict_member, Bot.restrict_chat_member, ['chat_id'], []
)
assert check_shortcut_call(chat.restrict_member, chat.bot, 'restrict_chat_member')
assert check_defaults_handling(chat.restrict_member, chat.bot)
assert check_shortcut_call(chat.restrict_member, chat.get_bot(), 'restrict_chat_member')
assert check_defaults_handling(chat.restrict_member, chat.get_bot())
monkeypatch.setattr(chat.bot, 'restrict_chat_member', make_assertion)
monkeypatch.setattr(chat.get_bot(), 'restrict_chat_member', make_assertion)
assert chat.restrict_member(user_id=42, permissions=permissions)
def test_set_permissions(self, monkeypatch, chat):
@ -342,10 +346,10 @@ class TestChat:
assert check_shortcut_signature(
Chat.set_permissions, Bot.set_chat_permissions, ['chat_id'], []
)
assert check_shortcut_call(chat.set_permissions, chat.bot, 'set_chat_permissions')
assert check_defaults_handling(chat.set_permissions, chat.bot)
assert check_shortcut_call(chat.set_permissions, chat.get_bot(), 'set_chat_permissions')
assert check_defaults_handling(chat.set_permissions, chat.get_bot())
monkeypatch.setattr(chat.bot, 'set_chat_permissions', make_assertion)
monkeypatch.setattr(chat.get_bot(), 'set_chat_permissions', make_assertion)
assert chat.set_permissions(permissions=self.permissions)
def test_set_administrator_custom_title(self, monkeypatch, chat):
@ -363,10 +367,10 @@ class TestChat:
return kwargs['chat_id'] == chat.id and kwargs['message_id'] == 42
assert check_shortcut_signature(Chat.pin_message, Bot.pin_chat_message, ['chat_id'], [])
assert check_shortcut_call(chat.pin_message, chat.bot, 'pin_chat_message')
assert check_defaults_handling(chat.pin_message, chat.bot)
assert check_shortcut_call(chat.pin_message, chat.get_bot(), 'pin_chat_message')
assert check_defaults_handling(chat.pin_message, chat.get_bot())
monkeypatch.setattr(chat.bot, 'pin_chat_message', make_assertion)
monkeypatch.setattr(chat.get_bot(), 'pin_chat_message', make_assertion)
assert chat.pin_message(message_id=42)
def test_unpin_message(self, monkeypatch, chat):
@ -376,10 +380,10 @@ class TestChat:
assert check_shortcut_signature(
Chat.unpin_message, Bot.unpin_chat_message, ['chat_id'], []
)
assert check_shortcut_call(chat.unpin_message, chat.bot, 'unpin_chat_message')
assert check_defaults_handling(chat.unpin_message, chat.bot)
assert check_shortcut_call(chat.unpin_message, chat.get_bot(), 'unpin_chat_message')
assert check_defaults_handling(chat.unpin_message, chat.get_bot())
monkeypatch.setattr(chat.bot, 'unpin_chat_message', make_assertion)
monkeypatch.setattr(chat.get_bot(), 'unpin_chat_message', make_assertion)
assert chat.unpin_message()
def test_unpin_all_messages(self, monkeypatch, chat):
@ -389,10 +393,12 @@ class TestChat:
assert check_shortcut_signature(
Chat.unpin_all_messages, Bot.unpin_all_chat_messages, ['chat_id'], []
)
assert check_shortcut_call(chat.unpin_all_messages, chat.bot, 'unpin_all_chat_messages')
assert check_defaults_handling(chat.unpin_all_messages, chat.bot)
assert check_shortcut_call(
chat.unpin_all_messages, chat.get_bot(), 'unpin_all_chat_messages'
)
assert check_defaults_handling(chat.unpin_all_messages, chat.get_bot())
monkeypatch.setattr(chat.bot, 'unpin_all_chat_messages', make_assertion)
monkeypatch.setattr(chat.get_bot(), 'unpin_all_chat_messages', make_assertion)
assert chat.unpin_all_messages()
def test_instance_method_send_message(self, monkeypatch, chat):
@ -400,10 +406,10 @@ class TestChat:
return kwargs['chat_id'] == chat.id and kwargs['text'] == 'test'
assert check_shortcut_signature(Chat.send_message, Bot.send_message, ['chat_id'], [])
assert check_shortcut_call(chat.send_message, chat.bot, 'send_message')
assert check_defaults_handling(chat.send_message, chat.bot)
assert check_shortcut_call(chat.send_message, chat.get_bot(), 'send_message')
assert check_defaults_handling(chat.send_message, chat.get_bot())
monkeypatch.setattr(chat.bot, 'send_message', make_assertion)
monkeypatch.setattr(chat.get_bot(), 'send_message', make_assertion)
assert chat.send_message(text='test')
def test_instance_method_send_media_group(self, monkeypatch, chat):
@ -413,10 +419,10 @@ class TestChat:
assert check_shortcut_signature(
Chat.send_media_group, Bot.send_media_group, ['chat_id'], []
)
assert check_shortcut_call(chat.send_media_group, chat.bot, 'send_media_group')
assert check_defaults_handling(chat.send_media_group, chat.bot)
assert check_shortcut_call(chat.send_media_group, chat.get_bot(), 'send_media_group')
assert check_defaults_handling(chat.send_media_group, chat.get_bot())
monkeypatch.setattr(chat.bot, 'send_media_group', make_assertion)
monkeypatch.setattr(chat.get_bot(), 'send_media_group', make_assertion)
assert chat.send_media_group(media='test_media_group')
def test_instance_method_send_photo(self, monkeypatch, chat):
@ -424,10 +430,10 @@ class TestChat:
return kwargs['chat_id'] == chat.id and kwargs['photo'] == 'test_photo'
assert check_shortcut_signature(Chat.send_photo, Bot.send_photo, ['chat_id'], [])
assert check_shortcut_call(chat.send_photo, chat.bot, 'send_photo')
assert check_defaults_handling(chat.send_photo, chat.bot)
assert check_shortcut_call(chat.send_photo, chat.get_bot(), 'send_photo')
assert check_defaults_handling(chat.send_photo, chat.get_bot())
monkeypatch.setattr(chat.bot, 'send_photo', make_assertion)
monkeypatch.setattr(chat.get_bot(), 'send_photo', make_assertion)
assert chat.send_photo(photo='test_photo')
def test_instance_method_send_contact(self, monkeypatch, chat):
@ -435,10 +441,10 @@ class TestChat:
return kwargs['chat_id'] == chat.id and kwargs['phone_number'] == 'test_contact'
assert check_shortcut_signature(Chat.send_contact, Bot.send_contact, ['chat_id'], [])
assert check_shortcut_call(chat.send_contact, chat.bot, 'send_contact')
assert check_defaults_handling(chat.send_contact, chat.bot)
assert check_shortcut_call(chat.send_contact, chat.get_bot(), 'send_contact')
assert check_defaults_handling(chat.send_contact, chat.get_bot())
monkeypatch.setattr(chat.bot, 'send_contact', make_assertion)
monkeypatch.setattr(chat.get_bot(), 'send_contact', make_assertion)
assert chat.send_contact(phone_number='test_contact')
def test_instance_method_send_audio(self, monkeypatch, chat):
@ -446,10 +452,10 @@ class TestChat:
return kwargs['chat_id'] == chat.id and kwargs['audio'] == 'test_audio'
assert check_shortcut_signature(Chat.send_audio, Bot.send_audio, ['chat_id'], [])
assert check_shortcut_call(chat.send_audio, chat.bot, 'send_audio')
assert check_defaults_handling(chat.send_audio, chat.bot)
assert check_shortcut_call(chat.send_audio, chat.get_bot(), 'send_audio')
assert check_defaults_handling(chat.send_audio, chat.get_bot())
monkeypatch.setattr(chat.bot, 'send_audio', make_assertion)
monkeypatch.setattr(chat.get_bot(), 'send_audio', make_assertion)
assert chat.send_audio(audio='test_audio')
def test_instance_method_send_document(self, monkeypatch, chat):
@ -457,10 +463,10 @@ class TestChat:
return kwargs['chat_id'] == chat.id and kwargs['document'] == 'test_document'
assert check_shortcut_signature(Chat.send_document, Bot.send_document, ['chat_id'], [])
assert check_shortcut_call(chat.send_document, chat.bot, 'send_document')
assert check_defaults_handling(chat.send_document, chat.bot)
assert check_shortcut_call(chat.send_document, chat.get_bot(), 'send_document')
assert check_defaults_handling(chat.send_document, chat.get_bot())
monkeypatch.setattr(chat.bot, 'send_document', make_assertion)
monkeypatch.setattr(chat.get_bot(), 'send_document', make_assertion)
assert chat.send_document(document='test_document')
def test_instance_method_send_dice(self, monkeypatch, chat):
@ -468,10 +474,10 @@ class TestChat:
return kwargs['chat_id'] == chat.id and kwargs['emoji'] == 'test_dice'
assert check_shortcut_signature(Chat.send_dice, Bot.send_dice, ['chat_id'], [])
assert check_shortcut_call(chat.send_dice, chat.bot, 'send_dice')
assert check_defaults_handling(chat.send_dice, chat.bot)
assert check_shortcut_call(chat.send_dice, chat.get_bot(), 'send_dice')
assert check_defaults_handling(chat.send_dice, chat.get_bot())
monkeypatch.setattr(chat.bot, 'send_dice', make_assertion)
monkeypatch.setattr(chat.get_bot(), 'send_dice', make_assertion)
assert chat.send_dice(emoji='test_dice')
def test_instance_method_send_game(self, monkeypatch, chat):
@ -479,10 +485,10 @@ class TestChat:
return kwargs['chat_id'] == chat.id and kwargs['game_short_name'] == 'test_game'
assert check_shortcut_signature(Chat.send_game, Bot.send_game, ['chat_id'], [])
assert check_shortcut_call(chat.send_game, chat.bot, 'send_game')
assert check_defaults_handling(chat.send_game, chat.bot)
assert check_shortcut_call(chat.send_game, chat.get_bot(), 'send_game')
assert check_defaults_handling(chat.send_game, chat.get_bot())
monkeypatch.setattr(chat.bot, 'send_game', make_assertion)
monkeypatch.setattr(chat.get_bot(), 'send_game', make_assertion)
assert chat.send_game(game_short_name='test_game')
def test_instance_method_send_invoice(self, monkeypatch, chat):
@ -497,10 +503,10 @@ class TestChat:
return kwargs['chat_id'] == chat.id and args
assert check_shortcut_signature(Chat.send_invoice, Bot.send_invoice, ['chat_id'], [])
assert check_shortcut_call(chat.send_invoice, chat.bot, 'send_invoice')
assert check_defaults_handling(chat.send_invoice, chat.bot)
assert check_shortcut_call(chat.send_invoice, chat.get_bot(), 'send_invoice')
assert check_defaults_handling(chat.send_invoice, chat.get_bot())
monkeypatch.setattr(chat.bot, 'send_invoice', make_assertion)
monkeypatch.setattr(chat.get_bot(), 'send_invoice', make_assertion)
assert chat.send_invoice(
'title',
'description',
@ -515,10 +521,10 @@ class TestChat:
return kwargs['chat_id'] == chat.id and kwargs['latitude'] == 'test_location'
assert check_shortcut_signature(Chat.send_location, Bot.send_location, ['chat_id'], [])
assert check_shortcut_call(chat.send_location, chat.bot, 'send_location')
assert check_defaults_handling(chat.send_location, chat.bot)
assert check_shortcut_call(chat.send_location, chat.get_bot(), 'send_location')
assert check_defaults_handling(chat.send_location, chat.get_bot())
monkeypatch.setattr(chat.bot, 'send_location', make_assertion)
monkeypatch.setattr(chat.get_bot(), 'send_location', make_assertion)
assert chat.send_location(latitude='test_location')
def test_instance_method_send_sticker(self, monkeypatch, chat):
@ -526,10 +532,10 @@ class TestChat:
return kwargs['chat_id'] == chat.id and kwargs['sticker'] == 'test_sticker'
assert check_shortcut_signature(Chat.send_sticker, Bot.send_sticker, ['chat_id'], [])
assert check_shortcut_call(chat.send_sticker, chat.bot, 'send_sticker')
assert check_defaults_handling(chat.send_sticker, chat.bot)
assert check_shortcut_call(chat.send_sticker, chat.get_bot(), 'send_sticker')
assert check_defaults_handling(chat.send_sticker, chat.get_bot())
monkeypatch.setattr(chat.bot, 'send_sticker', make_assertion)
monkeypatch.setattr(chat.get_bot(), 'send_sticker', make_assertion)
assert chat.send_sticker(sticker='test_sticker')
def test_instance_method_send_venue(self, monkeypatch, chat):
@ -537,10 +543,10 @@ class TestChat:
return kwargs['chat_id'] == chat.id and kwargs['title'] == 'test_venue'
assert check_shortcut_signature(Chat.send_venue, Bot.send_venue, ['chat_id'], [])
assert check_shortcut_call(chat.send_venue, chat.bot, 'send_venue')
assert check_defaults_handling(chat.send_venue, chat.bot)
assert check_shortcut_call(chat.send_venue, chat.get_bot(), 'send_venue')
assert check_defaults_handling(chat.send_venue, chat.get_bot())
monkeypatch.setattr(chat.bot, 'send_venue', make_assertion)
monkeypatch.setattr(chat.get_bot(), 'send_venue', make_assertion)
assert chat.send_venue(title='test_venue')
def test_instance_method_send_video(self, monkeypatch, chat):
@ -548,10 +554,10 @@ class TestChat:
return kwargs['chat_id'] == chat.id and kwargs['video'] == 'test_video'
assert check_shortcut_signature(Chat.send_video, Bot.send_video, ['chat_id'], [])
assert check_shortcut_call(chat.send_video, chat.bot, 'send_video')
assert check_defaults_handling(chat.send_video, chat.bot)
assert check_shortcut_call(chat.send_video, chat.get_bot(), 'send_video')
assert check_defaults_handling(chat.send_video, chat.get_bot())
monkeypatch.setattr(chat.bot, 'send_video', make_assertion)
monkeypatch.setattr(chat.get_bot(), 'send_video', make_assertion)
assert chat.send_video(video='test_video')
def test_instance_method_send_video_note(self, monkeypatch, chat):
@ -559,10 +565,10 @@ class TestChat:
return kwargs['chat_id'] == chat.id and kwargs['video_note'] == 'test_video_note'
assert check_shortcut_signature(Chat.send_video_note, Bot.send_video_note, ['chat_id'], [])
assert check_shortcut_call(chat.send_video_note, chat.bot, 'send_video_note')
assert check_defaults_handling(chat.send_video_note, chat.bot)
assert check_shortcut_call(chat.send_video_note, chat.get_bot(), 'send_video_note')
assert check_defaults_handling(chat.send_video_note, chat.get_bot())
monkeypatch.setattr(chat.bot, 'send_video_note', make_assertion)
monkeypatch.setattr(chat.get_bot(), 'send_video_note', make_assertion)
assert chat.send_video_note(video_note='test_video_note')
def test_instance_method_send_voice(self, monkeypatch, chat):
@ -570,10 +576,10 @@ class TestChat:
return kwargs['chat_id'] == chat.id and kwargs['voice'] == 'test_voice'
assert check_shortcut_signature(Chat.send_voice, Bot.send_voice, ['chat_id'], [])
assert check_shortcut_call(chat.send_voice, chat.bot, 'send_voice')
assert check_defaults_handling(chat.send_voice, chat.bot)
assert check_shortcut_call(chat.send_voice, chat.get_bot(), 'send_voice')
assert check_defaults_handling(chat.send_voice, chat.get_bot())
monkeypatch.setattr(chat.bot, 'send_voice', make_assertion)
monkeypatch.setattr(chat.get_bot(), 'send_voice', make_assertion)
assert chat.send_voice(voice='test_voice')
def test_instance_method_send_animation(self, monkeypatch, chat):
@ -581,10 +587,10 @@ class TestChat:
return kwargs['chat_id'] == chat.id and kwargs['animation'] == 'test_animation'
assert check_shortcut_signature(Chat.send_animation, Bot.send_animation, ['chat_id'], [])
assert check_shortcut_call(chat.send_animation, chat.bot, 'send_animation')
assert check_defaults_handling(chat.send_animation, chat.bot)
assert check_shortcut_call(chat.send_animation, chat.get_bot(), 'send_animation')
assert check_defaults_handling(chat.send_animation, chat.get_bot())
monkeypatch.setattr(chat.bot, 'send_animation', make_assertion)
monkeypatch.setattr(chat.get_bot(), 'send_animation', make_assertion)
assert chat.send_animation(animation='test_animation')
def test_instance_method_send_poll(self, monkeypatch, chat):
@ -592,10 +598,10 @@ class TestChat:
return kwargs['chat_id'] == chat.id and kwargs['question'] == 'test_poll'
assert check_shortcut_signature(Chat.send_poll, Bot.send_poll, ['chat_id'], [])
assert check_shortcut_call(chat.send_poll, chat.bot, 'send_poll')
assert check_defaults_handling(chat.send_poll, chat.bot)
assert check_shortcut_call(chat.send_poll, chat.get_bot(), 'send_poll')
assert check_defaults_handling(chat.send_poll, chat.get_bot())
monkeypatch.setattr(chat.bot, 'send_poll', make_assertion)
monkeypatch.setattr(chat.get_bot(), 'send_poll', make_assertion)
assert chat.send_poll(question='test_poll', options=[1, 2])
def test_instance_method_send_copy(self, monkeypatch, chat):
@ -606,10 +612,10 @@ class TestChat:
return from_chat_id and message_id and chat_id
assert check_shortcut_signature(Chat.send_copy, Bot.copy_message, ['chat_id'], [])
assert check_shortcut_call(chat.copy_message, chat.bot, 'copy_message')
assert check_defaults_handling(chat.copy_message, chat.bot)
assert check_shortcut_call(chat.copy_message, chat.get_bot(), 'copy_message')
assert check_defaults_handling(chat.copy_message, chat.get_bot())
monkeypatch.setattr(chat.bot, 'copy_message', make_assertion)
monkeypatch.setattr(chat.get_bot(), 'copy_message', make_assertion)
assert chat.send_copy(from_chat_id='test_copy', message_id=42)
def test_instance_method_copy_message(self, monkeypatch, chat):
@ -620,10 +626,10 @@ class TestChat:
return from_chat_id and message_id and chat_id
assert check_shortcut_signature(Chat.copy_message, Bot.copy_message, ['from_chat_id'], [])
assert check_shortcut_call(chat.copy_message, chat.bot, 'copy_message')
assert check_defaults_handling(chat.copy_message, chat.bot)
assert check_shortcut_call(chat.copy_message, chat.get_bot(), 'copy_message')
assert check_defaults_handling(chat.copy_message, chat.get_bot())
monkeypatch.setattr(chat.bot, 'copy_message', make_assertion)
monkeypatch.setattr(chat.get_bot(), 'copy_message', make_assertion)
assert chat.copy_message(chat_id='test_copy', message_id=42)
def test_export_invite_link(self, monkeypatch, chat):
@ -633,10 +639,12 @@ class TestChat:
assert check_shortcut_signature(
Chat.export_invite_link, Bot.export_chat_invite_link, ['chat_id'], []
)
assert check_shortcut_call(chat.export_invite_link, chat.bot, 'export_chat_invite_link')
assert check_defaults_handling(chat.export_invite_link, chat.bot)
assert check_shortcut_call(
chat.export_invite_link, chat.get_bot(), 'export_chat_invite_link'
)
assert check_defaults_handling(chat.export_invite_link, chat.get_bot())
monkeypatch.setattr(chat.bot, 'export_chat_invite_link', make_assertion)
monkeypatch.setattr(chat.get_bot(), 'export_chat_invite_link', make_assertion)
assert chat.export_invite_link()
def test_create_invite_link(self, monkeypatch, chat):
@ -646,10 +654,12 @@ class TestChat:
assert check_shortcut_signature(
Chat.create_invite_link, Bot.create_chat_invite_link, ['chat_id'], []
)
assert check_shortcut_call(chat.create_invite_link, chat.bot, 'create_chat_invite_link')
assert check_defaults_handling(chat.create_invite_link, chat.bot)
assert check_shortcut_call(
chat.create_invite_link, chat.get_bot(), 'create_chat_invite_link'
)
assert check_defaults_handling(chat.create_invite_link, chat.get_bot())
monkeypatch.setattr(chat.bot, 'create_chat_invite_link', make_assertion)
monkeypatch.setattr(chat.get_bot(), 'create_chat_invite_link', make_assertion)
assert chat.create_invite_link()
def test_edit_invite_link(self, monkeypatch, chat):
@ -661,10 +671,10 @@ class TestChat:
assert check_shortcut_signature(
Chat.edit_invite_link, Bot.edit_chat_invite_link, ['chat_id'], []
)
assert check_shortcut_call(chat.edit_invite_link, chat.bot, 'edit_chat_invite_link')
assert check_defaults_handling(chat.edit_invite_link, chat.bot)
assert check_shortcut_call(chat.edit_invite_link, chat.get_bot(), 'edit_chat_invite_link')
assert check_defaults_handling(chat.edit_invite_link, chat.get_bot())
monkeypatch.setattr(chat.bot, 'edit_chat_invite_link', make_assertion)
monkeypatch.setattr(chat.get_bot(), 'edit_chat_invite_link', make_assertion)
assert chat.edit_invite_link(invite_link=link)
def test_revoke_invite_link(self, monkeypatch, chat):
@ -676,10 +686,12 @@ class TestChat:
assert check_shortcut_signature(
Chat.revoke_invite_link, Bot.revoke_chat_invite_link, ['chat_id'], []
)
assert check_shortcut_call(chat.revoke_invite_link, chat.bot, 'revoke_chat_invite_link')
assert check_defaults_handling(chat.revoke_invite_link, chat.bot)
assert check_shortcut_call(
chat.revoke_invite_link, chat.get_bot(), 'revoke_chat_invite_link'
)
assert check_defaults_handling(chat.revoke_invite_link, chat.get_bot())
monkeypatch.setattr(chat.bot, 'revoke_chat_invite_link', make_assertion)
monkeypatch.setattr(chat.get_bot(), 'revoke_chat_invite_link', make_assertion)
assert chat.revoke_invite_link(invite_link=link)
def test_approve_join_request(self, monkeypatch, chat):
@ -690,11 +702,11 @@ class TestChat:
Chat.approve_join_request, Bot.approve_chat_join_request, ['chat_id'], []
)
assert check_shortcut_call(
chat.approve_join_request, chat.bot, 'approve_chat_join_request'
chat.approve_join_request, chat.get_bot(), 'approve_chat_join_request'
)
assert check_defaults_handling(chat.approve_join_request, chat.bot)
assert check_defaults_handling(chat.approve_join_request, chat.get_bot())
monkeypatch.setattr(chat.bot, 'approve_chat_join_request', make_assertion)
monkeypatch.setattr(chat.get_bot(), 'approve_chat_join_request', make_assertion)
assert chat.approve_join_request(user_id=42)
def test_decline_join_request(self, monkeypatch, chat):
@ -705,11 +717,11 @@ class TestChat:
Chat.decline_join_request, Bot.decline_chat_join_request, ['chat_id'], []
)
assert check_shortcut_call(
chat.decline_join_request, chat.bot, 'decline_chat_join_request'
chat.decline_join_request, chat.get_bot(), 'decline_chat_join_request'
)
assert check_defaults_handling(chat.decline_join_request, chat.bot)
assert check_defaults_handling(chat.decline_join_request, chat.get_bot())
monkeypatch.setattr(chat.bot, 'decline_chat_join_request', make_assertion)
monkeypatch.setattr(chat.get_bot(), 'decline_chat_join_request', make_assertion)
assert chat.decline_join_request(user_id=42)
def test_equality(self):

View file

@ -130,11 +130,13 @@ class TestChatJoinRequest:
ChatJoinRequest.approve, Bot.approve_chat_join_request, ['chat_id', 'user_id'], []
)
assert check_shortcut_call(
chat_join_request.approve, chat_join_request.bot, 'approve_chat_join_request'
chat_join_request.approve, chat_join_request.get_bot(), 'approve_chat_join_request'
)
assert check_defaults_handling(chat_join_request.approve, chat_join_request.bot)
assert check_defaults_handling(chat_join_request.approve, chat_join_request.get_bot())
monkeypatch.setattr(chat_join_request.bot, 'approve_chat_join_request', make_assertion)
monkeypatch.setattr(
chat_join_request.get_bot(), 'approve_chat_join_request', make_assertion
)
assert chat_join_request.approve()
def test_decline(self, monkeypatch, chat_join_request):
@ -148,9 +150,11 @@ class TestChatJoinRequest:
ChatJoinRequest.decline, Bot.decline_chat_join_request, ['chat_id', 'user_id'], []
)
assert check_shortcut_call(
chat_join_request.decline, chat_join_request.bot, 'decline_chat_join_request'
chat_join_request.decline, chat_join_request.get_bot(), 'decline_chat_join_request'
)
assert check_defaults_handling(chat_join_request.decline, chat_join_request.bot)
assert check_defaults_handling(chat_join_request.decline, chat_join_request.get_bot())
monkeypatch.setattr(chat_join_request.bot, 'decline_chat_join_request', make_assertion)
monkeypatch.setattr(
chat_join_request.get_bot(), 'decline_chat_join_request', make_assertion
)
assert chat_join_request.decline()

View file

@ -139,10 +139,10 @@ class TestChatPhoto:
return kwargs['file_id'] == chat_photo.small_file_id
assert check_shortcut_signature(ChatPhoto.get_small_file, Bot.get_file, ['file_id'], [])
assert check_shortcut_call(chat_photo.get_small_file, chat_photo.bot, 'get_file')
assert check_defaults_handling(chat_photo.get_small_file, chat_photo.bot)
assert check_shortcut_call(chat_photo.get_small_file, chat_photo.get_bot(), 'get_file')
assert check_defaults_handling(chat_photo.get_small_file, chat_photo.get_bot())
monkeypatch.setattr(chat_photo.bot, 'get_file', make_assertion)
monkeypatch.setattr(chat_photo.get_bot(), 'get_file', make_assertion)
assert chat_photo.get_small_file()
def test_get_big_file_instance_method(self, monkeypatch, chat_photo):
@ -150,10 +150,10 @@ class TestChatPhoto:
return kwargs['file_id'] == chat_photo.big_file_id
assert check_shortcut_signature(ChatPhoto.get_big_file, Bot.get_file, ['file_id'], [])
assert check_shortcut_call(chat_photo.get_big_file, chat_photo.bot, 'get_file')
assert check_defaults_handling(chat_photo.get_big_file, chat_photo.bot)
assert check_shortcut_call(chat_photo.get_big_file, chat_photo.get_bot(), 'get_file')
assert check_defaults_handling(chat_photo.get_big_file, chat_photo.get_bot())
monkeypatch.setattr(chat_photo.bot, 'get_file', make_assertion)
monkeypatch.setattr(chat_photo.get_bot(), 'get_file', make_assertion)
assert chat_photo.get_big_file()
def test_equality(self):

View file

@ -303,10 +303,10 @@ class TestDocument:
return kwargs['file_id'] == document.file_id
assert check_shortcut_signature(Document.get_file, Bot.get_file, ['file_id'], [])
assert check_shortcut_call(document.get_file, document.bot, 'get_file')
assert check_defaults_handling(document.get_file, document.bot)
assert check_shortcut_call(document.get_file, document.get_bot(), 'get_file')
assert check_defaults_handling(document.get_file, document.get_bot())
monkeypatch.setattr(document.bot, 'get_file', make_assertion)
monkeypatch.setattr(document.get_bot(), 'get_file', make_assertion)
assert document.get_file()
def test_equality(self, document):

View file

@ -85,10 +85,12 @@ class TestInlineQuery:
assert check_shortcut_signature(
InlineQuery.answer, Bot.answer_inline_query, ['inline_query_id'], ['auto_pagination']
)
assert check_shortcut_call(inline_query.answer, inline_query.bot, 'answer_inline_query')
assert check_defaults_handling(inline_query.answer, inline_query.bot)
assert check_shortcut_call(
inline_query.answer, inline_query.get_bot(), 'answer_inline_query'
)
assert check_defaults_handling(inline_query.answer, inline_query.get_bot())
monkeypatch.setattr(inline_query.bot, 'answer_inline_query', make_assertion)
monkeypatch.setattr(inline_query.get_bot(), 'answer_inline_query', make_assertion)
assert inline_query.answer(results=[])
def test_answer_error(self, inline_query):
@ -101,7 +103,7 @@ class TestInlineQuery:
offset_matches = kwargs.get('current_offset') == inline_query.offset
return offset_matches and inline_query_id_matches
monkeypatch.setattr(inline_query.bot, 'answer_inline_query', make_assertion)
monkeypatch.setattr(inline_query.get_bot(), 'answer_inline_query', make_assertion)
assert inline_query.answer(results=[], auto_pagination=True)
def test_equality(self):

View file

@ -695,10 +695,10 @@ class TestMessage:
assert check_shortcut_signature(
Message.reply_text, Bot.send_message, ['chat_id'], ['quote']
)
assert check_shortcut_call(message.reply_text, message.bot, 'send_message')
assert check_defaults_handling(message.reply_text, message.bot)
assert check_shortcut_call(message.reply_text, message.get_bot(), 'send_message')
assert check_defaults_handling(message.reply_text, message.get_bot())
monkeypatch.setattr(message.bot, 'send_message', make_assertion)
monkeypatch.setattr(message.get_bot(), 'send_message', make_assertion)
assert message.reply_text('test')
assert message.reply_text('test', quote=True)
assert message.reply_text('test', reply_to_message_id=message.message_id, quote=True)
@ -724,13 +724,13 @@ class TestMessage:
assert check_shortcut_signature(
Message.reply_markdown, Bot.send_message, ['chat_id', 'parse_mode'], ['quote']
)
assert check_shortcut_call(message.reply_text, message.bot, 'send_message')
assert check_defaults_handling(message.reply_text, message.bot)
assert check_shortcut_call(message.reply_text, message.get_bot(), 'send_message')
assert check_defaults_handling(message.reply_text, message.get_bot())
text_markdown = self.test_message.text_markdown
assert text_markdown == test_md_string
monkeypatch.setattr(message.bot, 'send_message', make_assertion)
monkeypatch.setattr(message.get_bot(), 'send_message', make_assertion)
assert message.reply_markdown(self.test_message.text_markdown)
assert message.reply_markdown(self.test_message.text_markdown, quote=True)
assert message.reply_markdown(
@ -759,13 +759,13 @@ class TestMessage:
assert check_shortcut_signature(
Message.reply_markdown_v2, Bot.send_message, ['chat_id', 'parse_mode'], ['quote']
)
assert check_shortcut_call(message.reply_text, message.bot, 'send_message')
assert check_defaults_handling(message.reply_text, message.bot)
assert check_shortcut_call(message.reply_text, message.get_bot(), 'send_message')
assert check_defaults_handling(message.reply_text, message.get_bot())
text_markdown = self.test_message_v2.text_markdown_v2
assert text_markdown == test_md_string
monkeypatch.setattr(message.bot, 'send_message', make_assertion)
monkeypatch.setattr(message.get_bot(), 'send_message', make_assertion)
assert message.reply_markdown_v2(self.test_message_v2.text_markdown_v2)
assert message.reply_markdown_v2(self.test_message_v2.text_markdown_v2, quote=True)
assert message.reply_markdown_v2(
@ -799,13 +799,13 @@ class TestMessage:
assert check_shortcut_signature(
Message.reply_html, Bot.send_message, ['chat_id', 'parse_mode'], ['quote']
)
assert check_shortcut_call(message.reply_text, message.bot, 'send_message')
assert check_defaults_handling(message.reply_text, message.bot)
assert check_shortcut_call(message.reply_text, message.get_bot(), 'send_message')
assert check_defaults_handling(message.reply_text, message.get_bot())
text_html = self.test_message_v2.text_html
assert text_html == test_html_string
monkeypatch.setattr(message.bot, 'send_message', make_assertion)
monkeypatch.setattr(message.get_bot(), 'send_message', make_assertion)
assert message.reply_html(self.test_message_v2.text_html)
assert message.reply_html(self.test_message_v2.text_html, quote=True)
assert message.reply_html(
@ -825,10 +825,12 @@ class TestMessage:
assert check_shortcut_signature(
Message.reply_media_group, Bot.send_media_group, ['chat_id'], ['quote']
)
assert check_shortcut_call(message.reply_media_group, message.bot, 'send_media_group')
assert check_defaults_handling(message.reply_media_group, message.bot)
assert check_shortcut_call(
message.reply_media_group, message.get_bot(), 'send_media_group'
)
assert check_defaults_handling(message.reply_media_group, message.get_bot())
monkeypatch.setattr(message.bot, 'send_media_group', make_assertion)
monkeypatch.setattr(message.get_bot(), 'send_media_group', make_assertion)
assert message.reply_media_group(media='reply_media_group')
assert message.reply_media_group(media='reply_media_group', quote=True)
@ -845,10 +847,10 @@ class TestMessage:
assert check_shortcut_signature(
Message.reply_photo, Bot.send_photo, ['chat_id'], ['quote']
)
assert check_shortcut_call(message.reply_photo, message.bot, 'send_photo')
assert check_defaults_handling(message.reply_photo, message.bot)
assert check_shortcut_call(message.reply_photo, message.get_bot(), 'send_photo')
assert check_defaults_handling(message.reply_photo, message.get_bot())
monkeypatch.setattr(message.bot, 'send_photo', make_assertion)
monkeypatch.setattr(message.get_bot(), 'send_photo', make_assertion)
assert message.reply_photo(photo='test_photo')
assert message.reply_photo(photo='test_photo', quote=True)
@ -865,10 +867,10 @@ class TestMessage:
assert check_shortcut_signature(
Message.reply_audio, Bot.send_audio, ['chat_id'], ['quote']
)
assert check_shortcut_call(message.reply_audio, message.bot, 'send_audio')
assert check_defaults_handling(message.reply_audio, message.bot)
assert check_shortcut_call(message.reply_audio, message.get_bot(), 'send_audio')
assert check_defaults_handling(message.reply_audio, message.get_bot())
monkeypatch.setattr(message.bot, 'send_audio', make_assertion)
monkeypatch.setattr(message.get_bot(), 'send_audio', make_assertion)
assert message.reply_audio(audio='test_audio')
assert message.reply_audio(audio='test_audio', quote=True)
@ -885,10 +887,10 @@ class TestMessage:
assert check_shortcut_signature(
Message.reply_document, Bot.send_document, ['chat_id'], ['quote']
)
assert check_shortcut_call(message.reply_document, message.bot, 'send_document')
assert check_defaults_handling(message.reply_document, message.bot)
assert check_shortcut_call(message.reply_document, message.get_bot(), 'send_document')
assert check_defaults_handling(message.reply_document, message.get_bot())
monkeypatch.setattr(message.bot, 'send_document', make_assertion)
monkeypatch.setattr(message.get_bot(), 'send_document', make_assertion)
assert message.reply_document(document='test_document')
assert message.reply_document(document='test_document', quote=True)
@ -905,10 +907,10 @@ class TestMessage:
assert check_shortcut_signature(
Message.reply_animation, Bot.send_animation, ['chat_id'], ['quote']
)
assert check_shortcut_call(message.reply_animation, message.bot, 'send_animation')
assert check_defaults_handling(message.reply_animation, message.bot)
assert check_shortcut_call(message.reply_animation, message.get_bot(), 'send_animation')
assert check_defaults_handling(message.reply_animation, message.get_bot())
monkeypatch.setattr(message.bot, 'send_animation', make_assertion)
monkeypatch.setattr(message.get_bot(), 'send_animation', make_assertion)
assert message.reply_animation(animation='test_animation')
assert message.reply_animation(animation='test_animation', quote=True)
@ -925,10 +927,10 @@ class TestMessage:
assert check_shortcut_signature(
Message.reply_sticker, Bot.send_sticker, ['chat_id'], ['quote']
)
assert check_shortcut_call(message.reply_sticker, message.bot, 'send_sticker')
assert check_defaults_handling(message.reply_sticker, message.bot)
assert check_shortcut_call(message.reply_sticker, message.get_bot(), 'send_sticker')
assert check_defaults_handling(message.reply_sticker, message.get_bot())
monkeypatch.setattr(message.bot, 'send_sticker', make_assertion)
monkeypatch.setattr(message.get_bot(), 'send_sticker', make_assertion)
assert message.reply_sticker(sticker='test_sticker')
assert message.reply_sticker(sticker='test_sticker', quote=True)
@ -945,10 +947,10 @@ class TestMessage:
assert check_shortcut_signature(
Message.reply_video, Bot.send_video, ['chat_id'], ['quote']
)
assert check_shortcut_call(message.reply_video, message.bot, 'send_video')
assert check_defaults_handling(message.reply_video, message.bot)
assert check_shortcut_call(message.reply_video, message.get_bot(), 'send_video')
assert check_defaults_handling(message.reply_video, message.get_bot())
monkeypatch.setattr(message.bot, 'send_video', make_assertion)
monkeypatch.setattr(message.get_bot(), 'send_video', make_assertion)
assert message.reply_video(video='test_video')
assert message.reply_video(video='test_video', quote=True)
@ -965,10 +967,10 @@ class TestMessage:
assert check_shortcut_signature(
Message.reply_video_note, Bot.send_video_note, ['chat_id'], ['quote']
)
assert check_shortcut_call(message.reply_video_note, message.bot, 'send_video_note')
assert check_defaults_handling(message.reply_video_note, message.bot)
assert check_shortcut_call(message.reply_video_note, message.get_bot(), 'send_video_note')
assert check_defaults_handling(message.reply_video_note, message.get_bot())
monkeypatch.setattr(message.bot, 'send_video_note', make_assertion)
monkeypatch.setattr(message.get_bot(), 'send_video_note', make_assertion)
assert message.reply_video_note(video_note='test_video_note')
assert message.reply_video_note(video_note='test_video_note', quote=True)
@ -985,10 +987,10 @@ class TestMessage:
assert check_shortcut_signature(
Message.reply_voice, Bot.send_voice, ['chat_id'], ['quote']
)
assert check_shortcut_call(message.reply_voice, message.bot, 'send_voice')
assert check_defaults_handling(message.reply_voice, message.bot)
assert check_shortcut_call(message.reply_voice, message.get_bot(), 'send_voice')
assert check_defaults_handling(message.reply_voice, message.get_bot())
monkeypatch.setattr(message.bot, 'send_voice', make_assertion)
monkeypatch.setattr(message.get_bot(), 'send_voice', make_assertion)
assert message.reply_voice(voice='test_voice')
assert message.reply_voice(voice='test_voice', quote=True)
@ -1005,10 +1007,10 @@ class TestMessage:
assert check_shortcut_signature(
Message.reply_location, Bot.send_location, ['chat_id'], ['quote']
)
assert check_shortcut_call(message.reply_location, message.bot, 'send_location')
assert check_defaults_handling(message.reply_location, message.bot)
assert check_shortcut_call(message.reply_location, message.get_bot(), 'send_location')
assert check_defaults_handling(message.reply_location, message.get_bot())
monkeypatch.setattr(message.bot, 'send_location', make_assertion)
monkeypatch.setattr(message.get_bot(), 'send_location', make_assertion)
assert message.reply_location(location='test_location')
assert message.reply_location(location='test_location', quote=True)
@ -1025,10 +1027,10 @@ class TestMessage:
assert check_shortcut_signature(
Message.reply_venue, Bot.send_venue, ['chat_id'], ['quote']
)
assert check_shortcut_call(message.reply_venue, message.bot, 'send_venue')
assert check_defaults_handling(message.reply_venue, message.bot)
assert check_shortcut_call(message.reply_venue, message.get_bot(), 'send_venue')
assert check_defaults_handling(message.reply_venue, message.get_bot())
monkeypatch.setattr(message.bot, 'send_venue', make_assertion)
monkeypatch.setattr(message.get_bot(), 'send_venue', make_assertion)
assert message.reply_venue(venue='test_venue')
assert message.reply_venue(venue='test_venue', quote=True)
@ -1045,10 +1047,10 @@ class TestMessage:
assert check_shortcut_signature(
Message.reply_contact, Bot.send_contact, ['chat_id'], ['quote']
)
assert check_shortcut_call(message.reply_contact, message.bot, 'send_contact')
assert check_defaults_handling(message.reply_contact, message.bot)
assert check_shortcut_call(message.reply_contact, message.get_bot(), 'send_contact')
assert check_defaults_handling(message.reply_contact, message.get_bot())
monkeypatch.setattr(message.bot, 'send_contact', make_assertion)
monkeypatch.setattr(message.get_bot(), 'send_contact', make_assertion)
assert message.reply_contact(contact='test_contact')
assert message.reply_contact(contact='test_contact', quote=True)
@ -1064,10 +1066,10 @@ class TestMessage:
return id_ and question and options and reply
assert check_shortcut_signature(Message.reply_poll, Bot.send_poll, ['chat_id'], ['quote'])
assert check_shortcut_call(message.reply_poll, message.bot, 'send_poll')
assert check_defaults_handling(message.reply_poll, message.bot)
assert check_shortcut_call(message.reply_poll, message.get_bot(), 'send_poll')
assert check_defaults_handling(message.reply_poll, message.get_bot())
monkeypatch.setattr(message.bot, 'send_poll', make_assertion)
monkeypatch.setattr(message.get_bot(), 'send_poll', make_assertion)
assert message.reply_poll(question='test_poll', options=['1', '2', '3'])
assert message.reply_poll(question='test_poll', quote=True, options=['1', '2', '3'])
@ -1082,10 +1084,10 @@ class TestMessage:
return id_ and contact and reply
assert check_shortcut_signature(Message.reply_dice, Bot.send_dice, ['chat_id'], ['quote'])
assert check_shortcut_call(message.reply_dice, message.bot, 'send_dice')
assert check_defaults_handling(message.reply_dice, message.bot)
assert check_shortcut_call(message.reply_dice, message.get_bot(), 'send_dice')
assert check_defaults_handling(message.reply_dice, message.get_bot())
monkeypatch.setattr(message.bot, 'send_dice', make_assertion)
monkeypatch.setattr(message.get_bot(), 'send_dice', make_assertion)
assert message.reply_dice(disable_notification=True)
assert message.reply_dice(disable_notification=True, quote=True)
@ -1098,10 +1100,12 @@ class TestMessage:
assert check_shortcut_signature(
Message.reply_chat_action, Bot.send_chat_action, ['chat_id'], []
)
assert check_shortcut_call(message.reply_chat_action, message.bot, 'send_chat_action')
assert check_defaults_handling(message.reply_chat_action, message.bot)
assert check_shortcut_call(
message.reply_chat_action, message.get_bot(), 'send_chat_action'
)
assert check_defaults_handling(message.reply_chat_action, message.get_bot())
monkeypatch.setattr(message.bot, 'send_chat_action', make_assertion)
monkeypatch.setattr(message.get_bot(), 'send_chat_action', make_assertion)
assert message.reply_chat_action(action=ChatAction.TYPING)
def test_reply_game(self, monkeypatch, message: Message):
@ -1111,10 +1115,10 @@ class TestMessage:
)
assert check_shortcut_signature(Message.reply_game, Bot.send_game, ['chat_id'], ['quote'])
assert check_shortcut_call(message.reply_game, message.bot, 'send_game')
assert check_defaults_handling(message.reply_game, message.bot)
assert check_shortcut_call(message.reply_game, message.get_bot(), 'send_game')
assert check_defaults_handling(message.reply_game, message.get_bot())
monkeypatch.setattr(message.bot, 'send_game', make_assertion)
monkeypatch.setattr(message.get_bot(), 'send_game', make_assertion)
assert message.reply_game(game_short_name='test_game')
assert message.reply_game(game_short_name='test_game', quote=True)
@ -1132,10 +1136,10 @@ class TestMessage:
assert check_shortcut_signature(
Message.reply_invoice, Bot.send_invoice, ['chat_id'], ['quote']
)
assert check_shortcut_call(message.reply_invoice, message.bot, 'send_invoice')
assert check_defaults_handling(message.reply_invoice, message.bot)
assert check_shortcut_call(message.reply_invoice, message.get_bot(), 'send_invoice')
assert check_defaults_handling(message.reply_invoice, message.get_bot())
monkeypatch.setattr(message.bot, 'send_invoice', make_assertion)
monkeypatch.setattr(message.get_bot(), 'send_invoice', make_assertion)
assert message.reply_invoice(
'title',
'description',
@ -1167,10 +1171,10 @@ class TestMessage:
assert check_shortcut_signature(
Message.forward, Bot.forward_message, ['from_chat_id', 'message_id'], []
)
assert check_shortcut_call(message.forward, message.bot, 'forward_message')
assert check_defaults_handling(message.forward, message.bot)
assert check_shortcut_call(message.forward, message.get_bot(), 'forward_message')
assert check_defaults_handling(message.forward, message.get_bot())
monkeypatch.setattr(message.bot, 'forward_message', make_assertion)
monkeypatch.setattr(message.get_bot(), 'forward_message', make_assertion)
assert message.forward(
123456, disable_notification=disable_notification, protect_content=protected
)
@ -1202,10 +1206,11 @@ class TestMessage:
assert check_shortcut_signature(
Message.copy, Bot.copy_message, ['from_chat_id', 'message_id'], []
)
assert check_shortcut_call(message.copy, message.bot, 'copy_message')
assert check_defaults_handling(message.copy, message.bot)
monkeypatch.setattr(message.bot, 'copy_message', make_assertion)
assert check_shortcut_call(message.copy, message.get_bot(), 'copy_message')
assert check_defaults_handling(message.copy, message.get_bot())
monkeypatch.setattr(message.get_bot(), 'copy_message', make_assertion)
assert message.copy(
123456, disable_notification=disable_notification, protect_content=protected
)
@ -1248,10 +1253,10 @@ class TestMessage:
assert check_shortcut_signature(
Message.reply_copy, Bot.copy_message, ['chat_id'], ['quote']
)
assert check_shortcut_call(message.copy, message.bot, 'copy_message')
assert check_defaults_handling(message.copy, message.bot)
assert check_shortcut_call(message.copy, message.get_bot(), 'copy_message')
assert check_defaults_handling(message.copy, message.get_bot())
monkeypatch.setattr(message.bot, 'copy_message', make_assertion)
monkeypatch.setattr(message.get_bot(), 'copy_message', make_assertion)
assert message.reply_copy(
123456, 456789, disable_notification=disable_notification, protect_content=protected
)
@ -1293,14 +1298,14 @@ class TestMessage:
)
assert check_shortcut_call(
message.edit_text,
message.bot,
message.get_bot(),
'edit_message_text',
skip_params=['inline_message_id'],
shortcut_kwargs=['message_id', 'chat_id'],
)
assert check_defaults_handling(message.edit_text, message.bot)
assert check_defaults_handling(message.edit_text, message.get_bot())
monkeypatch.setattr(message.bot, 'edit_message_text', make_assertion)
monkeypatch.setattr(message.get_bot(), 'edit_message_text', make_assertion)
assert message.edit_text(text='test')
def test_edit_caption(self, monkeypatch, message):
@ -1318,14 +1323,14 @@ class TestMessage:
)
assert check_shortcut_call(
message.edit_caption,
message.bot,
message.get_bot(),
'edit_message_caption',
skip_params=['inline_message_id'],
shortcut_kwargs=['message_id', 'chat_id'],
)
assert check_defaults_handling(message.edit_caption, message.bot)
assert check_defaults_handling(message.edit_caption, message.get_bot())
monkeypatch.setattr(message.bot, 'edit_message_caption', make_assertion)
monkeypatch.setattr(message.get_bot(), 'edit_message_caption', make_assertion)
assert message.edit_caption(caption='new caption')
def test_edit_media(self, monkeypatch, message):
@ -1343,14 +1348,14 @@ class TestMessage:
)
assert check_shortcut_call(
message.edit_media,
message.bot,
message.get_bot(),
'edit_message_media',
skip_params=['inline_message_id'],
shortcut_kwargs=['message_id', 'chat_id'],
)
assert check_defaults_handling(message.edit_media, message.bot)
assert check_defaults_handling(message.edit_media, message.get_bot())
monkeypatch.setattr(message.bot, 'edit_message_media', make_assertion)
monkeypatch.setattr(message.get_bot(), 'edit_message_media', make_assertion)
assert message.edit_media('my_media')
def test_edit_reply_markup(self, monkeypatch, message):
@ -1368,14 +1373,14 @@ class TestMessage:
)
assert check_shortcut_call(
message.edit_reply_markup,
message.bot,
message.get_bot(),
'edit_message_reply_markup',
skip_params=['inline_message_id'],
shortcut_kwargs=['message_id', 'chat_id'],
)
assert check_defaults_handling(message.edit_reply_markup, message.bot)
assert check_defaults_handling(message.edit_reply_markup, message.get_bot())
monkeypatch.setattr(message.bot, 'edit_message_reply_markup', make_assertion)
monkeypatch.setattr(message.get_bot(), 'edit_message_reply_markup', make_assertion)
assert message.edit_reply_markup(reply_markup=[['1', '2']])
def test_edit_live_location(self, monkeypatch, message):
@ -1394,14 +1399,14 @@ class TestMessage:
)
assert check_shortcut_call(
message.edit_live_location,
message.bot,
message.get_bot(),
'edit_message_live_location',
skip_params=['inline_message_id'],
shortcut_kwargs=['message_id', 'chat_id'],
)
assert check_defaults_handling(message.edit_live_location, message.bot)
assert check_defaults_handling(message.edit_live_location, message.get_bot())
monkeypatch.setattr(message.bot, 'edit_message_live_location', make_assertion)
monkeypatch.setattr(message.get_bot(), 'edit_message_live_location', make_assertion)
assert message.edit_live_location(latitude=1, longitude=2)
def test_stop_live_location(self, monkeypatch, message):
@ -1418,14 +1423,14 @@ class TestMessage:
)
assert check_shortcut_call(
message.stop_live_location,
message.bot,
message.get_bot(),
'stop_message_live_location',
skip_params=['inline_message_id'],
shortcut_kwargs=['message_id', 'chat_id'],
)
assert check_defaults_handling(message.stop_live_location, message.bot)
assert check_defaults_handling(message.stop_live_location, message.get_bot())
monkeypatch.setattr(message.bot, 'stop_message_live_location', make_assertion)
monkeypatch.setattr(message.get_bot(), 'stop_message_live_location', make_assertion)
assert message.stop_live_location()
def test_set_game_score(self, monkeypatch, message):
@ -1444,14 +1449,14 @@ class TestMessage:
)
assert check_shortcut_call(
message.set_game_score,
message.bot,
message.get_bot(),
'set_game_score',
skip_params=['inline_message_id'],
shortcut_kwargs=['message_id', 'chat_id'],
)
assert check_defaults_handling(message.set_game_score, message.bot)
assert check_defaults_handling(message.set_game_score, message.get_bot())
monkeypatch.setattr(message.bot, 'set_game_score', make_assertion)
monkeypatch.setattr(message.get_bot(), 'set_game_score', make_assertion)
assert message.set_game_score(user_id=1, score=2)
def test_get_game_high_scores(self, monkeypatch, message):
@ -1469,14 +1474,14 @@ class TestMessage:
)
assert check_shortcut_call(
message.get_game_high_scores,
message.bot,
message.get_bot(),
'get_game_high_scores',
skip_params=['inline_message_id'],
shortcut_kwargs=['message_id', 'chat_id'],
)
assert check_defaults_handling(message.get_game_high_scores, message.bot)
assert check_defaults_handling(message.get_game_high_scores, message.get_bot())
monkeypatch.setattr(message.bot, 'get_game_high_scores', make_assertion)
monkeypatch.setattr(message.get_bot(), 'get_game_high_scores', make_assertion)
assert message.get_game_high_scores(user_id=1)
def test_delete(self, monkeypatch, message):
@ -1488,10 +1493,10 @@ class TestMessage:
assert check_shortcut_signature(
Message.delete, Bot.delete_message, ['chat_id', 'message_id'], []
)
assert check_shortcut_call(message.delete, message.bot, 'delete_message')
assert check_defaults_handling(message.delete, message.bot)
assert check_shortcut_call(message.delete, message.get_bot(), 'delete_message')
assert check_defaults_handling(message.delete, message.get_bot())
monkeypatch.setattr(message.bot, 'delete_message', make_assertion)
monkeypatch.setattr(message.get_bot(), 'delete_message', make_assertion)
assert message.delete()
def test_stop_poll(self, monkeypatch, message):
@ -1503,10 +1508,10 @@ class TestMessage:
assert check_shortcut_signature(
Message.stop_poll, Bot.stop_poll, ['chat_id', 'message_id'], []
)
assert check_shortcut_call(message.stop_poll, message.bot, 'stop_poll')
assert check_defaults_handling(message.stop_poll, message.bot)
assert check_shortcut_call(message.stop_poll, message.get_bot(), 'stop_poll')
assert check_defaults_handling(message.stop_poll, message.get_bot())
monkeypatch.setattr(message.bot, 'stop_poll', make_assertion)
monkeypatch.setattr(message.get_bot(), 'stop_poll', make_assertion)
assert message.stop_poll()
def test_pin(self, monkeypatch, message):
@ -1518,10 +1523,10 @@ class TestMessage:
assert check_shortcut_signature(
Message.pin, Bot.pin_chat_message, ['chat_id', 'message_id'], []
)
assert check_shortcut_call(message.pin, message.bot, 'pin_chat_message')
assert check_defaults_handling(message.pin, message.bot)
assert check_shortcut_call(message.pin, message.get_bot(), 'pin_chat_message')
assert check_defaults_handling(message.pin, message.get_bot())
monkeypatch.setattr(message.bot, 'pin_chat_message', make_assertion)
monkeypatch.setattr(message.get_bot(), 'pin_chat_message', make_assertion)
assert message.pin()
def test_unpin(self, monkeypatch, message):
@ -1535,33 +1540,33 @@ class TestMessage:
)
assert check_shortcut_call(
message.unpin,
message.bot,
message.get_bot(),
'unpin_chat_message',
shortcut_kwargs=['chat_id', 'message_id'],
)
assert check_defaults_handling(message.unpin, message.bot)
assert check_defaults_handling(message.unpin, message.get_bot())
monkeypatch.setattr(message.bot, 'unpin_chat_message', make_assertion)
monkeypatch.setattr(message.get_bot(), 'unpin_chat_message', make_assertion)
assert message.unpin()
def test_default_quote(self, message):
message.bot._defaults = Defaults()
message.get_bot()._defaults = Defaults()
try:
message.bot.defaults._quote = False
message.get_bot().defaults._quote = False
assert message._quote(None, None) is None
message.bot.defaults._quote = True
message.get_bot().defaults._quote = True
assert message._quote(None, None) == message.message_id
message.bot.defaults._quote = None
message.get_bot().defaults._quote = None
message.chat.type = Chat.PRIVATE
assert message._quote(None, None) is None
message.chat.type = Chat.GROUP
assert message._quote(None, None)
finally:
message.bot._defaults = None
message.get_bot()._defaults = None
def test_equality(self):
id_ = 1

View file

@ -462,7 +462,7 @@ class TestPassport:
def get_file(*_, **kwargs):
return File(kwargs['file_id'], selfie.file_unique_id)
monkeypatch.setattr(passport_data.bot, 'get_file', get_file)
monkeypatch.setattr(passport_data.get_bot(), 'get_file', get_file)
file = selfie.get_file()
assert file.file_id == selfie.file_id
assert file.file_unique_id == selfie.file_unique_id

View file

@ -67,10 +67,10 @@ class TestPassportFile:
return File(file_id=result, file_unique_id=result)
assert check_shortcut_signature(PassportFile.get_file, Bot.get_file, ['file_id'], [])
assert check_shortcut_call(passport_file.get_file, passport_file.bot, 'get_file')
assert check_defaults_handling(passport_file.get_file, passport_file.bot)
assert check_shortcut_call(passport_file.get_file, passport_file.get_bot(), 'get_file')
assert check_defaults_handling(passport_file.get_file, passport_file.get_bot())
monkeypatch.setattr(passport_file.bot, 'get_file', make_assertion)
monkeypatch.setattr(passport_file.get_bot(), 'get_file', make_assertion)
assert passport_file.get_file().file_id == 'True'
def test_equality(self):

View file

@ -460,10 +460,10 @@ class TestPhoto:
return kwargs['file_id'] == photo.file_id
assert check_shortcut_signature(PhotoSize.get_file, Bot.get_file, ['file_id'], [])
assert check_shortcut_call(photo.get_file, photo.bot, 'get_file')
assert check_defaults_handling(photo.get_file, photo.bot)
assert check_shortcut_call(photo.get_file, photo.get_bot(), 'get_file')
assert check_defaults_handling(photo.get_file, photo.get_bot())
monkeypatch.setattr(photo.bot, 'get_file', make_assertion)
monkeypatch.setattr(photo.get_bot(), 'get_file', make_assertion)
assert photo.get_file()
def test_equality(self, photo):

View file

@ -63,7 +63,7 @@ class TestPreCheckoutQuery:
}
pre_checkout_query = PreCheckoutQuery.de_json(json_dict, bot)
assert pre_checkout_query.bot is bot
assert pre_checkout_query.get_bot() is bot
assert pre_checkout_query.id == self.id_
assert pre_checkout_query.invoice_payload == self.invoice_payload
assert pre_checkout_query.shipping_option_id == self.shipping_option_id
@ -93,12 +93,14 @@ class TestPreCheckoutQuery:
)
assert check_shortcut_call(
pre_checkout_query.answer,
pre_checkout_query.bot,
pre_checkout_query.get_bot(),
'answer_pre_checkout_query',
)
assert check_defaults_handling(pre_checkout_query.answer, pre_checkout_query.bot)
assert check_defaults_handling(pre_checkout_query.answer, pre_checkout_query.get_bot())
monkeypatch.setattr(pre_checkout_query.bot, 'answer_pre_checkout_query', make_assertion)
monkeypatch.setattr(
pre_checkout_query.get_bot(), 'answer_pre_checkout_query', make_assertion
)
assert pre_checkout_query.answer(ok=True)
def test_equality(self):

View file

@ -58,7 +58,7 @@ class TestShippingQuery:
assert shipping_query.invoice_payload == self.invoice_payload
assert shipping_query.from_user == self.from_user
assert shipping_query.shipping_address == self.shipping_address
assert shipping_query.bot is bot
assert shipping_query.get_bot() is bot
def test_to_dict(self, shipping_query):
shipping_query_dict = shipping_query.to_dict()
@ -77,11 +77,11 @@ class TestShippingQuery:
ShippingQuery.answer, Bot.answer_shipping_query, ['shipping_query_id'], []
)
assert check_shortcut_call(
shipping_query.answer, shipping_query.bot, 'answer_shipping_query'
shipping_query.answer, shipping_query._bot, 'answer_shipping_query'
)
assert check_defaults_handling(shipping_query.answer, shipping_query.bot)
assert check_defaults_handling(shipping_query.answer, shipping_query._bot)
monkeypatch.setattr(shipping_query.bot, 'answer_shipping_query', make_assertion)
monkeypatch.setattr(shipping_query._bot, 'answer_shipping_query', make_assertion)
assert shipping_query.answer(ok=True)
def test_equality(self):

View file

@ -634,10 +634,10 @@ class TestStickerSet:
return kwargs['file_id'] == sticker.file_id
assert check_shortcut_signature(Sticker.get_file, Bot.get_file, ['file_id'], [])
assert check_shortcut_call(sticker.get_file, sticker.bot, 'get_file')
assert check_defaults_handling(sticker.get_file, sticker.bot)
assert check_shortcut_call(sticker.get_file, sticker.get_bot(), 'get_file')
assert check_defaults_handling(sticker.get_file, sticker.get_bot())
monkeypatch.setattr(sticker.bot, 'get_file', make_assertion)
monkeypatch.setattr(sticker.get_bot(), 'get_file', make_assertion)
assert sticker.get_file()
def test_equality(self):

View file

@ -116,3 +116,18 @@ class TestTelegramObject:
assert len(recwarn) == 0
assert b == a
assert len(recwarn) == 0
def test_bot_instance_none(self):
tg_object = TelegramObject()
with pytest.raises(RuntimeError):
tg_object.get_bot()
@pytest.mark.parametrize('bot_inst', ['bot', None])
def test_bot_instance_states(self, bot_inst):
tg_object = TelegramObject()
tg_object.set_bot('bot' if bot_inst == 'bot' else bot_inst)
if bot_inst == 'bot':
assert tg_object.get_bot() == 'bot'
elif bot_inst is None:
with pytest.raises(RuntimeError):
tg_object.get_bot()

View file

@ -140,10 +140,12 @@ class TestUser:
assert check_shortcut_signature(
User.get_profile_photos, Bot.get_user_profile_photos, ['user_id'], []
)
assert check_shortcut_call(user.get_profile_photos, user.bot, 'get_user_profile_photos')
assert check_defaults_handling(user.get_profile_photos, user.bot)
assert check_shortcut_call(
user.get_profile_photos, user.get_bot(), 'get_user_profile_photos'
)
assert check_defaults_handling(user.get_profile_photos, user.get_bot())
monkeypatch.setattr(user.bot, 'get_user_profile_photos', make_assertion)
monkeypatch.setattr(user.get_bot(), 'get_user_profile_photos', make_assertion)
assert user.get_profile_photos()
def test_instance_method_pin_message(self, monkeypatch, user):
@ -151,10 +153,10 @@ class TestUser:
return kwargs['chat_id'] == user.id
assert check_shortcut_signature(User.pin_message, Bot.pin_chat_message, ['chat_id'], [])
assert check_shortcut_call(user.pin_message, user.bot, 'pin_chat_message')
assert check_defaults_handling(user.pin_message, user.bot)
assert check_shortcut_call(user.pin_message, user.get_bot(), 'pin_chat_message')
assert check_defaults_handling(user.pin_message, user.get_bot())
monkeypatch.setattr(user.bot, 'pin_chat_message', make_assertion)
monkeypatch.setattr(user.get_bot(), 'pin_chat_message', make_assertion)
assert user.pin_message(1)
def test_instance_method_unpin_message(self, monkeypatch, user):
@ -164,10 +166,10 @@ class TestUser:
assert check_shortcut_signature(
User.unpin_message, Bot.unpin_chat_message, ['chat_id'], []
)
assert check_shortcut_call(user.unpin_message, user.bot, 'unpin_chat_message')
assert check_defaults_handling(user.unpin_message, user.bot)
assert check_shortcut_call(user.unpin_message, user.get_bot(), 'unpin_chat_message')
assert check_defaults_handling(user.unpin_message, user.get_bot())
monkeypatch.setattr(user.bot, 'unpin_chat_message', make_assertion)
monkeypatch.setattr(user.get_bot(), 'unpin_chat_message', make_assertion)
assert user.unpin_message()
def test_instance_method_unpin_all_messages(self, monkeypatch, user):
@ -177,10 +179,12 @@ class TestUser:
assert check_shortcut_signature(
User.unpin_all_messages, Bot.unpin_all_chat_messages, ['chat_id'], []
)
assert check_shortcut_call(user.unpin_all_messages, user.bot, 'unpin_all_chat_messages')
assert check_defaults_handling(user.unpin_all_messages, user.bot)
assert check_shortcut_call(
user.unpin_all_messages, user.get_bot(), 'unpin_all_chat_messages'
)
assert check_defaults_handling(user.unpin_all_messages, user.get_bot())
monkeypatch.setattr(user.bot, 'unpin_all_chat_messages', make_assertion)
monkeypatch.setattr(user.get_bot(), 'unpin_all_chat_messages', make_assertion)
assert user.unpin_all_messages()
def test_instance_method_send_message(self, monkeypatch, user):
@ -188,10 +192,10 @@ class TestUser:
return kwargs['chat_id'] == user.id and kwargs['text'] == 'test'
assert check_shortcut_signature(User.send_message, Bot.send_message, ['chat_id'], [])
assert check_shortcut_call(user.send_message, user.bot, 'send_message')
assert check_defaults_handling(user.send_message, user.bot)
assert check_shortcut_call(user.send_message, user.get_bot(), 'send_message')
assert check_defaults_handling(user.send_message, user.get_bot())
monkeypatch.setattr(user.bot, 'send_message', make_assertion)
monkeypatch.setattr(user.get_bot(), 'send_message', make_assertion)
assert user.send_message('test')
def test_instance_method_send_photo(self, monkeypatch, user):
@ -199,10 +203,10 @@ class TestUser:
return kwargs['chat_id'] == user.id and kwargs['photo'] == 'test_photo'
assert check_shortcut_signature(User.send_photo, Bot.send_photo, ['chat_id'], [])
assert check_shortcut_call(user.send_photo, user.bot, 'send_photo')
assert check_defaults_handling(user.send_photo, user.bot)
assert check_shortcut_call(user.send_photo, user.get_bot(), 'send_photo')
assert check_defaults_handling(user.send_photo, user.get_bot())
monkeypatch.setattr(user.bot, 'send_photo', make_assertion)
monkeypatch.setattr(user.get_bot(), 'send_photo', make_assertion)
assert user.send_photo('test_photo')
def test_instance_method_send_media_group(self, monkeypatch, user):
@ -212,10 +216,10 @@ class TestUser:
assert check_shortcut_signature(
User.send_media_group, Bot.send_media_group, ['chat_id'], []
)
assert check_shortcut_call(user.send_media_group, user.bot, 'send_media_group')
assert check_defaults_handling(user.send_media_group, user.bot)
assert check_shortcut_call(user.send_media_group, user.get_bot(), 'send_media_group')
assert check_defaults_handling(user.send_media_group, user.get_bot())
monkeypatch.setattr(user.bot, 'send_media_group', make_assertion)
monkeypatch.setattr(user.get_bot(), 'send_media_group', make_assertion)
assert user.send_media_group('test_media_group')
def test_instance_method_send_audio(self, monkeypatch, user):
@ -223,10 +227,10 @@ class TestUser:
return kwargs['chat_id'] == user.id and kwargs['audio'] == 'test_audio'
assert check_shortcut_signature(User.send_audio, Bot.send_audio, ['chat_id'], [])
assert check_shortcut_call(user.send_audio, user.bot, 'send_audio')
assert check_defaults_handling(user.send_audio, user.bot)
assert check_shortcut_call(user.send_audio, user.get_bot(), 'send_audio')
assert check_defaults_handling(user.send_audio, user.get_bot())
monkeypatch.setattr(user.bot, 'send_audio', make_assertion)
monkeypatch.setattr(user.get_bot(), 'send_audio', make_assertion)
assert user.send_audio('test_audio')
def test_instance_method_send_chat_action(self, monkeypatch, user):
@ -236,10 +240,10 @@ class TestUser:
assert check_shortcut_signature(
User.send_chat_action, Bot.send_chat_action, ['chat_id'], []
)
assert check_shortcut_call(user.send_chat_action, user.bot, 'send_chat_action')
assert check_defaults_handling(user.send_chat_action, user.bot)
assert check_shortcut_call(user.send_chat_action, user.get_bot(), 'send_chat_action')
assert check_defaults_handling(user.send_chat_action, user.get_bot())
monkeypatch.setattr(user.bot, 'send_chat_action', make_assertion)
monkeypatch.setattr(user.get_bot(), 'send_chat_action', make_assertion)
assert user.send_chat_action('test_chat_action')
def test_instance_method_send_contact(self, monkeypatch, user):
@ -247,10 +251,10 @@ class TestUser:
return kwargs['chat_id'] == user.id and kwargs['phone_number'] == 'test_contact'
assert check_shortcut_signature(User.send_contact, Bot.send_contact, ['chat_id'], [])
assert check_shortcut_call(user.send_contact, user.bot, 'send_contact')
assert check_defaults_handling(user.send_contact, user.bot)
assert check_shortcut_call(user.send_contact, user.get_bot(), 'send_contact')
assert check_defaults_handling(user.send_contact, user.get_bot())
monkeypatch.setattr(user.bot, 'send_contact', make_assertion)
monkeypatch.setattr(user.get_bot(), 'send_contact', make_assertion)
assert user.send_contact(phone_number='test_contact')
def test_instance_method_send_dice(self, monkeypatch, user):
@ -258,10 +262,10 @@ class TestUser:
return kwargs['chat_id'] == user.id and kwargs['emoji'] == 'test_dice'
assert check_shortcut_signature(User.send_dice, Bot.send_dice, ['chat_id'], [])
assert check_shortcut_call(user.send_dice, user.bot, 'send_dice')
assert check_defaults_handling(user.send_dice, user.bot)
assert check_shortcut_call(user.send_dice, user.get_bot(), 'send_dice')
assert check_defaults_handling(user.send_dice, user.get_bot())
monkeypatch.setattr(user.bot, 'send_dice', make_assertion)
monkeypatch.setattr(user.get_bot(), 'send_dice', make_assertion)
assert user.send_dice(emoji='test_dice')
def test_instance_method_send_document(self, monkeypatch, user):
@ -269,10 +273,10 @@ class TestUser:
return kwargs['chat_id'] == user.id and kwargs['document'] == 'test_document'
assert check_shortcut_signature(User.send_document, Bot.send_document, ['chat_id'], [])
assert check_shortcut_call(user.send_document, user.bot, 'send_document')
assert check_defaults_handling(user.send_document, user.bot)
assert check_shortcut_call(user.send_document, user.get_bot(), 'send_document')
assert check_defaults_handling(user.send_document, user.get_bot())
monkeypatch.setattr(user.bot, 'send_document', make_assertion)
monkeypatch.setattr(user.get_bot(), 'send_document', make_assertion)
assert user.send_document('test_document')
def test_instance_method_send_game(self, monkeypatch, user):
@ -280,10 +284,10 @@ class TestUser:
return kwargs['chat_id'] == user.id and kwargs['game_short_name'] == 'test_game'
assert check_shortcut_signature(User.send_game, Bot.send_game, ['chat_id'], [])
assert check_shortcut_call(user.send_game, user.bot, 'send_game')
assert check_defaults_handling(user.send_game, user.bot)
assert check_shortcut_call(user.send_game, user.get_bot(), 'send_game')
assert check_defaults_handling(user.send_game, user.get_bot())
monkeypatch.setattr(user.bot, 'send_game', make_assertion)
monkeypatch.setattr(user.get_bot(), 'send_game', make_assertion)
assert user.send_game(game_short_name='test_game')
def test_instance_method_send_invoice(self, monkeypatch, user):
@ -298,10 +302,10 @@ class TestUser:
return kwargs['chat_id'] == user.id and args
assert check_shortcut_signature(User.send_invoice, Bot.send_invoice, ['chat_id'], [])
assert check_shortcut_call(user.send_invoice, user.bot, 'send_invoice')
assert check_defaults_handling(user.send_invoice, user.bot)
assert check_shortcut_call(user.send_invoice, user.get_bot(), 'send_invoice')
assert check_defaults_handling(user.send_invoice, user.get_bot())
monkeypatch.setattr(user.bot, 'send_invoice', make_assertion)
monkeypatch.setattr(user.get_bot(), 'send_invoice', make_assertion)
assert user.send_invoice(
'title',
'description',
@ -316,10 +320,10 @@ class TestUser:
return kwargs['chat_id'] == user.id and kwargs['latitude'] == 'test_location'
assert check_shortcut_signature(User.send_location, Bot.send_location, ['chat_id'], [])
assert check_shortcut_call(user.send_location, user.bot, 'send_location')
assert check_defaults_handling(user.send_location, user.bot)
assert check_shortcut_call(user.send_location, user.get_bot(), 'send_location')
assert check_defaults_handling(user.send_location, user.get_bot())
monkeypatch.setattr(user.bot, 'send_location', make_assertion)
monkeypatch.setattr(user.get_bot(), 'send_location', make_assertion)
assert user.send_location('test_location')
def test_instance_method_send_sticker(self, monkeypatch, user):
@ -327,10 +331,10 @@ class TestUser:
return kwargs['chat_id'] == user.id and kwargs['sticker'] == 'test_sticker'
assert check_shortcut_signature(User.send_sticker, Bot.send_sticker, ['chat_id'], [])
assert check_shortcut_call(user.send_sticker, user.bot, 'send_sticker')
assert check_defaults_handling(user.send_sticker, user.bot)
assert check_shortcut_call(user.send_sticker, user.get_bot(), 'send_sticker')
assert check_defaults_handling(user.send_sticker, user.get_bot())
monkeypatch.setattr(user.bot, 'send_sticker', make_assertion)
monkeypatch.setattr(user.get_bot(), 'send_sticker', make_assertion)
assert user.send_sticker('test_sticker')
def test_instance_method_send_video(self, monkeypatch, user):
@ -338,10 +342,10 @@ class TestUser:
return kwargs['chat_id'] == user.id and kwargs['video'] == 'test_video'
assert check_shortcut_signature(User.send_video, Bot.send_video, ['chat_id'], [])
assert check_shortcut_call(user.send_video, user.bot, 'send_video')
assert check_defaults_handling(user.send_video, user.bot)
assert check_shortcut_call(user.send_video, user.get_bot(), 'send_video')
assert check_defaults_handling(user.send_video, user.get_bot())
monkeypatch.setattr(user.bot, 'send_video', make_assertion)
monkeypatch.setattr(user.get_bot(), 'send_video', make_assertion)
assert user.send_video('test_video')
def test_instance_method_send_venue(self, monkeypatch, user):
@ -349,10 +353,10 @@ class TestUser:
return kwargs['chat_id'] == user.id and kwargs['title'] == 'test_venue'
assert check_shortcut_signature(User.send_venue, Bot.send_venue, ['chat_id'], [])
assert check_shortcut_call(user.send_venue, user.bot, 'send_venue')
assert check_defaults_handling(user.send_venue, user.bot)
assert check_shortcut_call(user.send_venue, user.get_bot(), 'send_venue')
assert check_defaults_handling(user.send_venue, user.get_bot())
monkeypatch.setattr(user.bot, 'send_venue', make_assertion)
monkeypatch.setattr(user.get_bot(), 'send_venue', make_assertion)
assert user.send_venue(title='test_venue')
def test_instance_method_send_video_note(self, monkeypatch, user):
@ -360,10 +364,10 @@ class TestUser:
return kwargs['chat_id'] == user.id and kwargs['video_note'] == 'test_video_note'
assert check_shortcut_signature(User.send_video_note, Bot.send_video_note, ['chat_id'], [])
assert check_shortcut_call(user.send_video_note, user.bot, 'send_video_note')
assert check_defaults_handling(user.send_video_note, user.bot)
assert check_shortcut_call(user.send_video_note, user.get_bot(), 'send_video_note')
assert check_defaults_handling(user.send_video_note, user.get_bot())
monkeypatch.setattr(user.bot, 'send_video_note', make_assertion)
monkeypatch.setattr(user.get_bot(), 'send_video_note', make_assertion)
assert user.send_video_note('test_video_note')
def test_instance_method_send_voice(self, monkeypatch, user):
@ -371,10 +375,10 @@ class TestUser:
return kwargs['chat_id'] == user.id and kwargs['voice'] == 'test_voice'
assert check_shortcut_signature(User.send_voice, Bot.send_voice, ['chat_id'], [])
assert check_shortcut_call(user.send_voice, user.bot, 'send_voice')
assert check_defaults_handling(user.send_voice, user.bot)
assert check_shortcut_call(user.send_voice, user.get_bot(), 'send_voice')
assert check_defaults_handling(user.send_voice, user.get_bot())
monkeypatch.setattr(user.bot, 'send_voice', make_assertion)
monkeypatch.setattr(user.get_bot(), 'send_voice', make_assertion)
assert user.send_voice('test_voice')
def test_instance_method_send_animation(self, monkeypatch, user):
@ -382,10 +386,10 @@ class TestUser:
return kwargs['chat_id'] == user.id and kwargs['animation'] == 'test_animation'
assert check_shortcut_signature(User.send_animation, Bot.send_animation, ['chat_id'], [])
assert check_shortcut_call(user.send_animation, user.bot, 'send_animation')
assert check_defaults_handling(user.send_animation, user.bot)
assert check_shortcut_call(user.send_animation, user.get_bot(), 'send_animation')
assert check_defaults_handling(user.send_animation, user.get_bot())
monkeypatch.setattr(user.bot, 'send_animation', make_assertion)
monkeypatch.setattr(user.get_bot(), 'send_animation', make_assertion)
assert user.send_animation('test_animation')
def test_instance_method_send_poll(self, monkeypatch, user):
@ -393,10 +397,10 @@ class TestUser:
return kwargs['chat_id'] == user.id and kwargs['question'] == 'test_poll'
assert check_shortcut_signature(User.send_poll, Bot.send_poll, ['chat_id'], [])
assert check_shortcut_call(user.send_poll, user.bot, 'send_poll')
assert check_defaults_handling(user.send_poll, user.bot)
assert check_shortcut_call(user.send_poll, user.get_bot(), 'send_poll')
assert check_defaults_handling(user.send_poll, user.get_bot())
monkeypatch.setattr(user.bot, 'send_poll', make_assertion)
monkeypatch.setattr(user.get_bot(), 'send_poll', make_assertion)
assert user.send_poll(question='test_poll', options=[1, 2])
def test_instance_method_send_copy(self, monkeypatch, user):
@ -407,10 +411,10 @@ class TestUser:
return from_chat_id and message_id and user_id
assert check_shortcut_signature(User.send_copy, Bot.copy_message, ['chat_id'], [])
assert check_shortcut_call(user.copy_message, user.bot, 'copy_message')
assert check_defaults_handling(user.copy_message, user.bot)
assert check_shortcut_call(user.copy_message, user.get_bot(), 'copy_message')
assert check_defaults_handling(user.copy_message, user.get_bot())
monkeypatch.setattr(user.bot, 'copy_message', make_assertion)
monkeypatch.setattr(user.get_bot(), 'copy_message', make_assertion)
assert user.send_copy(from_chat_id='from_chat_id', message_id='message_id')
def test_instance_method_copy_message(self, monkeypatch, user):
@ -421,10 +425,10 @@ class TestUser:
return chat_id and message_id and user_id
assert check_shortcut_signature(User.copy_message, Bot.copy_message, ['from_chat_id'], [])
assert check_shortcut_call(user.copy_message, user.bot, 'copy_message')
assert check_defaults_handling(user.copy_message, user.bot)
assert check_shortcut_call(user.copy_message, user.get_bot(), 'copy_message')
assert check_defaults_handling(user.copy_message, user.get_bot())
monkeypatch.setattr(user.bot, 'copy_message', make_assertion)
monkeypatch.setattr(user.get_bot(), 'copy_message', make_assertion)
assert user.copy_message(chat_id='chat_id', message_id='message_id')
def test_instance_method_approve_join_request(self, monkeypatch, user):
@ -437,11 +441,11 @@ class TestUser:
User.approve_join_request, Bot.approve_chat_join_request, ['user_id'], []
)
assert check_shortcut_call(
user.approve_join_request, user.bot, 'approve_chat_join_request'
user.approve_join_request, user.get_bot(), 'approve_chat_join_request'
)
assert check_defaults_handling(user.approve_join_request, user.bot)
assert check_defaults_handling(user.approve_join_request, user.get_bot())
monkeypatch.setattr(user.bot, 'approve_chat_join_request', make_assertion)
monkeypatch.setattr(user.get_bot(), 'approve_chat_join_request', make_assertion)
assert user.approve_join_request(chat_id='chat_id')
def test_instance_method_decline_join_request(self, monkeypatch, user):
@ -454,11 +458,11 @@ class TestUser:
User.decline_join_request, Bot.decline_chat_join_request, ['user_id'], []
)
assert check_shortcut_call(
user.decline_join_request, user.bot, 'decline_chat_join_request'
user.decline_join_request, user.get_bot(), 'decline_chat_join_request'
)
assert check_defaults_handling(user.decline_join_request, user.bot)
assert check_defaults_handling(user.decline_join_request, user.get_bot())
monkeypatch.setattr(user.bot, 'decline_chat_join_request', make_assertion)
monkeypatch.setattr(user.get_bot(), 'decline_chat_join_request', make_assertion)
assert user.decline_join_request(chat_id='chat_id')
def test_mention_html(self, user):

View file

@ -335,10 +335,10 @@ class TestVideo:
return kwargs['file_id'] == video.file_id
assert check_shortcut_signature(Video.get_file, Bot.get_file, ['file_id'], [])
assert check_shortcut_call(video.get_file, video.bot, 'get_file')
assert check_defaults_handling(video.get_file, video.bot)
assert check_shortcut_call(video.get_file, video.get_bot(), 'get_file')
assert check_defaults_handling(video.get_file, video.get_bot())
monkeypatch.setattr(video.bot, 'get_file', make_assertion)
monkeypatch.setattr(video.get_bot(), 'get_file', make_assertion)
assert video.get_file()
def test_equality(self, video):

View file

@ -238,10 +238,10 @@ class TestVideoNote:
return kwargs['file_id'] == video_note.file_id
assert check_shortcut_signature(VideoNote.get_file, Bot.get_file, ['file_id'], [])
assert check_shortcut_call(video_note.get_file, video_note.bot, 'get_file')
assert check_defaults_handling(video_note.get_file, video_note.bot)
assert check_shortcut_call(video_note.get_file, video_note.get_bot(), 'get_file')
assert check_defaults_handling(video_note.get_file, video_note.get_bot())
monkeypatch.setattr(video_note.bot, 'get_file', make_assertion)
monkeypatch.setattr(video_note.get_bot(), 'get_file', make_assertion)
assert video_note.get_file()
def test_equality(self, video_note):

View file

@ -288,10 +288,10 @@ class TestVoice:
return kwargs['file_id'] == voice.file_id
assert check_shortcut_signature(Voice.get_file, Bot.get_file, ['file_id'], [])
assert check_shortcut_call(voice.get_file, voice.bot, 'get_file')
assert check_defaults_handling(voice.get_file, voice.bot)
assert check_shortcut_call(voice.get_file, voice.get_bot(), 'get_file')
assert check_defaults_handling(voice.get_file, voice.get_bot())
monkeypatch.setattr(voice.bot, 'get_file', make_assertion)
monkeypatch.setattr(voice.get_bot(), 'get_file', make_assertion)
assert voice.get_file()
def test_equality(self, voice):