mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2025-03-16 20:29:55 +01:00
Class methods (#362)
* bot.py: add create_references method * create bot reference in webhook handler, use create_references on new updates * message.py: implement reply_text * echobot2.py: use Message.reply_text * fix create_references in webhook handler * add some more instance methods * Chat.kick_member and unban_member * bot.py: Create bot references in outgoing messages * add tests for everything testable * test_updater.py: add create_references method to MockBot * remove Bot.create_references and refactor TelegramObject.de_json to take the additional parameter bot * List bot as named kwarg where used * file.py: Use Bot.request property instead of Bot._request attr
This commit is contained in:
parent
1f597c6b4a
commit
5116a77221
106 changed files with 690 additions and 379 deletions
|
@ -29,15 +29,15 @@ logger = logging.getLogger(__name__)
|
|||
# Define a few command handlers. These usually take the two arguments bot and
|
||||
# update. Error handlers also receive the raised TelegramError object in error.
|
||||
def start(bot, update):
|
||||
bot.sendMessage(update.message.chat_id, text='Hi!')
|
||||
update.message.reply_text('Hi!')
|
||||
|
||||
|
||||
def help(bot, update):
|
||||
bot.sendMessage(update.message.chat_id, text='Help!')
|
||||
update.message.reply_text('Help!')
|
||||
|
||||
|
||||
def echo(bot, update):
|
||||
bot.sendMessage(update.message.chat_id, text=update.message.text)
|
||||
update.message.reply_text(update.message.text)
|
||||
|
||||
|
||||
def error(bot, update, error):
|
||||
|
|
|
@ -55,10 +55,11 @@ class Audio(TelegramObject):
|
|||
self.file_size = int(kwargs.get('file_size', 0))
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
def de_json(data, bot):
|
||||
"""
|
||||
Args:
|
||||
data (str):
|
||||
data (dict):
|
||||
bot (telegram.Bot):
|
||||
|
||||
Returns:
|
||||
telegram.Audio:
|
||||
|
|
|
@ -38,13 +38,14 @@ class TelegramObject(object):
|
|||
return self.__dict__[item]
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
def de_json(data, bot):
|
||||
"""
|
||||
Args:
|
||||
data (str):
|
||||
data (dict):
|
||||
bot (telegram.Bot):
|
||||
|
||||
Returns:
|
||||
telegram.TelegramObject:
|
||||
dict:
|
||||
"""
|
||||
if not data:
|
||||
return None
|
||||
|
@ -68,6 +69,9 @@ class TelegramObject(object):
|
|||
data = dict()
|
||||
|
||||
for key in iter(self.__dict__):
|
||||
if key == 'bot':
|
||||
continue
|
||||
|
||||
value = self.__dict__[key]
|
||||
if value is not None:
|
||||
if hasattr(value, 'to_dict'):
|
||||
|
|
|
@ -154,7 +154,7 @@ class Bot(TelegramObject):
|
|||
if result is True:
|
||||
return result
|
||||
|
||||
return Message.de_json(result)
|
||||
return Message.de_json(result, self)
|
||||
|
||||
return decorator
|
||||
|
||||
|
@ -176,7 +176,7 @@ class Bot(TelegramObject):
|
|||
|
||||
result = self._request.get(url)
|
||||
|
||||
self.bot = User.de_json(result)
|
||||
self.bot = User.de_json(result, self)
|
||||
|
||||
return self.bot
|
||||
|
||||
|
@ -860,7 +860,7 @@ class Bot(TelegramObject):
|
|||
|
||||
result = self._request.post(url, data, timeout=kwargs.get('timeout'))
|
||||
|
||||
return UserProfilePhotos.de_json(result)
|
||||
return UserProfilePhotos.de_json(result, self)
|
||||
|
||||
@log
|
||||
def getFile(self, file_id, **kwargs):
|
||||
|
@ -894,7 +894,7 @@ class Bot(TelegramObject):
|
|||
if result.get('file_path'):
|
||||
result['file_path'] = '%s/%s' % (self.base_file_url, result['file_path'])
|
||||
|
||||
return File.de_json(result, self._request)
|
||||
return File.de_json(result, self)
|
||||
|
||||
@log
|
||||
def kickChatMember(self, chat_id, user_id, **kwargs):
|
||||
|
@ -1225,7 +1225,7 @@ class Bot(TelegramObject):
|
|||
else:
|
||||
self.logger.debug('No new updates found.')
|
||||
|
||||
return [Update.de_json(x) for x in result]
|
||||
return [Update.de_json(u, self) for u in result]
|
||||
|
||||
@log
|
||||
def setWebhook(self, webhook_url=None, certificate=None, **kwargs):
|
||||
|
@ -1325,7 +1325,7 @@ class Bot(TelegramObject):
|
|||
|
||||
result = self._request.post(url, data, timeout=kwargs.get('timeout'))
|
||||
|
||||
return Chat.de_json(result)
|
||||
return Chat.de_json(result, self)
|
||||
|
||||
@log
|
||||
def getChatAdministrators(self, chat_id, **kwargs):
|
||||
|
@ -1360,7 +1360,7 @@ class Bot(TelegramObject):
|
|||
|
||||
result = self._request.post(url, data, timeout=kwargs.get('timeout'))
|
||||
|
||||
return [ChatMember.de_json(x) for x in result]
|
||||
return [ChatMember.de_json(x, self) for x in result]
|
||||
|
||||
@log
|
||||
def getChatMembersCount(self, chat_id, **kwargs):
|
||||
|
@ -1423,11 +1423,11 @@ class Bot(TelegramObject):
|
|||
|
||||
result = self._request.post(url, data, timeout=kwargs.get('timeout'))
|
||||
|
||||
return ChatMember.de_json(result)
|
||||
return ChatMember.de_json(result, self)
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
data = super(Bot, Bot).de_json(data)
|
||||
def de_json(data, bot):
|
||||
data = super(Bot, Bot).de_json(data, bot)
|
||||
|
||||
return Bot(**data)
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ from telegram import TelegramObject, Message, User
|
|||
class CallbackQuery(TelegramObject):
|
||||
"""This object represents a Telegram CallbackQuery."""
|
||||
|
||||
def __init__(self, id, from_user, data, **kwargs):
|
||||
def __init__(self, id, from_user, data, bot=None, **kwargs):
|
||||
# Required
|
||||
self.id = id
|
||||
self.from_user = from_user
|
||||
|
@ -34,15 +34,26 @@ class CallbackQuery(TelegramObject):
|
|||
self.message = kwargs.get('message')
|
||||
self.inline_message_id = kwargs.get('inline_message_id', '')
|
||||
|
||||
self.bot = bot
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
def de_json(data, bot):
|
||||
"""
|
||||
Args:
|
||||
data (dict):
|
||||
bot (telegram.Bot):
|
||||
|
||||
Returns:
|
||||
telegram.CallbackQuery:
|
||||
"""
|
||||
|
||||
if not data:
|
||||
return None
|
||||
|
||||
data['from_user'] = User.de_json(data.get('from'))
|
||||
data['message'] = Message.de_json(data.get('message'))
|
||||
data['from_user'] = User.de_json(data.get('from'), bot)
|
||||
data['message'] = Message.de_json(data.get('message'), bot)
|
||||
|
||||
return CallbackQuery(**data)
|
||||
return CallbackQuery(bot=bot, **data)
|
||||
|
||||
def to_dict(self):
|
||||
"""
|
||||
|
@ -54,3 +65,7 @@ class CallbackQuery(TelegramObject):
|
|||
# Required
|
||||
data['from'] = data.pop('from_user', None)
|
||||
return data
|
||||
|
||||
def answer(self, *args, **kwargs):
|
||||
"""Shortcut for ``bot.answerCallbackQuery(update.callback_query.id, *args, **kwargs)``"""
|
||||
return self.bot.answerCallbackQuery(self.id, *args, **kwargs)
|
||||
|
|
|
@ -40,6 +40,7 @@ class Chat(TelegramObject):
|
|||
|
||||
Keyword Args:
|
||||
type (Optional[str]):
|
||||
bot (Optional[Bot]): The Bot to use for instance methods
|
||||
"""
|
||||
|
||||
PRIVATE = 'private'
|
||||
|
@ -47,7 +48,7 @@ class Chat(TelegramObject):
|
|||
SUPERGROUP = 'supergroup'
|
||||
CHANNEL = 'channel'
|
||||
|
||||
def __init__(self, id, type, **kwargs):
|
||||
def __init__(self, id, type, bot=None, **kwargs):
|
||||
# Required
|
||||
self.id = int(id)
|
||||
self.type = type
|
||||
|
@ -57,11 +58,14 @@ class Chat(TelegramObject):
|
|||
self.first_name = kwargs.get('first_name', '')
|
||||
self.last_name = kwargs.get('last_name', '')
|
||||
|
||||
self.bot = bot
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
def de_json(data, bot):
|
||||
"""
|
||||
Args:
|
||||
data (dict):
|
||||
bot (telegram.Bot):
|
||||
|
||||
Returns:
|
||||
telegram.Chat:
|
||||
|
@ -69,4 +73,32 @@ class Chat(TelegramObject):
|
|||
if not data:
|
||||
return None
|
||||
|
||||
return Chat(**data)
|
||||
return Chat(bot=bot, **data)
|
||||
|
||||
def send_action(self, *args, **kwargs):
|
||||
"""Shortcut for ``bot.sendChatAction(update.message.chat.id, *args, **kwargs)``"""
|
||||
return self.bot.sendChatAction(self.id, *args, **kwargs)
|
||||
|
||||
def leave(self, *args, **kwargs):
|
||||
"""Shortcut for ``bot.leaveChat(update.message.chat.id, *args, **kwargs)``"""
|
||||
return self.bot.leaveChat(self.id, *args, **kwargs)
|
||||
|
||||
def get_administrators(self, *args, **kwargs):
|
||||
"""Shortcut for ``bot.getChatAdministrators(update.message.chat.id, *args, **kwargs)``"""
|
||||
return self.bot.getChatAdministrators(self.id, *args, **kwargs)
|
||||
|
||||
def get_members_count(self, *args, **kwargs):
|
||||
"""Shortcut for ``bot.getChatMembersCount(update.message.chat.id, *args, **kwargs)``"""
|
||||
return self.bot.getChatMembersCount(self.id, *args, **kwargs)
|
||||
|
||||
def get_member(self, *args, **kwargs):
|
||||
"""Shortcut for ``bot.getChatMember(update.message.chat.id, *args, **kwargs)``"""
|
||||
return self.bot.getChatMember(self.id, *args, **kwargs)
|
||||
|
||||
def kick_member(self, *args, **kwargs):
|
||||
"""Shortcut for ``bot.kickChatMember(update.message.chat.id, *args, **kwargs)``"""
|
||||
return self.bot.kickChatMember(self.id, *args, **kwargs)
|
||||
|
||||
def unban_member(self, *args, **kwargs):
|
||||
"""Shortcut for ``bot.unbanChatMember(update.message.chat.id, *args, **kwargs)``"""
|
||||
return self.bot.unbanChatMember(self.id, *args, **kwargs)
|
||||
|
|
|
@ -46,10 +46,11 @@ class ChatMember(TelegramObject):
|
|||
self.status = status
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
def de_json(data, bot):
|
||||
"""
|
||||
Args:
|
||||
data (dict):
|
||||
bot (telegram.Bot):
|
||||
|
||||
Returns:
|
||||
telegram.ChatMember:
|
||||
|
@ -57,6 +58,6 @@ class ChatMember(TelegramObject):
|
|||
if not data:
|
||||
return None
|
||||
|
||||
data['user'] = User.de_json(data.get('user'))
|
||||
data['user'] = User.de_json(data.get('user'), bot)
|
||||
|
||||
return ChatMember(**data)
|
||||
|
|
|
@ -57,10 +57,11 @@ class ChosenInlineResult(TelegramObject):
|
|||
self.inline_message_id = inline_message_id
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
def de_json(data, bot):
|
||||
"""
|
||||
Args:
|
||||
data (dict):
|
||||
bot (telegram.Bot):
|
||||
|
||||
Returns:
|
||||
telegram.ChosenInlineResult:
|
||||
|
@ -69,9 +70,9 @@ class ChosenInlineResult(TelegramObject):
|
|||
return None
|
||||
|
||||
# Required
|
||||
data['from_user'] = User.de_json(data.pop('from'))
|
||||
data['from_user'] = User.de_json(data.pop('from'), bot)
|
||||
# Optionals
|
||||
data['location'] = Location.de_json(data.get('location'))
|
||||
data['location'] = Location.de_json(data.get('location'), bot)
|
||||
|
||||
return ChosenInlineResult(**data)
|
||||
|
||||
|
|
|
@ -49,10 +49,11 @@ class Contact(TelegramObject):
|
|||
self.user_id = int(kwargs.get('user_id', 0))
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
def de_json(data, bot):
|
||||
"""
|
||||
Args:
|
||||
data (str):
|
||||
data (dict):
|
||||
bot (telegram.Bot):
|
||||
|
||||
Returns:
|
||||
telegram.Contact:
|
||||
|
|
|
@ -52,10 +52,11 @@ class Document(TelegramObject):
|
|||
self.file_size = int(kwargs.get('file_size', 0))
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
def de_json(data, bot):
|
||||
"""
|
||||
Args:
|
||||
data (str):
|
||||
data (dict):
|
||||
bot (telegram.Bot):
|
||||
|
||||
Returns:
|
||||
telegram.Document:
|
||||
|
@ -63,6 +64,6 @@ class Document(TelegramObject):
|
|||
if not data:
|
||||
return None
|
||||
|
||||
data['thumb'] = PhotoSize.de_json(data.get('thumb'))
|
||||
data['thumb'] = PhotoSize.de_json(data.get('thumb'), bot)
|
||||
|
||||
return Document(**data)
|
||||
|
|
|
@ -274,7 +274,8 @@ class Updater(object):
|
|||
url_path = '/{0}'.format(url_path)
|
||||
|
||||
# Create and start server
|
||||
self.httpd = WebhookServer((listen, port), WebhookHandler, self.update_queue, url_path)
|
||||
self.httpd = WebhookServer((listen, port), WebhookHandler, self.update_queue, url_path,
|
||||
self.bot)
|
||||
|
||||
if use_ssl:
|
||||
self._check_ssl_cert(cert, key)
|
||||
|
|
|
@ -33,7 +33,7 @@ class File(TelegramObject):
|
|||
|
||||
Args:
|
||||
file_id (str):
|
||||
request (telegram.utils.request.Request):
|
||||
bot (telegram.Bot):
|
||||
**kwargs: Arbitrary keyword arguments.
|
||||
|
||||
Keyword Args:
|
||||
|
@ -42,29 +42,30 @@ class File(TelegramObject):
|
|||
|
||||
"""
|
||||
|
||||
def __init__(self, file_id, request, **kwargs):
|
||||
def __init__(self, file_id, bot, **kwargs):
|
||||
# Required
|
||||
self.file_id = str(file_id)
|
||||
self._request = request
|
||||
|
||||
# Optionals
|
||||
self.file_size = int(kwargs.get('file_size', 0))
|
||||
self.file_path = str(kwargs.get('file_path', ''))
|
||||
|
||||
self.bot = bot
|
||||
|
||||
@staticmethod
|
||||
def de_json(data, request):
|
||||
def de_json(data, bot):
|
||||
"""
|
||||
Args:
|
||||
data (dict):
|
||||
request (telegram.utils.request.Request):
|
||||
bot (telegram.Bot):
|
||||
|
||||
Returns:
|
||||
telegram.File:
|
||||
|
||||
"""
|
||||
if not data:
|
||||
return None
|
||||
|
||||
return File(request=request, **data)
|
||||
return File(bot=bot, **data)
|
||||
|
||||
def download(self, custom_path=None):
|
||||
"""
|
||||
|
@ -79,4 +80,4 @@ class File(TelegramObject):
|
|||
else:
|
||||
filename = basename(url)
|
||||
|
||||
self._request.download(url, filename)
|
||||
self.bot.request.download(url, filename)
|
||||
|
|
|
@ -43,10 +43,11 @@ class ForceReply(ReplyMarkup):
|
|||
self.selective = bool(kwargs.get('selective', False))
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
def de_json(data, bot):
|
||||
"""
|
||||
Args:
|
||||
data (str):
|
||||
data (dict):
|
||||
bot (telegram.Bot):
|
||||
|
||||
Returns:
|
||||
telegram.ForceReply:
|
||||
|
|
|
@ -52,8 +52,16 @@ class InlineKeyboardButton(TelegramObject):
|
|||
self.switch_inline_query = kwargs.get('switch_inline_query')
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
data = super(InlineKeyboardButton, InlineKeyboardButton).de_json(data)
|
||||
def de_json(data, bot):
|
||||
"""
|
||||
Args:
|
||||
data (dict):
|
||||
bot (telegram.Bot):
|
||||
|
||||
Returns:
|
||||
telegram.InlineKeyboardButton:
|
||||
"""
|
||||
data = super(InlineKeyboardButton, InlineKeyboardButton).de_json(data, bot)
|
||||
|
||||
if not data:
|
||||
return None
|
||||
|
@ -61,12 +69,12 @@ class InlineKeyboardButton(TelegramObject):
|
|||
return InlineKeyboardButton(**data)
|
||||
|
||||
@staticmethod
|
||||
def de_list(data):
|
||||
def de_list(data, bot):
|
||||
if not data:
|
||||
return []
|
||||
|
||||
inline_keyboards = list()
|
||||
for inline_keyboard in data:
|
||||
inline_keyboards.append(InlineKeyboardButton.de_json(inline_keyboard))
|
||||
inline_keyboards.append(InlineKeyboardButton.de_json(inline_keyboard, bot))
|
||||
|
||||
return inline_keyboards
|
||||
|
|
|
@ -38,13 +38,21 @@ class InlineKeyboardMarkup(ReplyMarkup):
|
|||
self.inline_keyboard = inline_keyboard
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
data = super(InlineKeyboardMarkup, InlineKeyboardMarkup).de_json(data)
|
||||
def de_json(data, bot):
|
||||
"""
|
||||
Args:
|
||||
data (dict):
|
||||
bot (telegram.Bot):
|
||||
|
||||
Returns:
|
||||
telegram.InlineKeyboardMarkup:
|
||||
"""
|
||||
data = super(InlineKeyboardMarkup, InlineKeyboardMarkup).de_json(data, bot)
|
||||
|
||||
if not data:
|
||||
return None
|
||||
|
||||
data['inline_keyboard'] = [InlineKeyboardButton.de_list(inline_keyboard)
|
||||
data['inline_keyboard'] = [InlineKeyboardButton.de_list(inline_keyboard, bot)
|
||||
for inline_keyboard in data['inline_keyboard']]
|
||||
|
||||
return InlineKeyboardMarkup(**data)
|
||||
|
|
|
@ -42,9 +42,10 @@ class InlineQuery(TelegramObject):
|
|||
|
||||
Keyword Args:
|
||||
location (optional[:class:`telegram.Location`]):
|
||||
bot (Optional[Bot]): The Bot to use for instance methods
|
||||
"""
|
||||
|
||||
def __init__(self, id, from_user, query, offset, **kwargs):
|
||||
def __init__(self, id, from_user, query, offset, bot=None, **kwargs):
|
||||
# Required
|
||||
self.id = id
|
||||
self.from_user = from_user
|
||||
|
@ -54,24 +55,27 @@ class InlineQuery(TelegramObject):
|
|||
# Optional
|
||||
self.location = kwargs.get('location')
|
||||
|
||||
self.bot = bot
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
def de_json(data, bot):
|
||||
"""
|
||||
Args:
|
||||
data (dict):
|
||||
bot (telegram.Bot):
|
||||
|
||||
Returns:
|
||||
telegram.InlineQuery:
|
||||
"""
|
||||
data = super(InlineQuery, InlineQuery).de_json(data)
|
||||
data = super(InlineQuery, InlineQuery).de_json(data, bot)
|
||||
|
||||
if not data:
|
||||
return None
|
||||
|
||||
data['from_user'] = User.de_json(data.get('from'))
|
||||
data['location'] = Location.de_json(data.get('location'))
|
||||
data['from_user'] = User.de_json(data.get('from'), bot)
|
||||
data['location'] = Location.de_json(data.get('location'), bot)
|
||||
|
||||
return InlineQuery(**data)
|
||||
return InlineQuery(bot=bot, **data)
|
||||
|
||||
def to_dict(self):
|
||||
"""
|
||||
|
@ -84,3 +88,7 @@ class InlineQuery(TelegramObject):
|
|||
data['from'] = data.pop('from_user', None)
|
||||
|
||||
return data
|
||||
|
||||
def answer(self, *args, **kwargs):
|
||||
"""Shortcut for ``bot.answerInlineQuery(update.inline_query.id, *args, **kwargs)``"""
|
||||
return self.bot.answerInlineQuery(self.id, *args, **kwargs)
|
||||
|
|
|
@ -35,11 +35,11 @@ class InlineQueryResult(TelegramObject):
|
|||
|
||||
"""
|
||||
|
||||
def __init__(self, type, id):
|
||||
def __init__(self, type, id, **kwargs):
|
||||
# Required
|
||||
self.type = str(type)
|
||||
self.id = str(id)
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
return super(InlineQueryResult, InlineQueryResult).de_json(data)
|
||||
def de_json(data, bot):
|
||||
return super(InlineQueryResult, InlineQueryResult).de_json(data, bot)
|
||||
|
|
|
@ -94,11 +94,11 @@ class InlineQueryResultArticle(InlineQueryResult):
|
|||
self.thumb_height = thumb_height
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
data = super(InlineQueryResultArticle, InlineQueryResultArticle).de_json(data)
|
||||
def de_json(data, bot):
|
||||
data = super(InlineQueryResultArticle, InlineQueryResultArticle).de_json(data, bot)
|
||||
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'))
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||
data['input_message_content'] = InputMessageContent.de_json(
|
||||
data.get('input_message_content'))
|
||||
data.get('input_message_content'), bot)
|
||||
|
||||
return InlineQueryResultArticle(**data)
|
||||
|
|
|
@ -84,11 +84,11 @@ class InlineQueryResultAudio(InlineQueryResult):
|
|||
self.input_message_content = input_message_content
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
data = super(InlineQueryResultAudio, InlineQueryResultAudio).de_json(data)
|
||||
def de_json(data, bot):
|
||||
data = super(InlineQueryResultAudio, InlineQueryResultAudio).de_json(data, bot)
|
||||
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'))
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||
data['input_message_content'] = InputMessageContent.de_json(
|
||||
data.get('input_message_content'))
|
||||
data.get('input_message_content'), bot)
|
||||
|
||||
return InlineQueryResultAudio(**data)
|
||||
|
|
|
@ -65,11 +65,11 @@ class InlineQueryResultCachedAudio(InlineQueryResult):
|
|||
self.input_message_content = input_message_content
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
data = super(InlineQueryResultCachedAudio, InlineQueryResultCachedAudio).de_json(data)
|
||||
def de_json(data, bot):
|
||||
data = super(InlineQueryResultCachedAudio, InlineQueryResultCachedAudio).de_json(data, bot)
|
||||
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'))
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||
data['input_message_content'] = InputMessageContent.de_json(
|
||||
data.get('input_message_content'))
|
||||
data.get('input_message_content'), bot)
|
||||
|
||||
return InlineQueryResultCachedAudio(**data)
|
||||
|
|
|
@ -49,12 +49,12 @@ class InlineQueryResultCachedDocument(InlineQueryResult):
|
|||
self.input_message_content = input_message_content
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
def de_json(data, bot):
|
||||
data = super(InlineQueryResultCachedDocument,
|
||||
InlineQueryResultCachedDocument).de_json(data)
|
||||
InlineQueryResultCachedDocument).de_json(data, bot)
|
||||
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'))
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||
data['input_message_content'] = InputMessageContent.de_json(
|
||||
data.get('input_message_content'))
|
||||
data.get('input_message_content'), bot)
|
||||
|
||||
return InlineQueryResultCachedDocument(**data)
|
||||
|
|
|
@ -47,11 +47,11 @@ class InlineQueryResultCachedGif(InlineQueryResult):
|
|||
self.input_message_content = input_message_content
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
data = super(InlineQueryResultCachedGif, InlineQueryResultCachedGif).de_json(data)
|
||||
def de_json(data, bot):
|
||||
data = super(InlineQueryResultCachedGif, InlineQueryResultCachedGif).de_json(data, bot)
|
||||
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'))
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||
data['input_message_content'] = InputMessageContent.de_json(
|
||||
data.get('input_message_content'))
|
||||
data.get('input_message_content'), bot)
|
||||
|
||||
return InlineQueryResultCachedGif(**data)
|
||||
|
|
|
@ -47,12 +47,12 @@ class InlineQueryResultCachedMpeg4Gif(InlineQueryResult):
|
|||
self.input_message_content = input_message_content
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
def de_json(data, bot):
|
||||
data = super(InlineQueryResultCachedMpeg4Gif,
|
||||
InlineQueryResultCachedMpeg4Gif).de_json(data)
|
||||
InlineQueryResultCachedMpeg4Gif).de_json(data, bot)
|
||||
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'))
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||
data['input_message_content'] = InputMessageContent.de_json(
|
||||
data.get('input_message_content'))
|
||||
data.get('input_message_content'), bot)
|
||||
|
||||
return InlineQueryResultCachedMpeg4Gif(**data)
|
||||
|
|
|
@ -50,11 +50,11 @@ class InlineQueryResultCachedPhoto(InlineQueryResult):
|
|||
self.input_message_content = input_message_content
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
data = super(InlineQueryResultCachedPhoto, InlineQueryResultCachedPhoto).de_json(data)
|
||||
def de_json(data, bot):
|
||||
data = super(InlineQueryResultCachedPhoto, InlineQueryResultCachedPhoto).de_json(data, bot)
|
||||
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'))
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||
data['input_message_content'] = InputMessageContent.de_json(
|
||||
data.get('input_message_content'))
|
||||
data.get('input_message_content'), bot)
|
||||
|
||||
return InlineQueryResultCachedPhoto(**data)
|
||||
|
|
|
@ -41,11 +41,12 @@ class InlineQueryResultCachedSticker(InlineQueryResult):
|
|||
self.input_message_content = input_message_content
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
data = super(InlineQueryResultCachedSticker, InlineQueryResultCachedSticker).de_json(data)
|
||||
def de_json(data, bot):
|
||||
data = super(InlineQueryResultCachedSticker,
|
||||
InlineQueryResultCachedSticker).de_json(data, bot)
|
||||
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'))
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||
data['input_message_content'] = InputMessageContent.de_json(
|
||||
data.get('input_message_content'))
|
||||
data.get('input_message_content'), bot)
|
||||
|
||||
return InlineQueryResultCachedSticker(**data)
|
||||
|
|
|
@ -49,11 +49,11 @@ class InlineQueryResultCachedVideo(InlineQueryResult):
|
|||
self.input_message_content = input_message_content
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
data = super(InlineQueryResultCachedVideo, InlineQueryResultCachedVideo).de_json(data)
|
||||
def de_json(data, bot):
|
||||
data = super(InlineQueryResultCachedVideo, InlineQueryResultCachedVideo).de_json(data, bot)
|
||||
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'))
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||
data['input_message_content'] = InputMessageContent.de_json(
|
||||
data.get('input_message_content'))
|
||||
data.get('input_message_content'), bot)
|
||||
|
||||
return InlineQueryResultCachedVideo(**data)
|
||||
|
|
|
@ -46,11 +46,11 @@ class InlineQueryResultCachedVoice(InlineQueryResult):
|
|||
self.input_message_content = input_message_content
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
data = super(InlineQueryResultCachedVoice, InlineQueryResultCachedVoice).de_json(data)
|
||||
def de_json(data, bot):
|
||||
data = super(InlineQueryResultCachedVoice, InlineQueryResultCachedVoice).de_json(data, bot)
|
||||
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'))
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||
data['input_message_content'] = InputMessageContent.de_json(
|
||||
data.get('input_message_content'))
|
||||
data.get('input_message_content'), bot)
|
||||
|
||||
return InlineQueryResultCachedVoice(**data)
|
||||
|
|
|
@ -55,11 +55,11 @@ class InlineQueryResultContact(InlineQueryResult):
|
|||
self.thumb_height = thumb_height
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
data = super(InlineQueryResultContact, InlineQueryResultContact).de_json(data)
|
||||
def de_json(data, bot):
|
||||
data = super(InlineQueryResultContact, InlineQueryResultContact).de_json(data, bot)
|
||||
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'))
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||
data['input_message_content'] = InputMessageContent.de_json(
|
||||
data.get('input_message_content'))
|
||||
data.get('input_message_content'), bot)
|
||||
|
||||
return InlineQueryResultContact(**data)
|
||||
|
|
|
@ -60,11 +60,11 @@ class InlineQueryResultDocument(InlineQueryResult):
|
|||
self.thumb_height = thumb_height
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
data = super(InlineQueryResultDocument, InlineQueryResultDocument).de_json(data)
|
||||
def de_json(data, bot):
|
||||
data = super(InlineQueryResultDocument, InlineQueryResultDocument).de_json(data, bot)
|
||||
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'))
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||
data['input_message_content'] = InputMessageContent.de_json(
|
||||
data.get('input_message_content'))
|
||||
data.get('input_message_content'), bot)
|
||||
|
||||
return InlineQueryResultDocument(**data)
|
||||
|
|
|
@ -56,11 +56,11 @@ class InlineQueryResultGif(InlineQueryResult):
|
|||
self.input_message_content = input_message_content
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
data = super(InlineQueryResultGif, InlineQueryResultGif).de_json(data)
|
||||
def de_json(data, bot):
|
||||
data = super(InlineQueryResultGif, InlineQueryResultGif).de_json(data, bot)
|
||||
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'))
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||
data['input_message_content'] = InputMessageContent.de_json(
|
||||
data.get('input_message_content'))
|
||||
data.get('input_message_content'), bot)
|
||||
|
||||
return InlineQueryResultGif(**data)
|
||||
|
|
|
@ -54,11 +54,11 @@ class InlineQueryResultLocation(InlineQueryResult):
|
|||
self.thumb_height = thumb_height
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
data = super(InlineQueryResultLocation, InlineQueryResultLocation).de_json(data)
|
||||
def de_json(data, bot):
|
||||
data = super(InlineQueryResultLocation, InlineQueryResultLocation).de_json(data, bot)
|
||||
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'))
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||
data['input_message_content'] = InputMessageContent.de_json(
|
||||
data.get('input_message_content'))
|
||||
data.get('input_message_content'), bot)
|
||||
|
||||
return InlineQueryResultLocation(**data)
|
||||
|
|
|
@ -56,11 +56,11 @@ class InlineQueryResultMpeg4Gif(InlineQueryResult):
|
|||
self.input_message_content = input_message_content
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
data = super(InlineQueryResultMpeg4Gif, InlineQueryResultMpeg4Gif).de_json(data)
|
||||
def de_json(data, bot):
|
||||
data = super(InlineQueryResultMpeg4Gif, InlineQueryResultMpeg4Gif).de_json(data, bot)
|
||||
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'))
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||
data['input_message_content'] = InputMessageContent.de_json(
|
||||
data.get('input_message_content'))
|
||||
data.get('input_message_content'), bot)
|
||||
|
||||
return InlineQueryResultMpeg4Gif(**data)
|
||||
|
|
|
@ -58,11 +58,11 @@ class InlineQueryResultPhoto(InlineQueryResult):
|
|||
self.input_message_content = input_message_content
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
data = super(InlineQueryResultPhoto, InlineQueryResultPhoto).de_json(data)
|
||||
def de_json(data, bot):
|
||||
data = super(InlineQueryResultPhoto, InlineQueryResultPhoto).de_json(data, bot)
|
||||
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'))
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||
data['input_message_content'] = InputMessageContent.de_json(
|
||||
data.get('input_message_content'))
|
||||
data.get('input_message_content'), bot)
|
||||
|
||||
return InlineQueryResultPhoto(**data)
|
||||
|
|
|
@ -60,11 +60,11 @@ class InlineQueryResultVenue(InlineQueryResult):
|
|||
self.thumb_height = thumb_height
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
data = super(InlineQueryResultVenue, InlineQueryResultVenue).de_json(data)
|
||||
def de_json(data, bot):
|
||||
data = super(InlineQueryResultVenue, InlineQueryResultVenue).de_json(data, bot)
|
||||
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'))
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||
data['input_message_content'] = InputMessageContent.de_json(
|
||||
data.get('input_message_content'))
|
||||
data.get('input_message_content'), bot)
|
||||
|
||||
return InlineQueryResultVenue(**data)
|
||||
|
|
|
@ -63,11 +63,11 @@ class InlineQueryResultVideo(InlineQueryResult):
|
|||
self.input_message_content = input_message_content
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
data = super(InlineQueryResultVideo, InlineQueryResultVideo).de_json(data)
|
||||
def de_json(data, bot):
|
||||
data = super(InlineQueryResultVideo, InlineQueryResultVideo).de_json(data, bot)
|
||||
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'))
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||
data['input_message_content'] = InputMessageContent.de_json(
|
||||
data.get('input_message_content'))
|
||||
data.get('input_message_content'), bot)
|
||||
|
||||
return InlineQueryResultVideo(**data)
|
||||
|
|
|
@ -47,11 +47,11 @@ class InlineQueryResultVoice(InlineQueryResult):
|
|||
self.input_message_content = input_message_content
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
data = super(InlineQueryResultVoice, InlineQueryResultVoice).de_json(data)
|
||||
def de_json(data, bot):
|
||||
data = super(InlineQueryResultVoice, InlineQueryResultVoice).de_json(data, bot)
|
||||
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'))
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||
data['input_message_content'] = InputMessageContent.de_json(
|
||||
data.get('input_message_content'))
|
||||
data.get('input_message_content'), bot)
|
||||
|
||||
return InlineQueryResultVoice(**data)
|
||||
|
|
|
@ -33,5 +33,5 @@ class InputContactMessageContent(InputMessageContent):
|
|||
self.last_name = last_name
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
def de_json(data, bot):
|
||||
return InputContactMessageContent(**data)
|
||||
|
|
|
@ -31,5 +31,5 @@ class InputLocationMessageContent(InputMessageContent):
|
|||
self.longitude = longitude
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
def de_json(data, bot):
|
||||
return InputLocationMessageContent(**data)
|
||||
|
|
|
@ -26,33 +26,33 @@ class InputMessageContent(TelegramObject):
|
|||
"""Base class for Telegram InputMessageContent Objects"""
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
data = super(InputMessageContent, InputMessageContent).de_json(data)
|
||||
def de_json(data, bot):
|
||||
data = super(InputMessageContent, InputMessageContent).de_json(data, bot)
|
||||
|
||||
if not data:
|
||||
return None
|
||||
|
||||
try:
|
||||
from telegram import InputTextMessageContent
|
||||
return InputTextMessageContent.de_json(data)
|
||||
return InputTextMessageContent.de_json(data, bot)
|
||||
except TypeError:
|
||||
pass
|
||||
|
||||
try:
|
||||
from telegram import InputVenueMessageContent
|
||||
return InputVenueMessageContent.de_json(data)
|
||||
return InputVenueMessageContent.de_json(data, bot)
|
||||
except TypeError:
|
||||
pass
|
||||
|
||||
try:
|
||||
from telegram import InputLocationMessageContent
|
||||
return InputLocationMessageContent.de_json(data)
|
||||
return InputLocationMessageContent.de_json(data, bot)
|
||||
except TypeError:
|
||||
pass
|
||||
|
||||
try:
|
||||
from telegram import InputContactMessageContent
|
||||
return InputContactMessageContent.de_json(data)
|
||||
return InputContactMessageContent.de_json(data, bot)
|
||||
except TypeError:
|
||||
pass
|
||||
|
||||
|
|
|
@ -33,5 +33,5 @@ class InputTextMessageContent(InputMessageContent):
|
|||
self.disable_web_page_preview = disable_web_page_preview
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
def de_json(data, bot):
|
||||
return InputTextMessageContent(**data)
|
||||
|
|
|
@ -35,5 +35,5 @@ class InputVenueMessageContent(InputMessageContent):
|
|||
self.foursquare_id = foursquare_id
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
def de_json(data, bot):
|
||||
return InputVenueMessageContent(**data)
|
||||
|
|
|
@ -43,19 +43,19 @@ class KeyboardButton(TelegramObject):
|
|||
self.request_location = request_location
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
def de_json(data, bot):
|
||||
if not data:
|
||||
return None
|
||||
|
||||
return KeyboardButton(**data)
|
||||
|
||||
@staticmethod
|
||||
def de_list(data):
|
||||
def de_list(data, bot):
|
||||
if not data:
|
||||
return []
|
||||
|
||||
keyboards = list()
|
||||
for keyboard in data:
|
||||
keyboards.append(KeyboardButton.de_json(keyboard))
|
||||
keyboards.append(KeyboardButton.de_json(keyboard, bot))
|
||||
|
||||
return keyboards
|
||||
|
|
|
@ -39,10 +39,11 @@ class Location(TelegramObject):
|
|||
self.latitude = float(latitude)
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
def de_json(data, bot):
|
||||
"""
|
||||
Args:
|
||||
data (str):
|
||||
data (dict):
|
||||
bot (telegram.Bot):
|
||||
|
||||
Returns:
|
||||
telegram.Location:
|
||||
|
|
|
@ -103,9 +103,10 @@ class Message(TelegramObject):
|
|||
migrate_to_chat_id (Optional[int]):
|
||||
migrate_from_chat_id (Optional[int]):
|
||||
channel_chat_created (Optional[bool]):
|
||||
bot (Optional[Bot]): The Bot to use for instance methods
|
||||
"""
|
||||
|
||||
def __init__(self, message_id, from_user, date, chat, **kwargs):
|
||||
def __init__(self, message_id, from_user, date, chat, bot=None, **kwargs):
|
||||
# Required
|
||||
self.message_id = int(message_id)
|
||||
self.from_user = from_user
|
||||
|
@ -141,16 +142,19 @@ class Message(TelegramObject):
|
|||
self.channel_chat_created = bool(kwargs.get('channel_chat_created', False))
|
||||
self.pinned_message = kwargs.get('pinned_message')
|
||||
|
||||
self.bot = bot
|
||||
|
||||
@property
|
||||
def chat_id(self):
|
||||
"""int: Short for :attr:`Message.chat.id`"""
|
||||
return self.chat.id
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
def de_json(data, bot):
|
||||
"""
|
||||
Args:
|
||||
data (dict):
|
||||
bot (telegram.Bot):
|
||||
|
||||
Returns:
|
||||
telegram.Message:
|
||||
|
@ -158,30 +162,30 @@ class Message(TelegramObject):
|
|||
if not data:
|
||||
return None
|
||||
|
||||
data['from_user'] = User.de_json(data.get('from'))
|
||||
data['from_user'] = User.de_json(data.get('from'), bot)
|
||||
data['date'] = datetime.fromtimestamp(data['date'])
|
||||
data['chat'] = Chat.de_json(data.get('chat'))
|
||||
data['entities'] = MessageEntity.de_list(data.get('entities'))
|
||||
data['forward_from'] = User.de_json(data.get('forward_from'))
|
||||
data['forward_from_chat'] = Chat.de_json(data.get('forward_from_chat'))
|
||||
data['chat'] = Chat.de_json(data.get('chat'), bot)
|
||||
data['entities'] = MessageEntity.de_list(data.get('entities'), bot)
|
||||
data['forward_from'] = User.de_json(data.get('forward_from'), bot)
|
||||
data['forward_from_chat'] = Chat.de_json(data.get('forward_from_chat'), bot)
|
||||
data['forward_date'] = Message._fromtimestamp(data.get('forward_date'))
|
||||
data['reply_to_message'] = Message.de_json(data.get('reply_to_message'))
|
||||
data['reply_to_message'] = Message.de_json(data.get('reply_to_message'), bot)
|
||||
data['edit_date'] = Message._fromtimestamp(data.get('edit_date'))
|
||||
data['audio'] = Audio.de_json(data.get('audio'))
|
||||
data['document'] = Document.de_json(data.get('document'))
|
||||
data['photo'] = PhotoSize.de_list(data.get('photo'))
|
||||
data['sticker'] = Sticker.de_json(data.get('sticker'))
|
||||
data['video'] = Video.de_json(data.get('video'))
|
||||
data['voice'] = Voice.de_json(data.get('voice'))
|
||||
data['contact'] = Contact.de_json(data.get('contact'))
|
||||
data['location'] = Location.de_json(data.get('location'))
|
||||
data['venue'] = Venue.de_json(data.get('venue'))
|
||||
data['new_chat_member'] = User.de_json(data.get('new_chat_member'))
|
||||
data['left_chat_member'] = User.de_json(data.get('left_chat_member'))
|
||||
data['new_chat_photo'] = PhotoSize.de_list(data.get('new_chat_photo'))
|
||||
data['pinned_message'] = Message.de_json(data.get('pinned_message'))
|
||||
data['audio'] = Audio.de_json(data.get('audio'), bot)
|
||||
data['document'] = Document.de_json(data.get('document'), bot)
|
||||
data['photo'] = PhotoSize.de_list(data.get('photo'), bot)
|
||||
data['sticker'] = Sticker.de_json(data.get('sticker'), bot)
|
||||
data['video'] = Video.de_json(data.get('video'), bot)
|
||||
data['voice'] = Voice.de_json(data.get('voice'), bot)
|
||||
data['contact'] = Contact.de_json(data.get('contact'), bot)
|
||||
data['location'] = Location.de_json(data.get('location'), bot)
|
||||
data['venue'] = Venue.de_json(data.get('venue'), bot)
|
||||
data['new_chat_member'] = User.de_json(data.get('new_chat_member'), bot)
|
||||
data['left_chat_member'] = User.de_json(data.get('left_chat_member'), bot)
|
||||
data['new_chat_photo'] = PhotoSize.de_list(data.get('new_chat_photo'), bot)
|
||||
data['pinned_message'] = Message.de_json(data.get('pinned_message'), bot)
|
||||
|
||||
return Message(**data)
|
||||
return Message(bot=bot, **data)
|
||||
|
||||
def __getitem__(self, item):
|
||||
if item in self.__dict__.keys():
|
||||
|
@ -246,6 +250,61 @@ class Message(TelegramObject):
|
|||
# Python 3 (< 3.3) and Python 2
|
||||
return int(mktime(dt_obj.timetuple()))
|
||||
|
||||
def reply_text(self, *args, **kwargs):
|
||||
"""Shortcut for ``bot.sendMessage(update.message.chat_id, *args, **kwargs)``"""
|
||||
return self.bot.sendMessage(self.chat_id, *args, **kwargs)
|
||||
|
||||
def reply_photo(self, *args, **kwargs):
|
||||
"""Shortcut for ``bot.sendPhoto(update.message.chat_id, *args, **kwargs)``"""
|
||||
return self.bot.sendPhoto(self.chat_id, *args, **kwargs)
|
||||
|
||||
def reply_audio(self, *args, **kwargs):
|
||||
"""Shortcut for ``bot.sendAudio(update.message.chat_id, *args, **kwargs)``"""
|
||||
return self.bot.sendAudio(self.chat_id, *args, **kwargs)
|
||||
|
||||
def reply_document(self, *args, **kwargs):
|
||||
"""Shortcut for ``bot.sendDocument(update.message.chat_id, *args, **kwargs)``"""
|
||||
return self.bot.sendDocument(self.chat_id, *args, **kwargs)
|
||||
|
||||
def reply_sticker(self, *args, **kwargs):
|
||||
"""Shortcut for ``bot.sendSticker(update.message.chat_id, *args, **kwargs)``"""
|
||||
return self.bot.sendSticker(self.chat_id, *args, **kwargs)
|
||||
|
||||
def reply_video(self, *args, **kwargs):
|
||||
"""Shortcut for ``bot.sendVideo(update.message.chat_id, *args, **kwargs)``"""
|
||||
return self.bot.sendVideo(self.chat_id, *args, **kwargs)
|
||||
|
||||
def reply_voice(self, *args, **kwargs):
|
||||
"""Shortcut for ``bot.sendVoice(update.message.chat_id, *args, **kwargs)``"""
|
||||
return self.bot.sendVoice(self.chat_id, *args, **kwargs)
|
||||
|
||||
def reply_location(self, *args, **kwargs):
|
||||
"""Shortcut for ``bot.sendLocation(update.message.chat_id, *args, **kwargs)``"""
|
||||
return self.bot.sendLocation(self.chat_id, *args, **kwargs)
|
||||
|
||||
def reply_venue(self, *args, **kwargs):
|
||||
"""Shortcut for ``bot.sendVenue(update.message.chat_id, *args, **kwargs)``"""
|
||||
return self.bot.sendVenue(self.chat_id, *args, **kwargs)
|
||||
|
||||
def reply_contact(self, *args, **kwargs):
|
||||
"""Shortcut for ``bot.sendContact(update.message.chat_id, *args, **kwargs)``"""
|
||||
return self.bot.sendContact(self.chat_id, *args, **kwargs)
|
||||
|
||||
def forward(self, chat_id, disable_notification=False):
|
||||
"""Shortcut for
|
||||
|
||||
bot.forwardMessage(chat_id=chat_id,
|
||||
from_chat_id=update.message.chat_id,
|
||||
disable_notification=disable_notification,
|
||||
message_id=update.message.message_id)
|
||||
|
||||
"""
|
||||
return self.bot.forwardMessage(
|
||||
chat_id=chat_id,
|
||||
from_chat_id=self.chat_id,
|
||||
disable_notification=disable_notification,
|
||||
message_id=self.message_id)
|
||||
|
||||
def parse_entity(self, entity):
|
||||
"""
|
||||
Returns the text from a given :class:`telegram.MessageEntity`.
|
||||
|
|
|
@ -44,15 +44,15 @@ class MessageEntity(TelegramObject):
|
|||
self.user = kwargs.get('user')
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
data = super(MessageEntity, MessageEntity).de_json(data)
|
||||
def de_json(data, bot):
|
||||
data = super(MessageEntity, MessageEntity).de_json(data, bot)
|
||||
|
||||
data['user'] = User.de_json(data.get('user'))
|
||||
data['user'] = User.de_json(data.get('user'), bot)
|
||||
|
||||
return MessageEntity(**data)
|
||||
|
||||
@staticmethod
|
||||
def de_list(data):
|
||||
def de_list(data, bot):
|
||||
"""
|
||||
Args:
|
||||
data (list):
|
||||
|
@ -65,7 +65,7 @@ class MessageEntity(TelegramObject):
|
|||
|
||||
entities = list()
|
||||
for entity in data:
|
||||
entities.append(MessageEntity.de_json(entity))
|
||||
entities.append(MessageEntity.de_json(entity, bot))
|
||||
|
||||
return entities
|
||||
|
||||
|
|
|
@ -55,10 +55,11 @@ class PhotoSize(TelegramObject):
|
|||
and self.height == other.height and self.file_size == other.file_size)
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
def de_json(data, bot):
|
||||
"""
|
||||
Args:
|
||||
data (str):
|
||||
data (dict):
|
||||
bot (telegram.Bot):
|
||||
|
||||
Returns:
|
||||
telegram.PhotoSize:
|
||||
|
@ -69,10 +70,11 @@ class PhotoSize(TelegramObject):
|
|||
return PhotoSize(**data)
|
||||
|
||||
@staticmethod
|
||||
def de_list(data):
|
||||
def de_list(data, bot):
|
||||
"""
|
||||
Args:
|
||||
data (list):
|
||||
bot (telegram.Bot):
|
||||
|
||||
Returns:
|
||||
List<telegram.PhotoSize>:
|
||||
|
@ -82,6 +84,6 @@ class PhotoSize(TelegramObject):
|
|||
|
||||
photos = list()
|
||||
for photo in data:
|
||||
photos.append(PhotoSize.de_json(photo))
|
||||
photos.append(PhotoSize.de_json(photo, bot))
|
||||
|
||||
return photos
|
||||
|
|
|
@ -44,10 +44,11 @@ class ReplyKeyboardHide(ReplyMarkup):
|
|||
self.selective = bool(kwargs.get('selective', False))
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
def de_json(data, bot):
|
||||
"""
|
||||
Args:
|
||||
data (str):
|
||||
data (dict):
|
||||
bot(telegram.Bot):
|
||||
|
||||
Returns:
|
||||
telegram.ReplyKeyboardHide:
|
||||
|
|
|
@ -50,10 +50,11 @@ class ReplyKeyboardMarkup(ReplyMarkup):
|
|||
self.selective = bool(kwargs.get('selective', False))
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
def de_json(data, bot):
|
||||
"""
|
||||
Args:
|
||||
data (str):
|
||||
data (dict):
|
||||
bot (telegram.Bot):
|
||||
|
||||
Returns:
|
||||
telegram.ReplyKeyboardMarkup:
|
||||
|
@ -61,7 +62,7 @@ class ReplyKeyboardMarkup(ReplyMarkup):
|
|||
if not data:
|
||||
return None
|
||||
|
||||
data['keyboard'] = [KeyboardButton.de_list(keyboard) for keyboard in data['keyboard']]
|
||||
data['keyboard'] = [KeyboardButton.de_list(keyboard, bot) for keyboard in data['keyboard']]
|
||||
|
||||
return ReplyKeyboardMarkup(**data)
|
||||
|
||||
|
|
|
@ -25,8 +25,8 @@ class ReplyMarkup(TelegramObject):
|
|||
"""Base class for Telegram ReplyMarkup Objects"""
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
data = super(ReplyMarkup, ReplyMarkup).de_json(data)
|
||||
def de_json(data, bot):
|
||||
data = super(ReplyMarkup, ReplyMarkup).de_json(data, bot)
|
||||
|
||||
if not data:
|
||||
return None
|
||||
|
|
|
@ -55,10 +55,11 @@ class Sticker(TelegramObject):
|
|||
self.file_size = int(kwargs.get('file_size', 0))
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
def de_json(data, bot):
|
||||
"""
|
||||
Args:
|
||||
data (str):
|
||||
data (dict):
|
||||
bot (telegram.Bot):
|
||||
|
||||
Returns:
|
||||
telegram.Sticker:
|
||||
|
@ -66,6 +67,6 @@ class Sticker(TelegramObject):
|
|||
if not data:
|
||||
return None
|
||||
|
||||
data['thumb'] = PhotoSize.de_json(data.get('thumb'))
|
||||
data['thumb'] = PhotoSize.de_json(data.get('thumb'), bot)
|
||||
|
||||
return Sticker(**data)
|
||||
|
|
|
@ -55,10 +55,11 @@ class Update(TelegramObject):
|
|||
self.callback_query = kwargs.get('callback_query')
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
def de_json(data, bot):
|
||||
"""
|
||||
Args:
|
||||
data (dict):
|
||||
bot (telegram.Bot):
|
||||
|
||||
Returns:
|
||||
telegram.Update:
|
||||
|
@ -66,10 +67,11 @@ class Update(TelegramObject):
|
|||
if not data:
|
||||
return None
|
||||
|
||||
data['message'] = Message.de_json(data.get('message'))
|
||||
data['edited_message'] = Message.de_json(data.get('edited_message'))
|
||||
data['inline_query'] = InlineQuery.de_json(data.get('inline_query'))
|
||||
data['chosen_inline_result'] = ChosenInlineResult.de_json(data.get('chosen_inline_result'))
|
||||
data['callback_query'] = CallbackQuery.de_json(data.get('callback_query'))
|
||||
data['message'] = Message.de_json(data.get('message'), bot)
|
||||
data['edited_message'] = Message.de_json(data.get('edited_message'), bot)
|
||||
data['inline_query'] = InlineQuery.de_json(data.get('inline_query'), bot)
|
||||
data['chosen_inline_result'] = ChosenInlineResult.de_json(
|
||||
data.get('chosen_inline_result'), bot)
|
||||
data['callback_query'] = CallbackQuery.de_json(data.get('callback_query'), bot)
|
||||
|
||||
return Update(**data)
|
||||
|
|
|
@ -41,9 +41,10 @@ class User(TelegramObject):
|
|||
type (Optional[str]):
|
||||
last_name (Optional[str]):
|
||||
username (Optional[str]):
|
||||
bot (Optional[Bot]): The Bot to use for instance methods
|
||||
"""
|
||||
|
||||
def __init__(self, id, first_name, **kwargs):
|
||||
def __init__(self, id, first_name, bot=None, **kwargs):
|
||||
# Required
|
||||
self.id = int(id)
|
||||
self.first_name = first_name
|
||||
|
@ -52,6 +53,8 @@ class User(TelegramObject):
|
|||
self.last_name = kwargs.get('last_name', '')
|
||||
self.username = kwargs.get('username', '')
|
||||
|
||||
self.bot = bot
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""str: """
|
||||
|
@ -62,10 +65,11 @@ class User(TelegramObject):
|
|||
return self.first_name
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
def de_json(data, bot):
|
||||
"""
|
||||
Args:
|
||||
data (str):
|
||||
data (dict):
|
||||
bot (telegram.Bot):
|
||||
|
||||
Returns:
|
||||
telegram.User:
|
||||
|
@ -73,4 +77,10 @@ class User(TelegramObject):
|
|||
if not data:
|
||||
return None
|
||||
|
||||
return User(**data)
|
||||
return User(bot=bot, **data)
|
||||
|
||||
def get_profile_photos(self, *args, **kwargs):
|
||||
"""
|
||||
Shortcut for ``bot.getUserProfilePhotos(update.message.from_user.id, *args, **kwargs)``
|
||||
"""
|
||||
return self.bot.getUserProfilePhotos(self.id, *args, **kwargs)
|
||||
|
|
|
@ -40,10 +40,11 @@ class UserProfilePhotos(TelegramObject):
|
|||
self.photos = photos
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
def de_json(data, bot):
|
||||
"""
|
||||
Args:
|
||||
data (str):
|
||||
data (dict):
|
||||
bot (telegram.Bot):
|
||||
|
||||
Returns:
|
||||
telegram.UserProfilePhotos:
|
||||
|
@ -51,7 +52,7 @@ class UserProfilePhotos(TelegramObject):
|
|||
if not data:
|
||||
return None
|
||||
|
||||
data['photos'] = [PhotoSize.de_list(photo) for photo in data['photos']]
|
||||
data['photos'] = [PhotoSize.de_list(photo, bot) for photo in data['photos']]
|
||||
|
||||
return UserProfilePhotos(**data)
|
||||
|
||||
|
|
|
@ -24,11 +24,12 @@ class _InvalidPost(Exception):
|
|||
|
||||
class WebhookServer(BaseHTTPServer.HTTPServer, object):
|
||||
|
||||
def __init__(self, server_address, RequestHandlerClass, update_queue, webhook_path):
|
||||
def __init__(self, server_address, RequestHandlerClass, update_queue, webhook_path, bot):
|
||||
super(WebhookServer, self).__init__(server_address, RequestHandlerClass)
|
||||
self.logger = logging.getLogger(__name__)
|
||||
self.update_queue = update_queue
|
||||
self.webhook_path = webhook_path
|
||||
self.bot = bot
|
||||
self.is_running = False
|
||||
self.server_lock = Lock()
|
||||
self.shutdown_lock = Lock()
|
||||
|
@ -85,7 +86,8 @@ class WebhookHandler(BaseHTTPServer.BaseHTTPRequestHandler, object):
|
|||
|
||||
self.logger.debug('Webhook received data: ' + json_string)
|
||||
|
||||
update = Update.de_json(json.loads(json_string))
|
||||
update = Update.de_json(json.loads(json_string), self.server.bot)
|
||||
|
||||
self.logger.debug('Received Update with ID %d on Webhook' % update.update_id)
|
||||
self.server.update_queue.put(update)
|
||||
|
||||
|
|
|
@ -41,12 +41,12 @@ class Venue(TelegramObject):
|
|||
self.foursquare_id = foursquare_id
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
data = super(Venue, Venue).de_json(data)
|
||||
def de_json(data, bot):
|
||||
data = super(Venue, Venue).de_json(data, bot)
|
||||
|
||||
if not data:
|
||||
return None
|
||||
|
||||
data['location'] = Location.de_json(data.get('location'))
|
||||
data['location'] = Location.de_json(data.get('location'), bot)
|
||||
|
||||
return Venue(**data)
|
||||
|
|
|
@ -58,10 +58,11 @@ class Video(TelegramObject):
|
|||
self.file_size = int(kwargs.get('file_size', 0))
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
def de_json(data, bot):
|
||||
"""
|
||||
Args:
|
||||
data (str):
|
||||
data (dict):
|
||||
bot (telegram.Bot):
|
||||
|
||||
Returns:
|
||||
telegram.Video:
|
||||
|
@ -69,6 +70,6 @@ class Video(TelegramObject):
|
|||
if not data:
|
||||
return None
|
||||
|
||||
data['thumb'] = PhotoSize.de_json(data.get('thumb'))
|
||||
data['thumb'] = PhotoSize.de_json(data.get('thumb'), bot)
|
||||
|
||||
return Video(**data)
|
||||
|
|
|
@ -49,10 +49,11 @@ class Voice(TelegramObject):
|
|||
self.file_size = int(kwargs.get('file_size', 0))
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
def de_json(data, bot):
|
||||
"""
|
||||
Args:
|
||||
data (str):
|
||||
data (dict):
|
||||
bot (telegram.Bot)
|
||||
|
||||
Returns:
|
||||
telegram.Voice:
|
||||
|
|
|
@ -169,7 +169,7 @@ class AudioTest(BaseTest, unittest.TestCase):
|
|||
self.assertEqual(audio.mime_type, self.mime_type)
|
||||
|
||||
def test_audio_de_json(self):
|
||||
audio = telegram.Audio.de_json(self.json_dict)
|
||||
audio = telegram.Audio.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertEqual(audio.file_id, self.audio_file_id)
|
||||
self.assertEqual(audio.duration, self.duration)
|
||||
|
@ -179,12 +179,12 @@ class AudioTest(BaseTest, unittest.TestCase):
|
|||
self.assertEqual(audio.file_size, self.file_size)
|
||||
|
||||
def test_audio_to_json(self):
|
||||
audio = telegram.Audio.de_json(self.json_dict)
|
||||
audio = telegram.Audio.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertTrue(self.is_json(audio.to_json()))
|
||||
|
||||
def test_audio_to_dict(self):
|
||||
audio = telegram.Audio.de_json(self.json_dict)
|
||||
audio = telegram.Audio.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertTrue(self.is_dict(audio.to_dict()))
|
||||
self.assertEqual(audio['file_id'], self.audio_file_id)
|
||||
|
@ -230,6 +230,15 @@ class AudioTest(BaseTest, unittest.TestCase):
|
|||
TypeError,
|
||||
lambda: self._bot.sendAudio(chat_id=self._chat_id, **json_dict))
|
||||
|
||||
@flaky(3, 1)
|
||||
@timeout(10)
|
||||
def test_reply_audio(self):
|
||||
"""Test for Message.reply_audio"""
|
||||
message = self._bot.sendMessage(self._chat_id, '.')
|
||||
message = message.reply_audio(self.audio_file)
|
||||
|
||||
self.assertNotEqual(message.audio.file_id, '')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -20,6 +20,9 @@
|
|||
|
||||
import unittest
|
||||
import sys
|
||||
|
||||
from flaky import flaky
|
||||
|
||||
sys.path.append('.')
|
||||
|
||||
import telegram
|
||||
|
@ -37,30 +40,41 @@ class ChatTest(BaseTest, unittest.TestCase):
|
|||
self.json_dict = {'id': self.id, 'title': self.title, 'type': self.type}
|
||||
|
||||
def test_group_chat_de_json_empty_json(self):
|
||||
group_chat = telegram.Chat.de_json({})
|
||||
group_chat = telegram.Chat.de_json({}, self._bot)
|
||||
|
||||
self.assertEqual(group_chat, None)
|
||||
|
||||
def test_group_chat_de_json(self):
|
||||
group_chat = telegram.Chat.de_json(self.json_dict)
|
||||
group_chat = telegram.Chat.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertEqual(group_chat.id, self.id)
|
||||
self.assertEqual(group_chat.title, self.title)
|
||||
self.assertEqual(group_chat.type, self.type)
|
||||
|
||||
def test_group_chat_to_json(self):
|
||||
group_chat = telegram.Chat.de_json(self.json_dict)
|
||||
group_chat = telegram.Chat.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertTrue(self.is_json(group_chat.to_json()))
|
||||
|
||||
def test_group_chat_to_dict(self):
|
||||
group_chat = telegram.Chat.de_json(self.json_dict)
|
||||
group_chat = telegram.Chat.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertTrue(self.is_dict(group_chat.to_dict()))
|
||||
self.assertEqual(group_chat['id'], self.id)
|
||||
self.assertEqual(group_chat['title'], self.title)
|
||||
self.assertEqual(group_chat['type'], self.type)
|
||||
|
||||
@flaky(3, 1)
|
||||
def test_send_action(self):
|
||||
"""Test for Chat.send_action"""
|
||||
self.json_dict['id'] = self._chat_id
|
||||
group_chat = telegram.Chat.de_json(self.json_dict, self._bot)
|
||||
group_chat.bot = self._bot
|
||||
|
||||
result = group_chat.send_action(telegram.ChatAction.TYPING)
|
||||
|
||||
self.assertTrue(result)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -45,19 +45,19 @@ class ChosenInlineResultTest(BaseTest, unittest.TestCase):
|
|||
}
|
||||
|
||||
def test_choseninlineresult_de_json(self):
|
||||
result = telegram.ChosenInlineResult.de_json(self.json_dict)
|
||||
result = telegram.ChosenInlineResult.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertEqual(result.result_id, self.result_id)
|
||||
self.assertDictEqual(result.from_user.to_dict(), self.from_user.to_dict())
|
||||
self.assertEqual(result.query, self.query)
|
||||
|
||||
def test_choseninlineresult_to_json(self):
|
||||
result = telegram.ChosenInlineResult.de_json(self.json_dict)
|
||||
result = telegram.ChosenInlineResult.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertTrue(self.is_json(result.to_json()))
|
||||
|
||||
def test_choseninlineresult_to_dict(self):
|
||||
result = telegram.ChosenInlineResult.de_json(self.json_dict).to_dict()
|
||||
result = telegram.ChosenInlineResult.de_json(self.json_dict, self._bot).to_dict()
|
||||
|
||||
self.assertTrue(self.is_dict(result))
|
||||
self.assertEqual(result['result_id'], self.result_id)
|
||||
|
|
|
@ -20,6 +20,9 @@
|
|||
|
||||
import unittest
|
||||
import sys
|
||||
|
||||
from flaky import flaky
|
||||
|
||||
sys.path.append('.')
|
||||
|
||||
import telegram
|
||||
|
@ -43,7 +46,7 @@ class ContactTest(BaseTest, unittest.TestCase):
|
|||
}
|
||||
|
||||
def test_contact_de_json(self):
|
||||
contact = telegram.Contact.de_json(self.json_dict)
|
||||
contact = telegram.Contact.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertEqual(contact.phone_number, self.phone_number)
|
||||
self.assertEqual(contact.first_name, self.first_name)
|
||||
|
@ -51,12 +54,12 @@ class ContactTest(BaseTest, unittest.TestCase):
|
|||
self.assertEqual(contact.user_id, self.user_id)
|
||||
|
||||
def test_contact_to_json(self):
|
||||
contact = telegram.Contact.de_json(self.json_dict)
|
||||
contact = telegram.Contact.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertTrue(self.is_json(contact.to_json()))
|
||||
|
||||
def test_contact_to_dict(self):
|
||||
contact = telegram.Contact.de_json(self.json_dict)
|
||||
contact = telegram.Contact.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertTrue(self.is_dict(contact.to_dict()))
|
||||
self.assertEqual(contact['phone_number'], self.phone_number)
|
||||
|
@ -64,6 +67,15 @@ class ContactTest(BaseTest, unittest.TestCase):
|
|||
self.assertEqual(contact['last_name'], self.last_name)
|
||||
self.assertEqual(contact['user_id'], self.user_id)
|
||||
|
||||
@flaky(3, 1)
|
||||
def test_reply_contact(self):
|
||||
"""Test for Message.reply_contact"""
|
||||
message = self._bot.sendMessage(self._chat_id, '.')
|
||||
message = message.reply_contact(self.phone_number, self.first_name)
|
||||
|
||||
self.assertEqual(message.contact.phone_number, self.phone_number)
|
||||
self.assertEqual(message.contact.first_name, self.first_name)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -109,7 +109,7 @@ class DocumentTest(BaseTest, unittest.TestCase):
|
|||
self.assertEqual(document.mime_type, self.mime_type)
|
||||
|
||||
def test_document_de_json(self):
|
||||
document = telegram.Document.de_json(self.json_dict)
|
||||
document = telegram.Document.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertEqual(document.file_id, self.document_file_id)
|
||||
self.assertTrue(isinstance(document.thumb, telegram.PhotoSize))
|
||||
|
@ -118,12 +118,12 @@ class DocumentTest(BaseTest, unittest.TestCase):
|
|||
self.assertEqual(document.file_size, self.file_size)
|
||||
|
||||
def test_document_to_json(self):
|
||||
document = telegram.Document.de_json(self.json_dict)
|
||||
document = telegram.Document.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertTrue(self.is_json(document.to_json()))
|
||||
|
||||
def test_document_to_dict(self):
|
||||
document = telegram.Document.de_json(self.json_dict)
|
||||
document = telegram.Document.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertTrue(self.is_dict(document.to_dict()))
|
||||
self.assertEqual(document['file_id'], self.document_file_id)
|
||||
|
@ -167,6 +167,15 @@ class DocumentTest(BaseTest, unittest.TestCase):
|
|||
lambda: self._bot.sendDocument(chat_id=self._chat_id,
|
||||
**json_dict))
|
||||
|
||||
@flaky(3, 1)
|
||||
@timeout(10)
|
||||
def test_reply_document(self):
|
||||
"""Test for Message.reply_document"""
|
||||
message = self._bot.sendMessage(self._chat_id, '.')
|
||||
message = message.reply_document(self.document_file)
|
||||
|
||||
self.assertNotEqual(message.document.file_id, '')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -101,19 +101,19 @@ class FileTest(BaseTest, unittest.TestCase):
|
|||
self.assertTrue(os.path.isfile('telegram.ogg'))
|
||||
|
||||
def test_file_de_json(self):
|
||||
newFile = telegram.File.de_json(self.json_dict, None)
|
||||
newFile = telegram.File.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertEqual(newFile.file_id, self.json_dict['file_id'])
|
||||
self.assertEqual(newFile.file_path, self.json_dict['file_path'])
|
||||
self.assertEqual(newFile.file_size, self.json_dict['file_size'])
|
||||
|
||||
def test_file_to_json(self):
|
||||
newFile = telegram.File.de_json(self.json_dict, None)
|
||||
newFile = telegram.File.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertTrue(self.is_json(newFile.to_json()))
|
||||
|
||||
def test_file_to_dict(self):
|
||||
newFile = telegram.File.de_json(self.json_dict, None)
|
||||
newFile = telegram.File.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertTrue(self.is_dict(newFile.to_dict()))
|
||||
self.assertEqual(newFile['file_id'], self.json_dict['file_id'])
|
||||
|
|
|
@ -42,29 +42,29 @@ class ForceReplyTest(BaseTest, unittest.TestCase):
|
|||
message = self._bot.sendMessage(
|
||||
self._chat_id,
|
||||
'Моё судно на воздушной подушке полно угрей',
|
||||
reply_markup=telegram.ForceReply.de_json(self.json_dict))
|
||||
reply_markup=telegram.ForceReply.de_json(self.json_dict, self._bot))
|
||||
|
||||
self.assertTrue(self.is_json(message.to_json()))
|
||||
self.assertEqual(message.text, u'Моё судно на воздушной подушке полно угрей')
|
||||
|
||||
def test_force_reply_de_json(self):
|
||||
force_reply = telegram.ForceReply.de_json(self.json_dict)
|
||||
force_reply = telegram.ForceReply.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertEqual(force_reply.force_reply, self.force_reply)
|
||||
self.assertEqual(force_reply.selective, self.selective)
|
||||
|
||||
def test_force_reply_de_json_empty(self):
|
||||
force_reply = telegram.ForceReply.de_json(None)
|
||||
force_reply = telegram.ForceReply.de_json(None, self._bot)
|
||||
|
||||
self.assertFalse(force_reply)
|
||||
|
||||
def test_force_reply_to_json(self):
|
||||
force_reply = telegram.ForceReply.de_json(self.json_dict)
|
||||
force_reply = telegram.ForceReply.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertTrue(self.is_json(force_reply.to_json()))
|
||||
|
||||
def test_force_reply_to_dict(self):
|
||||
force_reply = telegram.ForceReply.de_json(self.json_dict)
|
||||
force_reply = telegram.ForceReply.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertEqual(force_reply['force_reply'], self.force_reply)
|
||||
self.assertEqual(force_reply['selective'], self.selective)
|
||||
|
|
|
@ -45,7 +45,7 @@ class InlineKeyboardButtonTest(BaseTest, unittest.TestCase):
|
|||
}
|
||||
|
||||
def test_inline_keyboard_button_de_json(self):
|
||||
inline_keyboard_button = telegram.InlineKeyboardButton.de_json(self.json_dict)
|
||||
inline_keyboard_button = telegram.InlineKeyboardButton.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertEqual(inline_keyboard_button.text, self.text)
|
||||
self.assertEqual(inline_keyboard_button.url, self.url)
|
||||
|
@ -53,22 +53,23 @@ class InlineKeyboardButtonTest(BaseTest, unittest.TestCase):
|
|||
self.assertEqual(inline_keyboard_button.switch_inline_query, self.switch_inline_query)
|
||||
|
||||
def test_inline_keyboard_button_de_json_empty(self):
|
||||
inline_keyboard_button = telegram.InlineKeyboardButton.de_json(None)
|
||||
inline_keyboard_button = telegram.InlineKeyboardButton.de_json(None, self._bot)
|
||||
|
||||
self.assertFalse(inline_keyboard_button)
|
||||
|
||||
def test_inline_keyboard_button_de_list_empty(self):
|
||||
inline_keyboard_button = telegram.InlineKeyboardButton.de_list(None)
|
||||
inline_keyboard_button = telegram.InlineKeyboardButton.de_list(None, self._bot)
|
||||
|
||||
self.assertFalse(inline_keyboard_button)
|
||||
|
||||
def test_inline_keyboard_button_to_json(self):
|
||||
inline_keyboard_button = telegram.InlineKeyboardButton.de_json(self.json_dict)
|
||||
inline_keyboard_button = telegram.InlineKeyboardButton.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertTrue(self.is_json(inline_keyboard_button.to_json()))
|
||||
|
||||
def test_inline_keyboard_button_to_dict(self):
|
||||
inline_keyboard_button = telegram.InlineKeyboardButton.de_json(self.json_dict).to_dict()
|
||||
inline_keyboard_button = telegram.InlineKeyboardButton.de_json(self.json_dict,
|
||||
self._bot).to_dict()
|
||||
|
||||
self.assertTrue(self.is_dict(inline_keyboard_button))
|
||||
self.assertDictEqual(self.json_dict, inline_keyboard_button)
|
||||
|
|
|
@ -51,12 +51,12 @@ class InlineKeyboardMarkupTest(BaseTest, unittest.TestCase):
|
|||
self.assertEqual(message.text, 'Testing InlineKeyboardMarkup')
|
||||
|
||||
def test_inline_keyboard_markup_de_json_empty(self):
|
||||
inline_keyboard_markup = telegram.InlineKeyboardMarkup.de_json(None)
|
||||
inline_keyboard_markup = telegram.InlineKeyboardMarkup.de_json(None, self._bot)
|
||||
|
||||
self.assertFalse(inline_keyboard_markup)
|
||||
|
||||
def test_inline_keyboard_markup_de_json(self):
|
||||
inline_keyboard_markup = telegram.InlineKeyboardMarkup.de_json(self.json_dict)
|
||||
inline_keyboard_markup = telegram.InlineKeyboardMarkup.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertTrue(isinstance(inline_keyboard_markup.inline_keyboard, list))
|
||||
self.assertTrue(
|
||||
|
@ -64,12 +64,12 @@ class InlineKeyboardMarkupTest(BaseTest, unittest.TestCase):
|
|||
telegram.InlineKeyboardButton))
|
||||
|
||||
def test_inline_keyboard_markup_to_json(self):
|
||||
inline_keyboard_markup = telegram.InlineKeyboardMarkup.de_json(self.json_dict)
|
||||
inline_keyboard_markup = telegram.InlineKeyboardMarkup.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertTrue(self.is_json(inline_keyboard_markup.to_json()))
|
||||
|
||||
def test_inline_keyboard_markup_to_dict(self):
|
||||
inline_keyboard_markup = telegram.InlineKeyboardMarkup.de_json(self.json_dict)
|
||||
inline_keyboard_markup = telegram.InlineKeyboardMarkup.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertTrue(isinstance(inline_keyboard_markup.inline_keyboard, list))
|
||||
self.assertTrue(
|
||||
|
|
|
@ -50,7 +50,7 @@ class InlineQueryTest(BaseTest, unittest.TestCase):
|
|||
}
|
||||
|
||||
def test_inlinequery_de_json(self):
|
||||
inlinequery = telegram.InlineQuery.de_json(self.json_dict)
|
||||
inlinequery = telegram.InlineQuery.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertEqual(inlinequery.id, self.id)
|
||||
self.assertDictEqual(inlinequery.from_user.to_dict(), self.from_user.to_dict())
|
||||
|
@ -59,12 +59,12 @@ class InlineQueryTest(BaseTest, unittest.TestCase):
|
|||
self.assertEqual(inlinequery.offset, self.offset)
|
||||
|
||||
def test_inlinequery_to_json(self):
|
||||
inlinequery = telegram.InlineQuery.de_json(self.json_dict)
|
||||
inlinequery = telegram.InlineQuery.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertTrue(self.is_json(inlinequery.to_json()))
|
||||
|
||||
def test_inlinequery_to_dict(self):
|
||||
inlinequery = telegram.InlineQuery.de_json(self.json_dict).to_dict()
|
||||
inlinequery = telegram.InlineQuery.de_json(self.json_dict, self._bot).to_dict()
|
||||
|
||||
self.assertTrue(self.is_dict(inlinequery))
|
||||
self.assertDictEqual(inlinequery, self.json_dict)
|
||||
|
|
|
@ -61,7 +61,7 @@ class InlineQueryResultArticleTest(BaseTest, unittest.TestCase):
|
|||
}
|
||||
|
||||
def test_article_de_json(self):
|
||||
article = telegram.InlineQueryResultArticle.de_json(self.json_dict)
|
||||
article = telegram.InlineQueryResultArticle.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertEqual(article.type, self.type)
|
||||
self.assertEqual(article.id, self.id)
|
||||
|
@ -77,12 +77,12 @@ class InlineQueryResultArticleTest(BaseTest, unittest.TestCase):
|
|||
self.assertEqual(article.thumb_width, self.thumb_width)
|
||||
|
||||
def test_article_to_json(self):
|
||||
article = telegram.InlineQueryResultArticle.de_json(self.json_dict)
|
||||
article = telegram.InlineQueryResultArticle.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertTrue(self.is_json(article.to_json()))
|
||||
|
||||
def test_article_to_dict(self):
|
||||
article = telegram.InlineQueryResultArticle.de_json(self.json_dict).to_dict()
|
||||
article = telegram.InlineQueryResultArticle.de_json(self.json_dict, self._bot).to_dict()
|
||||
|
||||
self.assertTrue(self.is_dict(article))
|
||||
self.assertDictEqual(self.json_dict, article)
|
||||
|
|
|
@ -55,7 +55,7 @@ class InlineQueryResultAudioTest(BaseTest, unittest.TestCase):
|
|||
}
|
||||
|
||||
def test_audio_de_json(self):
|
||||
audio = telegram.InlineQueryResultAudio.de_json(self.json_dict)
|
||||
audio = telegram.InlineQueryResultAudio.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertEqual(audio.type, self.type)
|
||||
self.assertEqual(audio.id, self.id)
|
||||
|
@ -68,12 +68,12 @@ class InlineQueryResultAudioTest(BaseTest, unittest.TestCase):
|
|||
self.assertDictEqual(audio.reply_markup.to_dict(), self.reply_markup.to_dict())
|
||||
|
||||
def test_audio_to_json(self):
|
||||
audio = telegram.InlineQueryResultAudio.de_json(self.json_dict)
|
||||
audio = telegram.InlineQueryResultAudio.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertTrue(self.is_json(audio.to_json()))
|
||||
|
||||
def test_audio_to_dict(self):
|
||||
audio = telegram.InlineQueryResultAudio.de_json(self.json_dict).to_dict()
|
||||
audio = telegram.InlineQueryResultAudio.de_json(self.json_dict, self._bot).to_dict()
|
||||
|
||||
self.assertTrue(self.is_dict(audio))
|
||||
self.assertDictEqual(self.json_dict, audio)
|
||||
|
|
|
@ -50,7 +50,7 @@ class InlineQueryResultCachedAudioTest(BaseTest, unittest.TestCase):
|
|||
}
|
||||
|
||||
def test_audio_de_json(self):
|
||||
audio = telegram.InlineQueryResultCachedAudio.de_json(self.json_dict)
|
||||
audio = telegram.InlineQueryResultCachedAudio.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertEqual(audio.type, self.type)
|
||||
self.assertEqual(audio.id, self.id)
|
||||
|
@ -60,12 +60,12 @@ class InlineQueryResultCachedAudioTest(BaseTest, unittest.TestCase):
|
|||
self.assertDictEqual(audio.reply_markup.to_dict(), self.reply_markup.to_dict())
|
||||
|
||||
def test_audio_to_json(self):
|
||||
audio = telegram.InlineQueryResultCachedAudio.de_json(self.json_dict)
|
||||
audio = telegram.InlineQueryResultCachedAudio.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertTrue(self.is_json(audio.to_json()))
|
||||
|
||||
def test_audio_to_dict(self):
|
||||
audio = telegram.InlineQueryResultCachedAudio.de_json(self.json_dict).to_dict()
|
||||
audio = telegram.InlineQueryResultCachedAudio.de_json(self.json_dict, self._bot).to_dict()
|
||||
|
||||
self.assertTrue(self.is_dict(audio))
|
||||
self.assertDictEqual(self.json_dict, audio)
|
||||
|
|
|
@ -55,7 +55,7 @@ class InlineQueryResultCachedDocumentTest(BaseTest, unittest.TestCase):
|
|||
}
|
||||
|
||||
def test_document_de_json(self):
|
||||
document = telegram.InlineQueryResultCachedDocument.de_json(self.json_dict)
|
||||
document = telegram.InlineQueryResultCachedDocument.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertEqual(document.id, self.id)
|
||||
self.assertEqual(document.type, self.type)
|
||||
|
@ -68,12 +68,13 @@ class InlineQueryResultCachedDocumentTest(BaseTest, unittest.TestCase):
|
|||
self.assertDictEqual(document.reply_markup.to_dict(), self.reply_markup.to_dict())
|
||||
|
||||
def test_document_to_json(self):
|
||||
document = telegram.InlineQueryResultCachedDocument.de_json(self.json_dict)
|
||||
document = telegram.InlineQueryResultCachedDocument.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertTrue(self.is_json(document.to_json()))
|
||||
|
||||
def test_document_to_dict(self):
|
||||
document = telegram.InlineQueryResultCachedDocument.de_json(self.json_dict).to_dict()
|
||||
document = telegram.InlineQueryResultCachedDocument.de_json(self.json_dict,
|
||||
self._bot).to_dict()
|
||||
|
||||
self.assertTrue(self.is_dict(document))
|
||||
self.assertDictEqual(self.json_dict, document)
|
||||
|
|
|
@ -53,7 +53,7 @@ class InlineQueryResultCachedGifTest(BaseTest, unittest.TestCase):
|
|||
}
|
||||
|
||||
def test_gif_de_json(self):
|
||||
gif = telegram.InlineQueryResultCachedGif.de_json(self.json_dict)
|
||||
gif = telegram.InlineQueryResultCachedGif.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertEqual(gif.type, self.type)
|
||||
self.assertEqual(gif.id, self.id)
|
||||
|
@ -65,12 +65,12 @@ class InlineQueryResultCachedGifTest(BaseTest, unittest.TestCase):
|
|||
self.assertDictEqual(gif.reply_markup.to_dict(), self.reply_markup.to_dict())
|
||||
|
||||
def test_gif_to_json(self):
|
||||
gif = telegram.InlineQueryResultCachedGif.de_json(self.json_dict)
|
||||
gif = telegram.InlineQueryResultCachedGif.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertTrue(self.is_json(gif.to_json()))
|
||||
|
||||
def test_gif_to_dict(self):
|
||||
gif = telegram.InlineQueryResultCachedGif.de_json(self.json_dict).to_dict()
|
||||
gif = telegram.InlineQueryResultCachedGif.de_json(self.json_dict, self._bot).to_dict()
|
||||
|
||||
self.assertTrue(self.is_dict(gif))
|
||||
self.assertDictEqual(self.json_dict, gif)
|
||||
|
|
|
@ -54,7 +54,7 @@ class InlineQueryResultCachedMpeg4GifTest(BaseTest, unittest.TestCase):
|
|||
}
|
||||
|
||||
def test_mpeg4_de_json(self):
|
||||
mpeg4 = telegram.InlineQueryResultCachedMpeg4Gif.de_json(self.json_dict)
|
||||
mpeg4 = telegram.InlineQueryResultCachedMpeg4Gif.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertEqual(mpeg4.type, self.type)
|
||||
self.assertEqual(mpeg4.id, self.id)
|
||||
|
@ -66,12 +66,13 @@ class InlineQueryResultCachedMpeg4GifTest(BaseTest, unittest.TestCase):
|
|||
self.assertDictEqual(mpeg4.reply_markup.to_dict(), self.reply_markup.to_dict())
|
||||
|
||||
def test_mpeg4_to_json(self):
|
||||
mpeg4 = telegram.InlineQueryResultCachedMpeg4Gif.de_json(self.json_dict)
|
||||
mpeg4 = telegram.InlineQueryResultCachedMpeg4Gif.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertTrue(self.is_json(mpeg4.to_json()))
|
||||
|
||||
def test_mpeg4_to_dict(self):
|
||||
mpeg4 = telegram.InlineQueryResultCachedMpeg4Gif.de_json(self.json_dict).to_dict()
|
||||
mpeg4 = telegram.InlineQueryResultCachedMpeg4Gif.de_json(self.json_dict,
|
||||
self._bot).to_dict()
|
||||
|
||||
self.assertTrue(self.is_dict(mpeg4))
|
||||
self.assertDictEqual(self.json_dict, mpeg4)
|
||||
|
|
|
@ -56,7 +56,7 @@ class InlineQueryResultCachedPhotoTest(BaseTest, unittest.TestCase):
|
|||
}
|
||||
|
||||
def test_photo_de_json(self):
|
||||
photo = telegram.InlineQueryResultCachedPhoto.de_json(self.json_dict)
|
||||
photo = telegram.InlineQueryResultCachedPhoto.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertEqual(photo.type, self.type)
|
||||
self.assertEqual(photo.id, self.id)
|
||||
|
@ -69,12 +69,12 @@ class InlineQueryResultCachedPhotoTest(BaseTest, unittest.TestCase):
|
|||
self.assertDictEqual(photo.reply_markup.to_dict(), self.reply_markup.to_dict())
|
||||
|
||||
def test_photo_to_json(self):
|
||||
photo = telegram.InlineQueryResultCachedPhoto.de_json(self.json_dict)
|
||||
photo = telegram.InlineQueryResultCachedPhoto.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertTrue(self.is_json(photo.to_json()))
|
||||
|
||||
def test_photo_to_dict(self):
|
||||
photo = telegram.InlineQueryResultCachedPhoto.de_json(self.json_dict).to_dict()
|
||||
photo = telegram.InlineQueryResultCachedPhoto.de_json(self.json_dict, self._bot).to_dict()
|
||||
|
||||
self.assertTrue(self.is_dict(photo))
|
||||
self.assertDictEqual(self.json_dict, photo)
|
||||
|
|
|
@ -50,7 +50,7 @@ class InlineQueryResultCachedStickerTest(BaseTest, unittest.TestCase):
|
|||
}
|
||||
|
||||
def test_sticker_de_json(self):
|
||||
sticker = telegram.InlineQueryResultCachedSticker.de_json(self.json_dict)
|
||||
sticker = telegram.InlineQueryResultCachedSticker.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertEqual(sticker.type, self.type)
|
||||
self.assertEqual(sticker.id, self.id)
|
||||
|
@ -60,12 +60,13 @@ class InlineQueryResultCachedStickerTest(BaseTest, unittest.TestCase):
|
|||
self.assertDictEqual(sticker.reply_markup.to_dict(), self.reply_markup.to_dict())
|
||||
|
||||
def test_sticker_to_json(self):
|
||||
sticker = telegram.InlineQueryResultCachedSticker.de_json(self.json_dict)
|
||||
sticker = telegram.InlineQueryResultCachedSticker.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertTrue(self.is_json(sticker.to_json()))
|
||||
|
||||
def test_sticker_to_dict(self):
|
||||
sticker = telegram.InlineQueryResultCachedSticker.de_json(self.json_dict).to_dict()
|
||||
sticker = telegram.InlineQueryResultCachedSticker.de_json(self.json_dict,
|
||||
self._bot).to_dict()
|
||||
|
||||
self.assertTrue(self.is_dict(sticker))
|
||||
self.assertDictEqual(self.json_dict, sticker)
|
||||
|
|
|
@ -56,7 +56,7 @@ class InlineQueryResultCachedVideoTest(BaseTest, unittest.TestCase):
|
|||
}
|
||||
|
||||
def test_video_de_json(self):
|
||||
video = telegram.InlineQueryResultCachedVideo.de_json(self.json_dict)
|
||||
video = telegram.InlineQueryResultCachedVideo.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertEqual(video.type, self.type)
|
||||
self.assertEqual(video.id, self.id)
|
||||
|
@ -69,12 +69,12 @@ class InlineQueryResultCachedVideoTest(BaseTest, unittest.TestCase):
|
|||
self.assertDictEqual(video.reply_markup.to_dict(), self.reply_markup.to_dict())
|
||||
|
||||
def test_video_to_json(self):
|
||||
video = telegram.InlineQueryResultCachedVideo.de_json(self.json_dict)
|
||||
video = telegram.InlineQueryResultCachedVideo.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertTrue(self.is_json(video.to_json()))
|
||||
|
||||
def test_video_to_dict(self):
|
||||
video = telegram.InlineQueryResultCachedVideo.de_json(self.json_dict).to_dict()
|
||||
video = telegram.InlineQueryResultCachedVideo.de_json(self.json_dict, self._bot).to_dict()
|
||||
|
||||
self.assertTrue(self.is_dict(video))
|
||||
self.assertDictEqual(self.json_dict, video)
|
||||
|
|
|
@ -54,7 +54,7 @@ class InlineQueryResultCachedVoiceTest(BaseTest, unittest.TestCase):
|
|||
}
|
||||
|
||||
def test_voice_de_json(self):
|
||||
voice = telegram.InlineQueryResultCachedVoice.de_json(self.json_dict)
|
||||
voice = telegram.InlineQueryResultCachedVoice.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertEqual(voice.type, self.type)
|
||||
self.assertEqual(voice.id, self.id)
|
||||
|
@ -66,12 +66,12 @@ class InlineQueryResultCachedVoiceTest(BaseTest, unittest.TestCase):
|
|||
self.assertDictEqual(voice.reply_markup.to_dict(), self.reply_markup.to_dict())
|
||||
|
||||
def test_voice_to_json(self):
|
||||
voice = telegram.InlineQueryResultCachedVoice.de_json(self.json_dict)
|
||||
voice = telegram.InlineQueryResultCachedVoice.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertTrue(self.is_json(voice.to_json()))
|
||||
|
||||
def test_voice_to_dict(self):
|
||||
voice = telegram.InlineQueryResultCachedVoice.de_json(self.json_dict).to_dict()
|
||||
voice = telegram.InlineQueryResultCachedVoice.de_json(self.json_dict, self._bot).to_dict()
|
||||
|
||||
self.assertTrue(self.is_dict(voice))
|
||||
self.assertDictEqual(self.json_dict, voice)
|
||||
|
|
|
@ -58,7 +58,7 @@ class InlineQueryResultContactTest(BaseTest, unittest.TestCase):
|
|||
}
|
||||
|
||||
def test_contact_de_json(self):
|
||||
contact = telegram.InlineQueryResultContact.de_json(self.json_dict)
|
||||
contact = telegram.InlineQueryResultContact.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertEqual(contact.id, self.id)
|
||||
self.assertEqual(contact.type, self.type)
|
||||
|
@ -73,12 +73,12 @@ class InlineQueryResultContactTest(BaseTest, unittest.TestCase):
|
|||
self.assertDictEqual(contact.reply_markup.to_dict(), self.reply_markup.to_dict())
|
||||
|
||||
def test_contact_to_json(self):
|
||||
contact = telegram.InlineQueryResultContact.de_json(self.json_dict)
|
||||
contact = telegram.InlineQueryResultContact.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertTrue(self.is_json(contact.to_json()))
|
||||
|
||||
def test_contact_to_dict(self):
|
||||
contact = telegram.InlineQueryResultContact.de_json(self.json_dict).to_dict()
|
||||
contact = telegram.InlineQueryResultContact.de_json(self.json_dict, self._bot).to_dict()
|
||||
|
||||
self.assertTrue(self.is_dict(contact))
|
||||
self.assertDictEqual(self.json_dict, contact)
|
||||
|
|
|
@ -62,7 +62,7 @@ class InlineQueryResultDocumentTest(BaseTest, unittest.TestCase):
|
|||
}
|
||||
|
||||
def test_document_de_json(self):
|
||||
document = telegram.InlineQueryResultDocument.de_json(self.json_dict)
|
||||
document = telegram.InlineQueryResultDocument.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertEqual(document.id, self.id)
|
||||
self.assertEqual(document.type, self.type)
|
||||
|
@ -79,12 +79,12 @@ class InlineQueryResultDocumentTest(BaseTest, unittest.TestCase):
|
|||
self.assertDictEqual(document.reply_markup.to_dict(), self.reply_markup.to_dict())
|
||||
|
||||
def test_document_to_json(self):
|
||||
document = telegram.InlineQueryResultDocument.de_json(self.json_dict)
|
||||
document = telegram.InlineQueryResultDocument.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertTrue(self.is_json(document.to_json()))
|
||||
|
||||
def test_document_to_dict(self):
|
||||
document = telegram.InlineQueryResultDocument.de_json(self.json_dict).to_dict()
|
||||
document = telegram.InlineQueryResultDocument.de_json(self.json_dict, self._bot).to_dict()
|
||||
|
||||
self.assertTrue(self.is_dict(document))
|
||||
self.assertDictEqual(self.json_dict, document)
|
||||
|
|
|
@ -59,7 +59,7 @@ class InlineQueryResultGifTest(BaseTest, unittest.TestCase):
|
|||
}
|
||||
|
||||
def test_gif_de_json(self):
|
||||
gif = telegram.InlineQueryResultGif.de_json(self.json_dict)
|
||||
gif = telegram.InlineQueryResultGif.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertEqual(gif.type, self.type)
|
||||
self.assertEqual(gif.id, self.id)
|
||||
|
@ -74,12 +74,12 @@ class InlineQueryResultGifTest(BaseTest, unittest.TestCase):
|
|||
self.assertDictEqual(gif.reply_markup.to_dict(), self.reply_markup.to_dict())
|
||||
|
||||
def test_gif_to_json(self):
|
||||
gif = telegram.InlineQueryResultGif.de_json(self.json_dict)
|
||||
gif = telegram.InlineQueryResultGif.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertTrue(self.is_json(gif.to_json()))
|
||||
|
||||
def test_gif_to_dict(self):
|
||||
gif = telegram.InlineQueryResultGif.de_json(self.json_dict).to_dict()
|
||||
gif = telegram.InlineQueryResultGif.de_json(self.json_dict, self._bot).to_dict()
|
||||
|
||||
self.assertTrue(self.is_dict(gif))
|
||||
self.assertDictEqual(self.json_dict, gif)
|
||||
|
|
|
@ -58,7 +58,7 @@ class InlineQueryResultLocationTest(BaseTest, unittest.TestCase):
|
|||
}
|
||||
|
||||
def test_location_de_json(self):
|
||||
location = telegram.InlineQueryResultLocation.de_json(self.json_dict)
|
||||
location = telegram.InlineQueryResultLocation.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertEqual(location.id, self.id)
|
||||
self.assertEqual(location.type, self.type)
|
||||
|
@ -73,12 +73,12 @@ class InlineQueryResultLocationTest(BaseTest, unittest.TestCase):
|
|||
self.assertDictEqual(location.reply_markup.to_dict(), self.reply_markup.to_dict())
|
||||
|
||||
def test_location_to_json(self):
|
||||
location = telegram.InlineQueryResultLocation.de_json(self.json_dict)
|
||||
location = telegram.InlineQueryResultLocation.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertTrue(self.is_json(location.to_json()))
|
||||
|
||||
def test_location_to_dict(self):
|
||||
location = telegram.InlineQueryResultLocation.de_json(self.json_dict).to_dict()
|
||||
location = telegram.InlineQueryResultLocation.de_json(self.json_dict, self._bot).to_dict()
|
||||
|
||||
self.assertTrue(self.is_dict(location))
|
||||
self.assertDictEqual(self.json_dict, location)
|
||||
|
|
|
@ -59,7 +59,7 @@ class InlineQueryResultMpeg4GifTest(BaseTest, unittest.TestCase):
|
|||
}
|
||||
|
||||
def test_mpeg4_de_json(self):
|
||||
mpeg4 = telegram.InlineQueryResultMpeg4Gif.de_json(self.json_dict)
|
||||
mpeg4 = telegram.InlineQueryResultMpeg4Gif.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertEqual(mpeg4.type, self.type)
|
||||
self.assertEqual(mpeg4.id, self.id)
|
||||
|
@ -74,12 +74,12 @@ class InlineQueryResultMpeg4GifTest(BaseTest, unittest.TestCase):
|
|||
self.assertDictEqual(mpeg4.reply_markup.to_dict(), self.reply_markup.to_dict())
|
||||
|
||||
def test_mpeg4_to_json(self):
|
||||
mpeg4 = telegram.InlineQueryResultMpeg4Gif.de_json(self.json_dict)
|
||||
mpeg4 = telegram.InlineQueryResultMpeg4Gif.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertTrue(self.is_json(mpeg4.to_json()))
|
||||
|
||||
def test_mpeg4_to_dict(self):
|
||||
mpeg4 = telegram.InlineQueryResultMpeg4Gif.de_json(self.json_dict).to_dict()
|
||||
mpeg4 = telegram.InlineQueryResultMpeg4Gif.de_json(self.json_dict, self._bot).to_dict()
|
||||
|
||||
self.assertTrue(self.is_dict(mpeg4))
|
||||
self.assertDictEqual(self.json_dict, mpeg4)
|
||||
|
|
|
@ -61,7 +61,7 @@ class InlineQueryResultPhotoTest(BaseTest, unittest.TestCase):
|
|||
}
|
||||
|
||||
def test_photo_de_json(self):
|
||||
photo = telegram.InlineQueryResultPhoto.de_json(self.json_dict)
|
||||
photo = telegram.InlineQueryResultPhoto.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertEqual(photo.type, self.type)
|
||||
self.assertEqual(photo.id, self.id)
|
||||
|
@ -77,12 +77,12 @@ class InlineQueryResultPhotoTest(BaseTest, unittest.TestCase):
|
|||
self.assertDictEqual(photo.reply_markup.to_dict(), self.reply_markup.to_dict())
|
||||
|
||||
def test_photo_to_json(self):
|
||||
photo = telegram.InlineQueryResultPhoto.de_json(self.json_dict)
|
||||
photo = telegram.InlineQueryResultPhoto.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertTrue(self.is_json(photo.to_json()))
|
||||
|
||||
def test_photo_to_dict(self):
|
||||
photo = telegram.InlineQueryResultPhoto.de_json(self.json_dict).to_dict()
|
||||
photo = telegram.InlineQueryResultPhoto.de_json(self.json_dict, self._bot).to_dict()
|
||||
|
||||
self.assertTrue(self.is_dict(photo))
|
||||
self.assertDictEqual(self.json_dict, photo)
|
||||
|
|
|
@ -62,7 +62,7 @@ class InlineQueryResultVenueTest(BaseTest, unittest.TestCase):
|
|||
}
|
||||
|
||||
def test_venue_de_json(self):
|
||||
venue = telegram.InlineQueryResultVenue.de_json(self.json_dict)
|
||||
venue = telegram.InlineQueryResultVenue.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertEqual(venue.id, self.id)
|
||||
self.assertEqual(venue.type, self.type)
|
||||
|
@ -79,12 +79,12 @@ class InlineQueryResultVenueTest(BaseTest, unittest.TestCase):
|
|||
self.assertDictEqual(venue.reply_markup.to_dict(), self.reply_markup.to_dict())
|
||||
|
||||
def test_venue_to_json(self):
|
||||
venue = telegram.InlineQueryResultVenue.de_json(self.json_dict)
|
||||
venue = telegram.InlineQueryResultVenue.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertTrue(self.is_json(venue.to_json()))
|
||||
|
||||
def test_venue_to_dict(self):
|
||||
venue = telegram.InlineQueryResultVenue.de_json(self.json_dict).to_dict()
|
||||
venue = telegram.InlineQueryResultVenue.de_json(self.json_dict, self._bot).to_dict()
|
||||
|
||||
self.assertTrue(self.is_dict(venue))
|
||||
self.assertDictEqual(self.json_dict, venue)
|
||||
|
|
|
@ -65,7 +65,7 @@ class InlineQueryResultVideoTest(BaseTest, unittest.TestCase):
|
|||
}
|
||||
|
||||
def test_video_de_json(self):
|
||||
video = telegram.InlineQueryResultVideo.de_json(self.json_dict)
|
||||
video = telegram.InlineQueryResultVideo.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertEqual(video.type, self.type)
|
||||
self.assertEqual(video.id, self.id)
|
||||
|
@ -83,12 +83,12 @@ class InlineQueryResultVideoTest(BaseTest, unittest.TestCase):
|
|||
self.assertDictEqual(video.reply_markup.to_dict(), self.reply_markup.to_dict())
|
||||
|
||||
def test_video_to_json(self):
|
||||
video = telegram.InlineQueryResultVideo.de_json(self.json_dict)
|
||||
video = telegram.InlineQueryResultVideo.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertTrue(self.is_json(video.to_json()))
|
||||
|
||||
def test_video_to_dict(self):
|
||||
video = telegram.InlineQueryResultVideo.de_json(self.json_dict).to_dict()
|
||||
video = telegram.InlineQueryResultVideo.de_json(self.json_dict, self._bot).to_dict()
|
||||
|
||||
self.assertTrue(self.is_dict(video))
|
||||
self.assertDictEqual(self.json_dict, video)
|
||||
|
|
|
@ -53,7 +53,7 @@ class InlineQueryResultVoiceTest(BaseTest, unittest.TestCase):
|
|||
}
|
||||
|
||||
def test_voice_de_json(self):
|
||||
voice = telegram.InlineQueryResultVoice.de_json(self.json_dict)
|
||||
voice = telegram.InlineQueryResultVoice.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertEqual(voice.type, self.type)
|
||||
self.assertEqual(voice.id, self.id)
|
||||
|
@ -65,12 +65,12 @@ class InlineQueryResultVoiceTest(BaseTest, unittest.TestCase):
|
|||
self.assertDictEqual(voice.reply_markup.to_dict(), self.reply_markup.to_dict())
|
||||
|
||||
def test_voice_to_json(self):
|
||||
voice = telegram.InlineQueryResultVoice.de_json(self.json_dict)
|
||||
voice = telegram.InlineQueryResultVoice.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertTrue(self.is_json(voice.to_json()))
|
||||
|
||||
def test_voice_to_dict(self):
|
||||
voice = telegram.InlineQueryResultVoice.de_json(self.json_dict).to_dict()
|
||||
voice = telegram.InlineQueryResultVoice.de_json(self.json_dict, self._bot).to_dict()
|
||||
|
||||
self.assertTrue(self.is_dict(voice))
|
||||
self.assertDictEqual(self.json_dict, voice)
|
||||
|
|
|
@ -43,14 +43,14 @@ class InputContactMessageContentTest(BaseTest, unittest.TestCase):
|
|||
}
|
||||
|
||||
def test_icmc_de_json(self):
|
||||
icmc = telegram.InputContactMessageContent.de_json(self.json_dict)
|
||||
icmc = telegram.InputContactMessageContent.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertEqual(icmc.first_name, self.first_name)
|
||||
self.assertEqual(icmc.phone_number, self.phone_number)
|
||||
self.assertEqual(icmc.last_name, self.last_name)
|
||||
|
||||
def test_icmc_de_json_factory(self):
|
||||
icmc = telegram.InputMessageContent.de_json(self.json_dict)
|
||||
icmc = telegram.InputMessageContent.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertTrue(isinstance(icmc, telegram.InputContactMessageContent))
|
||||
|
||||
|
@ -60,17 +60,17 @@ class InputContactMessageContentTest(BaseTest, unittest.TestCase):
|
|||
del (json_dict['phone_number'])
|
||||
del (json_dict['first_name'])
|
||||
|
||||
icmc = telegram.InputMessageContent.de_json(json_dict)
|
||||
icmc = telegram.InputMessageContent.de_json(json_dict, self._bot)
|
||||
|
||||
self.assertFalse(icmc)
|
||||
|
||||
def test_icmc_to_json(self):
|
||||
icmc = telegram.InputContactMessageContent.de_json(self.json_dict)
|
||||
icmc = telegram.InputContactMessageContent.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertTrue(self.is_json(icmc.to_json()))
|
||||
|
||||
def test_icmc_to_dict(self):
|
||||
icmc = telegram.InputContactMessageContent.de_json(self.json_dict).to_dict()
|
||||
icmc = telegram.InputContactMessageContent.de_json(self.json_dict, self._bot).to_dict()
|
||||
|
||||
self.assertTrue(self.is_dict(icmc))
|
||||
self.assertDictEqual(self.json_dict, icmc)
|
||||
|
|
|
@ -39,13 +39,13 @@ class InputLocationMessageContentTest(BaseTest, unittest.TestCase):
|
|||
'latitude': self.latitude,}
|
||||
|
||||
def test_ilmc_de_json(self):
|
||||
ilmc = telegram.InputLocationMessageContent.de_json(self.json_dict)
|
||||
ilmc = telegram.InputLocationMessageContent.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertEqual(ilmc.longitude, self.longitude)
|
||||
self.assertEqual(ilmc.latitude, self.latitude)
|
||||
|
||||
def test_ilmc_de_json_factory(self):
|
||||
ilmc = telegram.InputMessageContent.de_json(self.json_dict)
|
||||
ilmc = telegram.InputMessageContent.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertTrue(isinstance(ilmc, telegram.InputLocationMessageContent))
|
||||
|
||||
|
@ -56,17 +56,17 @@ class InputLocationMessageContentTest(BaseTest, unittest.TestCase):
|
|||
# If none args are sent it will fall in a different condition
|
||||
# del (json_dict['latitude'])
|
||||
|
||||
ilmc = telegram.InputMessageContent.de_json(json_dict)
|
||||
ilmc = telegram.InputMessageContent.de_json(json_dict, self._bot)
|
||||
|
||||
self.assertFalse(ilmc)
|
||||
|
||||
def test_ilmc_to_json(self):
|
||||
ilmc = telegram.InputLocationMessageContent.de_json(self.json_dict)
|
||||
ilmc = telegram.InputLocationMessageContent.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertTrue(self.is_json(ilmc.to_json()))
|
||||
|
||||
def test_ilmc_to_dict(self):
|
||||
ilmc = telegram.InputLocationMessageContent.de_json(self.json_dict).to_dict()
|
||||
ilmc = telegram.InputLocationMessageContent.de_json(self.json_dict, self._bot).to_dict()
|
||||
|
||||
self.assertTrue(self.is_dict(ilmc))
|
||||
self.assertDictEqual(self.json_dict, ilmc)
|
||||
|
|
|
@ -32,7 +32,7 @@ class InputMessageContentTest(BaseTest, unittest.TestCase):
|
|||
"""This object represents Tests for Telegram InputMessageContent."""
|
||||
|
||||
def test_imc_de_json(self):
|
||||
imc = telegram.InputMessageContent.de_json(None)
|
||||
imc = telegram.InputMessageContent.de_json(None, self._bot)
|
||||
|
||||
self.assertFalse(imc)
|
||||
|
||||
|
|
|
@ -43,14 +43,14 @@ class InputTextMessageContentTest(BaseTest, unittest.TestCase):
|
|||
}
|
||||
|
||||
def test_itmc_de_json(self):
|
||||
itmc = telegram.InputTextMessageContent.de_json(self.json_dict)
|
||||
itmc = telegram.InputTextMessageContent.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertEqual(itmc.parse_mode, self.parse_mode)
|
||||
self.assertEqual(itmc.message_text, self.message_text)
|
||||
self.assertEqual(itmc.disable_web_page_preview, self.disable_web_page_preview)
|
||||
|
||||
def test_itmc_de_json_factory(self):
|
||||
itmc = telegram.InputMessageContent.de_json(self.json_dict)
|
||||
itmc = telegram.InputMessageContent.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertTrue(isinstance(itmc, telegram.InputTextMessageContent))
|
||||
|
||||
|
@ -59,17 +59,17 @@ class InputTextMessageContentTest(BaseTest, unittest.TestCase):
|
|||
|
||||
del (json_dict['message_text'])
|
||||
|
||||
itmc = telegram.InputMessageContent.de_json(json_dict)
|
||||
itmc = telegram.InputMessageContent.de_json(json_dict, self._bot)
|
||||
|
||||
self.assertFalse(itmc)
|
||||
|
||||
def test_itmc_to_json(self):
|
||||
itmc = telegram.InputTextMessageContent.de_json(self.json_dict)
|
||||
itmc = telegram.InputTextMessageContent.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertTrue(self.is_json(itmc.to_json()))
|
||||
|
||||
def test_itmc_to_dict(self):
|
||||
itmc = telegram.InputTextMessageContent.de_json(self.json_dict).to_dict()
|
||||
itmc = telegram.InputTextMessageContent.de_json(self.json_dict, self._bot).to_dict()
|
||||
|
||||
self.assertTrue(self.is_dict(itmc))
|
||||
self.assertDictEqual(self.json_dict, itmc)
|
||||
|
|
|
@ -47,7 +47,7 @@ class InputVenueMessageContentTest(BaseTest, unittest.TestCase):
|
|||
}
|
||||
|
||||
def test_ivmc_de_json(self):
|
||||
ivmc = telegram.InputVenueMessageContent.de_json(self.json_dict)
|
||||
ivmc = telegram.InputVenueMessageContent.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertEqual(ivmc.longitude, self.longitude)
|
||||
self.assertEqual(ivmc.latitude, self.latitude)
|
||||
|
@ -56,7 +56,7 @@ class InputVenueMessageContentTest(BaseTest, unittest.TestCase):
|
|||
self.assertEqual(ivmc.foursquare_id, self.foursquare_id)
|
||||
|
||||
def test_ivmc_de_json_factory(self):
|
||||
ivmc = telegram.InputMessageContent.de_json(self.json_dict)
|
||||
ivmc = telegram.InputMessageContent.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertTrue(isinstance(ivmc, telegram.InputVenueMessageContent))
|
||||
|
||||
|
@ -68,17 +68,17 @@ class InputVenueMessageContentTest(BaseTest, unittest.TestCase):
|
|||
del (json_dict['title'])
|
||||
del (json_dict['address'])
|
||||
|
||||
ivmc = telegram.InputMessageContent.de_json(json_dict)
|
||||
ivmc = telegram.InputMessageContent.de_json(json_dict, self._bot)
|
||||
|
||||
self.assertFalse(ivmc)
|
||||
|
||||
def test_ivmc_to_json(self):
|
||||
ivmc = telegram.InputVenueMessageContent.de_json(self.json_dict)
|
||||
ivmc = telegram.InputVenueMessageContent.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertTrue(self.is_json(ivmc.to_json()))
|
||||
|
||||
def test_ivmc_to_dict(self):
|
||||
ivmc = telegram.InputVenueMessageContent.de_json(self.json_dict).to_dict()
|
||||
ivmc = telegram.InputVenueMessageContent.de_json(self.json_dict, self._bot).to_dict()
|
||||
|
||||
self.assertTrue(self.is_dict(ivmc))
|
||||
self.assertDictEqual(self.json_dict, ivmc)
|
||||
|
|
|
@ -44,29 +44,29 @@ class KeyboardButtonTest(BaseTest, unittest.TestCase):
|
|||
}
|
||||
|
||||
def test_keyboard_button_de_json(self):
|
||||
keyboard_button = telegram.KeyboardButton.de_json(self.json_dict)
|
||||
keyboard_button = telegram.KeyboardButton.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertEqual(keyboard_button.text, self.text)
|
||||
self.assertEqual(keyboard_button.request_location, self.request_location)
|
||||
self.assertEqual(keyboard_button.request_contact, self.request_contact)
|
||||
|
||||
def test_keyboard_button_de_json_empty(self):
|
||||
keyboard_button = telegram.KeyboardButton.de_json(None)
|
||||
keyboard_button = telegram.KeyboardButton.de_json(None, self._bot)
|
||||
|
||||
self.assertFalse(keyboard_button)
|
||||
|
||||
def test_keyboard_button_de_list_empty(self):
|
||||
keyboard_button = telegram.KeyboardButton.de_list(None)
|
||||
keyboard_button = telegram.KeyboardButton.de_list(None, self._bot)
|
||||
|
||||
self.assertFalse(keyboard_button)
|
||||
|
||||
def test_keyboard_button_to_json(self):
|
||||
keyboard_button = telegram.KeyboardButton.de_json(self.json_dict)
|
||||
keyboard_button = telegram.KeyboardButton.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertTrue(self.is_json(keyboard_button.to_json()))
|
||||
|
||||
def test_keyboard_button_to_dict(self):
|
||||
keyboard_button = telegram.KeyboardButton.de_json(self.json_dict).to_dict()
|
||||
keyboard_button = telegram.KeyboardButton.de_json(self.json_dict, self._bot).to_dict()
|
||||
|
||||
self.assertTrue(self.is_dict(keyboard_button))
|
||||
self.assertDictEqual(self.json_dict, keyboard_button)
|
||||
|
|
|
@ -20,6 +20,9 @@
|
|||
|
||||
import unittest
|
||||
import sys
|
||||
|
||||
from flaky import flaky
|
||||
|
||||
sys.path.append('.')
|
||||
|
||||
import telegram
|
||||
|
@ -53,18 +56,18 @@ class LocationTest(BaseTest, unittest.TestCase):
|
|||
self.assertEqual(location.longitude, self.longitude)
|
||||
|
||||
def test_location_de_json(self):
|
||||
location = telegram.Location.de_json(self.json_dict)
|
||||
location = telegram.Location.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertEqual(location.latitude, self.latitude)
|
||||
self.assertEqual(location.longitude, self.longitude)
|
||||
|
||||
def test_location_to_json(self):
|
||||
location = telegram.Location.de_json(self.json_dict)
|
||||
location = telegram.Location.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertTrue(self.is_json(location.to_json()))
|
||||
|
||||
def test_location_to_dict(self):
|
||||
location = telegram.Location.de_json(self.json_dict)
|
||||
location = telegram.Location.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertEqual(location['latitude'], self.latitude)
|
||||
self.assertEqual(location['longitude'], self.longitude)
|
||||
|
@ -89,6 +92,15 @@ class LocationTest(BaseTest, unittest.TestCase):
|
|||
lambda: self._bot.sendLocation(chat_id=self._chat_id,
|
||||
**json_dict))
|
||||
|
||||
@flaky(3, 1)
|
||||
def test_reply_location(self):
|
||||
"""Test for Message.reply_location"""
|
||||
message = self._bot.sendMessage(self._chat_id, '.')
|
||||
message = message.reply_location(self.latitude, self.longitude)
|
||||
|
||||
self.assertEqual(message.location.latitude, self.latitude)
|
||||
self.assertEqual(message.location.longitude, self.longitude)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
import sys
|
||||
import unittest
|
||||
|
||||
from flaky import flaky
|
||||
|
||||
sys.path.append('.')
|
||||
|
||||
import telegram
|
||||
|
@ -56,6 +58,24 @@ class MessageTest(BaseTest, unittest.TestCase):
|
|||
self.assertDictEqual(message.parse_entities(), {entity: 'http://google.com',
|
||||
entity_2: 'h'})
|
||||
|
||||
@flaky(3, 1)
|
||||
def test_reply_text(self):
|
||||
"""Test for Message.reply_text"""
|
||||
message = self._bot.sendMessage(self._chat_id, '.')
|
||||
message = message.reply_text('Testing class method')
|
||||
|
||||
self.assertTrue(self.is_json(message.to_json()))
|
||||
self.assertEqual(message.text, 'Testing class method')
|
||||
|
||||
@flaky(3, 1)
|
||||
def test_forward(self):
|
||||
"""Test for Message.forward"""
|
||||
message = self._bot.sendMessage(self._chat_id, 'Testing class method')
|
||||
message = message.forward(self._chat_id)
|
||||
|
||||
self.assertTrue(self.is_json(message.to_json()))
|
||||
self.assertEqual(message.text, 'Testing class method')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -45,7 +45,7 @@ class MessageEntityTest(BaseTest, unittest.TestCase):
|
|||
}
|
||||
|
||||
def test_sticker_de_json(self):
|
||||
sticker = telegram.MessageEntity.de_json(self.json_dict)
|
||||
sticker = telegram.MessageEntity.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertEqual(sticker.type, self.type)
|
||||
self.assertEqual(sticker.offset, self.offset)
|
||||
|
@ -53,12 +53,12 @@ class MessageEntityTest(BaseTest, unittest.TestCase):
|
|||
self.assertEqual(sticker.url, self.url)
|
||||
|
||||
def test_sticker_to_json(self):
|
||||
sticker = telegram.MessageEntity.de_json(self.json_dict)
|
||||
sticker = telegram.MessageEntity.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertTrue(self.is_json(sticker.to_json()))
|
||||
|
||||
def test_sticker_to_dict(self):
|
||||
sticker = telegram.MessageEntity.de_json(self.json_dict).to_dict()
|
||||
sticker = telegram.MessageEntity.de_json(self.json_dict, self._bot).to_dict()
|
||||
|
||||
self.assertTrue(self.is_dict(sticker))
|
||||
self.assertDictEqual(self.json_dict, sticker)
|
||||
|
|
|
@ -140,7 +140,7 @@ class PhotoTest(BaseTest, unittest.TestCase):
|
|||
self.assertEqual(photo.height, self.height)
|
||||
|
||||
def test_photo_de_json(self):
|
||||
photo = telegram.PhotoSize.de_json(self.json_dict)
|
||||
photo = telegram.PhotoSize.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertEqual(photo.file_id, self.photo_file_id)
|
||||
self.assertTrue(isinstance(photo, telegram.PhotoSize))
|
||||
|
@ -149,12 +149,12 @@ class PhotoTest(BaseTest, unittest.TestCase):
|
|||
self.assertEqual(photo.file_size, self.file_size)
|
||||
|
||||
def test_photo_to_json(self):
|
||||
photo = telegram.PhotoSize.de_json(self.json_dict)
|
||||
photo = telegram.PhotoSize.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertTrue(self.is_json(photo.to_json()))
|
||||
|
||||
def test_photo_to_dict(self):
|
||||
photo = telegram.PhotoSize.de_json(self.json_dict)
|
||||
photo = telegram.PhotoSize.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertTrue(self.is_dict(photo.to_dict()))
|
||||
self.assertEqual(photo['file_id'], self.photo_file_id)
|
||||
|
@ -200,6 +200,15 @@ class PhotoTest(BaseTest, unittest.TestCase):
|
|||
TypeError,
|
||||
lambda: self._bot.sendPhoto(chat_id=self._chat_id, **json_dict))
|
||||
|
||||
@flaky(3, 1)
|
||||
@timeout(10)
|
||||
def test_reply_photo(self):
|
||||
"""Test for Message.reply_photo"""
|
||||
message = self._bot.sendMessage(self._chat_id, '.')
|
||||
message = message.reply_photo(self.photo_file)
|
||||
|
||||
self.assertNotEqual(message.photo[0].file_id, '')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -42,29 +42,29 @@ class ReplyKeyboardHideTest(BaseTest, unittest.TestCase):
|
|||
message = self._bot.sendMessage(
|
||||
self._chat_id,
|
||||
'Моё судно на воздушной подушке полно угрей',
|
||||
reply_markup=telegram.ReplyKeyboardHide.de_json(self.json_dict))
|
||||
reply_markup=telegram.ReplyKeyboardHide.de_json(self.json_dict, self._bot))
|
||||
|
||||
self.assertTrue(self.is_json(message.to_json()))
|
||||
self.assertEqual(message.text, u'Моё судно на воздушной подушке полно угрей')
|
||||
|
||||
def test_reply_keyboard_hide_de_json(self):
|
||||
reply_keyboard_hide = telegram.ReplyKeyboardHide.de_json(self.json_dict)
|
||||
reply_keyboard_hide = telegram.ReplyKeyboardHide.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertEqual(reply_keyboard_hide.hide_keyboard, self.hide_keyboard)
|
||||
self.assertEqual(reply_keyboard_hide.selective, self.selective)
|
||||
|
||||
def test_reply_keyboard_hide_de_json_empty(self):
|
||||
reply_keyboard_hide = telegram.ReplyKeyboardHide.de_json(None)
|
||||
reply_keyboard_hide = telegram.ReplyKeyboardHide.de_json(None, self._bot)
|
||||
|
||||
self.assertFalse(reply_keyboard_hide)
|
||||
|
||||
def test_reply_keyboard_hide_to_json(self):
|
||||
reply_keyboard_hide = telegram.ReplyKeyboardHide.de_json(self.json_dict)
|
||||
reply_keyboard_hide = telegram.ReplyKeyboardHide.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertTrue(self.is_json(reply_keyboard_hide.to_json()))
|
||||
|
||||
def test_reply_keyboard_hide_to_dict(self):
|
||||
reply_keyboard_hide = telegram.ReplyKeyboardHide.de_json(self.json_dict)
|
||||
reply_keyboard_hide = telegram.ReplyKeyboardHide.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertEqual(reply_keyboard_hide['hide_keyboard'], self.hide_keyboard)
|
||||
self.assertEqual(reply_keyboard_hide['selective'], self.selective)
|
||||
|
|
|
@ -48,18 +48,18 @@ class ReplyKeyboardMarkupTest(BaseTest, unittest.TestCase):
|
|||
message = self._bot.sendMessage(
|
||||
self._chat_id,
|
||||
'Моё судно на воздушной подушке полно угрей',
|
||||
reply_markup=telegram.ReplyKeyboardMarkup.de_json(self.json_dict))
|
||||
reply_markup=telegram.ReplyKeyboardMarkup.de_json(self.json_dict, self._bot))
|
||||
|
||||
self.assertTrue(self.is_json(message.to_json()))
|
||||
self.assertEqual(message.text, u'Моё судно на воздушной подушке полно угрей')
|
||||
|
||||
def test_reply_markup_empty_de_json_empty(self):
|
||||
reply_markup_empty = telegram.ReplyKeyboardMarkup.de_json(None)
|
||||
reply_markup_empty = telegram.ReplyKeyboardMarkup.de_json(None, self._bot)
|
||||
|
||||
self.assertFalse(reply_markup_empty)
|
||||
|
||||
def test_reply_keyboard_markup_de_json(self):
|
||||
reply_keyboard_markup = telegram.ReplyKeyboardMarkup.de_json(self.json_dict)
|
||||
reply_keyboard_markup = telegram.ReplyKeyboardMarkup.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertTrue(isinstance(reply_keyboard_markup.keyboard, list))
|
||||
self.assertTrue(isinstance(reply_keyboard_markup.keyboard[0][0], telegram.KeyboardButton))
|
||||
|
@ -68,12 +68,12 @@ class ReplyKeyboardMarkupTest(BaseTest, unittest.TestCase):
|
|||
self.assertEqual(reply_keyboard_markup.selective, self.selective)
|
||||
|
||||
def test_reply_keyboard_markup_to_json(self):
|
||||
reply_keyboard_markup = telegram.ReplyKeyboardMarkup.de_json(self.json_dict)
|
||||
reply_keyboard_markup = telegram.ReplyKeyboardMarkup.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertTrue(self.is_json(reply_keyboard_markup.to_json()))
|
||||
|
||||
def test_reply_keyboard_markup_to_dict(self):
|
||||
reply_keyboard_markup = telegram.ReplyKeyboardMarkup.de_json(self.json_dict)
|
||||
reply_keyboard_markup = telegram.ReplyKeyboardMarkup.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertTrue(isinstance(reply_keyboard_markup.keyboard, list))
|
||||
self.assertTrue(isinstance(reply_keyboard_markup.keyboard[0][0], telegram.KeyboardButton))
|
||||
|
|
|
@ -32,7 +32,7 @@ class ReplyMarkupTest(BaseTest, unittest.TestCase):
|
|||
"""This object represents Tests for Telegram ReplyMarkup."""
|
||||
|
||||
def test_reply_markup_de_json_empty(self):
|
||||
reply_markup = telegram.ReplyMarkup.de_json(None)
|
||||
reply_markup = telegram.ReplyMarkup.de_json(None, self._bot)
|
||||
|
||||
self.assertFalse(reply_markup)
|
||||
|
||||
|
|
|
@ -77,7 +77,7 @@ class StickerTest(BaseTest, unittest.TestCase):
|
|||
self.assertEqual(sticker.file_size, self.file_size)
|
||||
|
||||
def test_sticker_de_json(self):
|
||||
sticker = telegram.Sticker.de_json(self.json_dict)
|
||||
sticker = telegram.Sticker.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertEqual(sticker.file_id, self.sticker_file_id)
|
||||
self.assertEqual(sticker.width, self.width)
|
||||
|
@ -87,12 +87,12 @@ class StickerTest(BaseTest, unittest.TestCase):
|
|||
self.assertEqual(sticker.file_size, self.file_size)
|
||||
|
||||
def test_sticker_to_json(self):
|
||||
sticker = telegram.Sticker.de_json(self.json_dict)
|
||||
sticker = telegram.Sticker.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertTrue(self.is_json(sticker.to_json()))
|
||||
|
||||
def test_sticker_to_dict(self):
|
||||
sticker = telegram.Sticker.de_json(self.json_dict)
|
||||
sticker = telegram.Sticker.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertEqual(sticker['file_id'], self.sticker_file_id)
|
||||
self.assertEqual(sticker['width'], self.width)
|
||||
|
@ -136,6 +136,15 @@ class StickerTest(BaseTest, unittest.TestCase):
|
|||
TypeError,
|
||||
lambda: self._bot.sendSticker(chat_id=self._chat_id, **json_dict))
|
||||
|
||||
@flaky(3, 1)
|
||||
@timeout(10)
|
||||
def test_reply_sticker(self):
|
||||
"""Test for Message.reply_sticker"""
|
||||
message = self._bot.sendMessage(self._chat_id, '.')
|
||||
message = message.reply_sticker(self.sticker_file_id)
|
||||
|
||||
self.assertNotEqual(message.sticker.file_id, '')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue