mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2025-03-16 20:29:55 +01:00
remove de_json() (#789)
* remove de_json() * Remove or rename obsolete tests * fixes according to rc
This commit is contained in:
parent
160ffed5ad
commit
eae139d3e9
42 changed files with 52 additions and 631 deletions
|
@ -2772,12 +2772,6 @@ class Bot(TelegramObject):
|
|||
|
||||
return result
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data, bot):
|
||||
data = super(Bot, cls).de_json(data, bot)
|
||||
|
||||
return cls(**data)
|
||||
|
||||
def to_dict(self):
|
||||
data = {'id': self.id, 'username': self.username, 'first_name': self.username}
|
||||
|
||||
|
|
|
@ -49,10 +49,3 @@ class ForceReply(ReplyMarkup):
|
|||
self.force_reply = bool(force_reply)
|
||||
# Optionals
|
||||
self.selective = bool(selective)
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data, bot):
|
||||
if not data:
|
||||
return None
|
||||
|
||||
return cls(**data)
|
||||
|
|
|
@ -87,23 +87,3 @@ class InlineKeyboardButton(TelegramObject):
|
|||
self.switch_inline_query_current_chat = switch_inline_query_current_chat
|
||||
self.callback_game = callback_game
|
||||
self.pay = pay
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data, bot):
|
||||
data = super(InlineKeyboardButton, cls).de_json(data, bot)
|
||||
|
||||
if not data:
|
||||
return None
|
||||
|
||||
return cls(**data)
|
||||
|
||||
@classmethod
|
||||
def de_list(cls, data, bot):
|
||||
if not data:
|
||||
return []
|
||||
|
||||
inline_keyboards = list()
|
||||
for inline_keyboard in data:
|
||||
inline_keyboards.append(cls.de_json(inline_keyboard, bot))
|
||||
|
||||
return inline_keyboards
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains an object that represents a Telegram InlineKeyboardMarkup."""
|
||||
|
||||
from telegram import ReplyMarkup, InlineKeyboardButton
|
||||
from telegram import ReplyMarkup
|
||||
|
||||
|
||||
class InlineKeyboardMarkup(ReplyMarkup):
|
||||
|
@ -40,20 +40,6 @@ class InlineKeyboardMarkup(ReplyMarkup):
|
|||
# Required
|
||||
self.inline_keyboard = inline_keyboard
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data, bot):
|
||||
data = super(InlineKeyboardMarkup, cls).de_json(data, bot)
|
||||
|
||||
if not data:
|
||||
return None
|
||||
|
||||
data['inline_keyboard'] = [
|
||||
InlineKeyboardButton.de_list(inline_keyboard, bot)
|
||||
for inline_keyboard in data['inline_keyboard']
|
||||
]
|
||||
|
||||
return cls(**data)
|
||||
|
||||
def to_dict(self):
|
||||
data = super(InlineKeyboardMarkup, self).to_dict()
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains the classes that represent Telegram InlineQueryResultArticle."""
|
||||
|
||||
from telegram import InlineQueryResult, InlineKeyboardMarkup, InputMessageContent
|
||||
from telegram import InlineQueryResult
|
||||
|
||||
|
||||
class InlineQueryResultArticle(InlineQueryResult):
|
||||
|
@ -91,16 +91,3 @@ class InlineQueryResultArticle(InlineQueryResult):
|
|||
self.thumb_width = thumb_width
|
||||
if thumb_height:
|
||||
self.thumb_height = thumb_height
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data, bot):
|
||||
data = super(InlineQueryResultArticle, cls).de_json(data, bot)
|
||||
|
||||
if not data:
|
||||
return None
|
||||
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||
data['input_message_content'] = InputMessageContent.de_json(
|
||||
data.get('input_message_content'), bot)
|
||||
|
||||
return cls(**data)
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains the classes that represent Telegram InlineQueryResultAudio."""
|
||||
|
||||
from telegram import InlineQueryResult, InlineKeyboardMarkup, InputMessageContent
|
||||
from telegram import InlineQueryResult
|
||||
|
||||
|
||||
class InlineQueryResultAudio(InlineQueryResult):
|
||||
|
@ -82,16 +82,3 @@ class InlineQueryResultAudio(InlineQueryResult):
|
|||
self.reply_markup = reply_markup
|
||||
if input_message_content:
|
||||
self.input_message_content = input_message_content
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data, bot):
|
||||
data = super(InlineQueryResultAudio, cls).de_json(data, bot)
|
||||
|
||||
if not data:
|
||||
return None
|
||||
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||
data['input_message_content'] = InputMessageContent.de_json(
|
||||
data.get('input_message_content'), bot)
|
||||
|
||||
return cls(**data)
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains the classes that represent Telegram InlineQueryResultCachedAudio."""
|
||||
|
||||
from telegram import InlineQueryResult, InlineKeyboardMarkup, InputMessageContent
|
||||
from telegram import InlineQueryResult
|
||||
|
||||
|
||||
class InlineQueryResultCachedAudio(InlineQueryResult):
|
||||
|
@ -67,16 +67,3 @@ class InlineQueryResultCachedAudio(InlineQueryResult):
|
|||
self.reply_markup = reply_markup
|
||||
if input_message_content:
|
||||
self.input_message_content = input_message_content
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data, bot):
|
||||
data = super(InlineQueryResultCachedAudio, cls).de_json(data, bot)
|
||||
|
||||
if not data:
|
||||
return None
|
||||
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||
data['input_message_content'] = InputMessageContent.de_json(
|
||||
data.get('input_message_content'), bot)
|
||||
|
||||
return cls(**data)
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains the classes that represent Telegram InlineQueryResultCachedDocument."""
|
||||
|
||||
from telegram import InlineQueryResult, InlineKeyboardMarkup, InputMessageContent
|
||||
from telegram import InlineQueryResult
|
||||
|
||||
|
||||
class InlineQueryResultCachedDocument(InlineQueryResult):
|
||||
|
@ -76,16 +76,3 @@ class InlineQueryResultCachedDocument(InlineQueryResult):
|
|||
self.reply_markup = reply_markup
|
||||
if input_message_content:
|
||||
self.input_message_content = input_message_content
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data, bot):
|
||||
data = super(InlineQueryResultCachedDocument, cls).de_json(data, bot)
|
||||
|
||||
if not data:
|
||||
return None
|
||||
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||
data['input_message_content'] = InputMessageContent.de_json(
|
||||
data.get('input_message_content'), bot)
|
||||
|
||||
return cls(**data)
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains the classes that represent Telegram InlineQueryResultCachedGif."""
|
||||
|
||||
from telegram import InlineQueryResult, InlineKeyboardMarkup, InputMessageContent
|
||||
from telegram import InlineQueryResult
|
||||
|
||||
|
||||
class InlineQueryResultCachedGif(InlineQueryResult):
|
||||
|
@ -73,16 +73,3 @@ class InlineQueryResultCachedGif(InlineQueryResult):
|
|||
self.reply_markup = reply_markup
|
||||
if input_message_content:
|
||||
self.input_message_content = input_message_content
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data, bot):
|
||||
data = super(InlineQueryResultCachedGif, cls).de_json(data, bot)
|
||||
|
||||
if not data:
|
||||
return None
|
||||
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||
data['input_message_content'] = InputMessageContent.de_json(
|
||||
data.get('input_message_content'), bot)
|
||||
|
||||
return cls(**data)
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains the classes that represent Telegram InlineQueryResultMpeg4Gif."""
|
||||
|
||||
from telegram import InlineQueryResult, InlineKeyboardMarkup, InputMessageContent
|
||||
from telegram import InlineQueryResult
|
||||
|
||||
|
||||
class InlineQueryResultCachedMpeg4Gif(InlineQueryResult):
|
||||
|
@ -73,16 +73,3 @@ class InlineQueryResultCachedMpeg4Gif(InlineQueryResult):
|
|||
self.reply_markup = reply_markup
|
||||
if input_message_content:
|
||||
self.input_message_content = input_message_content
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data, bot):
|
||||
data = super(InlineQueryResultCachedMpeg4Gif, cls).de_json(data, bot)
|
||||
|
||||
if not data:
|
||||
return None
|
||||
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||
data['input_message_content'] = InputMessageContent.de_json(
|
||||
data.get('input_message_content'), bot)
|
||||
|
||||
return cls(**data)
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains the classes that represent Telegram InlineQueryResultPhoto"""
|
||||
|
||||
from telegram import InlineQueryResult, InlineKeyboardMarkup, InputMessageContent
|
||||
from telegram import InlineQueryResult
|
||||
|
||||
|
||||
class InlineQueryResultCachedPhoto(InlineQueryResult):
|
||||
|
@ -78,16 +78,3 @@ class InlineQueryResultCachedPhoto(InlineQueryResult):
|
|||
self.reply_markup = reply_markup
|
||||
if input_message_content:
|
||||
self.input_message_content = input_message_content
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data, bot):
|
||||
data = super(InlineQueryResultCachedPhoto, cls).de_json(data, bot)
|
||||
|
||||
if not data:
|
||||
return None
|
||||
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||
data['input_message_content'] = InputMessageContent.de_json(
|
||||
data.get('input_message_content'), bot)
|
||||
|
||||
return cls(**data)
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains the classes that represent Telegram InlineQueryResultCachedSticker."""
|
||||
|
||||
from telegram import InlineQueryResult, InlineKeyboardMarkup, InputMessageContent
|
||||
from telegram import InlineQueryResult
|
||||
|
||||
|
||||
class InlineQueryResultCachedSticker(InlineQueryResult):
|
||||
|
@ -62,16 +62,3 @@ class InlineQueryResultCachedSticker(InlineQueryResult):
|
|||
self.reply_markup = reply_markup
|
||||
if input_message_content:
|
||||
self.input_message_content = input_message_content
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data, bot):
|
||||
data = super(InlineQueryResultCachedSticker, cls).de_json(data, bot)
|
||||
|
||||
if not data:
|
||||
return None
|
||||
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||
data['input_message_content'] = InputMessageContent.de_json(
|
||||
data.get('input_message_content'), bot)
|
||||
|
||||
return cls(**data)
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains the classes that represent Telegram InlineQueryResultCachedVideo."""
|
||||
|
||||
from telegram import InlineQueryResult, InlineKeyboardMarkup, InputMessageContent
|
||||
from telegram import InlineQueryResult
|
||||
|
||||
|
||||
class InlineQueryResultCachedVideo(InlineQueryResult):
|
||||
|
@ -77,16 +77,3 @@ class InlineQueryResultCachedVideo(InlineQueryResult):
|
|||
self.reply_markup = reply_markup
|
||||
if input_message_content:
|
||||
self.input_message_content = input_message_content
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data, bot):
|
||||
data = super(InlineQueryResultCachedVideo, cls).de_json(data, bot)
|
||||
|
||||
if not data:
|
||||
return None
|
||||
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||
data['input_message_content'] = InputMessageContent.de_json(
|
||||
data.get('input_message_content'), bot)
|
||||
|
||||
return cls(**data)
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains the classes that represent Telegram InlineQueryResultCachedVoice."""
|
||||
|
||||
from telegram import InlineQueryResult, InlineKeyboardMarkup, InputMessageContent
|
||||
from telegram import InlineQueryResult
|
||||
|
||||
|
||||
class InlineQueryResultCachedVoice(InlineQueryResult):
|
||||
|
@ -71,16 +71,3 @@ class InlineQueryResultCachedVoice(InlineQueryResult):
|
|||
self.reply_markup = reply_markup
|
||||
if input_message_content:
|
||||
self.input_message_content = input_message_content
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data, bot):
|
||||
data = super(InlineQueryResultCachedVoice, cls).de_json(data, bot)
|
||||
|
||||
if not data:
|
||||
return None
|
||||
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||
data['input_message_content'] = InputMessageContent.de_json(
|
||||
data.get('input_message_content'), bot)
|
||||
|
||||
return cls(**data)
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains the classes that represent Telegram InlineQueryResultContact."""
|
||||
|
||||
from telegram import InlineQueryResult, InlineKeyboardMarkup, InputMessageContent
|
||||
from telegram import InlineQueryResult
|
||||
|
||||
|
||||
class InlineQueryResultContact(InlineQueryResult):
|
||||
|
@ -86,16 +86,3 @@ class InlineQueryResultContact(InlineQueryResult):
|
|||
self.thumb_width = thumb_width
|
||||
if thumb_height:
|
||||
self.thumb_height = thumb_height
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data, bot):
|
||||
data = super(InlineQueryResultContact, cls).de_json(data, bot)
|
||||
|
||||
if not data:
|
||||
return None
|
||||
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||
data['input_message_content'] = InputMessageContent.de_json(
|
||||
data.get('input_message_content'), bot)
|
||||
|
||||
return cls(**data)
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains the classes that represent Telegram InlineQueryResultDocument"""
|
||||
|
||||
from telegram import InlineQueryResult, InlineKeyboardMarkup, InputMessageContent
|
||||
from telegram import InlineQueryResult
|
||||
|
||||
|
||||
class InlineQueryResultDocument(InlineQueryResult):
|
||||
|
@ -98,16 +98,3 @@ class InlineQueryResultDocument(InlineQueryResult):
|
|||
self.thumb_width = thumb_width
|
||||
if thumb_height:
|
||||
self.thumb_height = thumb_height
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data, bot):
|
||||
data = super(InlineQueryResultDocument, cls).de_json(data, bot)
|
||||
|
||||
if not data:
|
||||
return None
|
||||
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||
data['input_message_content'] = InputMessageContent.de_json(
|
||||
data.get('input_message_content'), bot)
|
||||
|
||||
return cls(**data)
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains the classes that represent Telegram InlineQueryResultGame."""
|
||||
|
||||
from telegram import InlineQueryResult, InlineKeyboardMarkup
|
||||
from telegram import InlineQueryResult
|
||||
|
||||
|
||||
class InlineQueryResultGame(InlineQueryResult):
|
||||
|
@ -48,14 +48,3 @@ class InlineQueryResultGame(InlineQueryResult):
|
|||
|
||||
if reply_markup:
|
||||
self.reply_markup = reply_markup
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data, bot):
|
||||
data = super(InlineQueryResultGame, cls).de_json(data, bot)
|
||||
|
||||
if not data:
|
||||
return None
|
||||
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||
|
||||
return cls(**data)
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains the classes that represent Telegram InlineQueryResultGif."""
|
||||
|
||||
from telegram import InlineQueryResult, InlineKeyboardMarkup, InputMessageContent
|
||||
from telegram import InlineQueryResult
|
||||
|
||||
|
||||
class InlineQueryResultGif(InlineQueryResult):
|
||||
|
@ -92,16 +92,3 @@ class InlineQueryResultGif(InlineQueryResult):
|
|||
self.reply_markup = reply_markup
|
||||
if input_message_content:
|
||||
self.input_message_content = input_message_content
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data, bot):
|
||||
data = super(InlineQueryResultGif, cls).de_json(data, bot)
|
||||
|
||||
if not data:
|
||||
return None
|
||||
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||
data['input_message_content'] = InputMessageContent.de_json(
|
||||
data.get('input_message_content'), bot)
|
||||
|
||||
return cls(**data)
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains the classes that represent Telegram InlineQueryResultLocation."""
|
||||
|
||||
from telegram import InlineQueryResult, InlineKeyboardMarkup, InputMessageContent
|
||||
from telegram import InlineQueryResult
|
||||
|
||||
|
||||
class InlineQueryResultLocation(InlineQueryResult):
|
||||
|
@ -85,16 +85,3 @@ class InlineQueryResultLocation(InlineQueryResult):
|
|||
self.thumb_width = thumb_width
|
||||
if thumb_height:
|
||||
self.thumb_height = thumb_height
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data, bot):
|
||||
data = super(InlineQueryResultLocation, cls).de_json(data, bot)
|
||||
|
||||
if not data:
|
||||
return None
|
||||
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||
data['input_message_content'] = InputMessageContent.de_json(
|
||||
data.get('input_message_content'), bot)
|
||||
|
||||
return cls(**data)
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains the classes that represent Telegram InlineQueryResultMpeg4Gif."""
|
||||
|
||||
from telegram import InlineQueryResult, InlineKeyboardMarkup, InputMessageContent
|
||||
from telegram import InlineQueryResult
|
||||
|
||||
|
||||
class InlineQueryResultMpeg4Gif(InlineQueryResult):
|
||||
|
@ -93,16 +93,3 @@ class InlineQueryResultMpeg4Gif(InlineQueryResult):
|
|||
self.reply_markup = reply_markup
|
||||
if input_message_content:
|
||||
self.input_message_content = input_message_content
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data, bot):
|
||||
data = super(InlineQueryResultMpeg4Gif, cls).de_json(data, bot)
|
||||
|
||||
if not data:
|
||||
return None
|
||||
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||
data['input_message_content'] = InputMessageContent.de_json(
|
||||
data.get('input_message_content'), bot)
|
||||
|
||||
return cls(**data)
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains the classes that represent Telegram InlineQueryResultPhoto."""
|
||||
|
||||
from telegram import InlineQueryResult, InlineKeyboardMarkup, InputMessageContent
|
||||
from telegram import InlineQueryResult
|
||||
|
||||
|
||||
class InlineQueryResultPhoto(InlineQueryResult):
|
||||
|
@ -93,16 +93,3 @@ class InlineQueryResultPhoto(InlineQueryResult):
|
|||
self.reply_markup = reply_markup
|
||||
if input_message_content:
|
||||
self.input_message_content = input_message_content
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data, bot):
|
||||
data = super(InlineQueryResultPhoto, cls).de_json(data, bot)
|
||||
|
||||
if not data:
|
||||
return None
|
||||
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||
data['input_message_content'] = InputMessageContent.de_json(
|
||||
data.get('input_message_content'), bot)
|
||||
|
||||
return cls(**data)
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains the classes that represent Telegram InlineQueryResultVenue."""
|
||||
|
||||
from telegram import InlineQueryResult, InlineKeyboardMarkup, InputMessageContent
|
||||
from telegram import InlineQueryResult
|
||||
|
||||
|
||||
class InlineQueryResultVenue(InlineQueryResult):
|
||||
|
@ -95,16 +95,3 @@ class InlineQueryResultVenue(InlineQueryResult):
|
|||
self.thumb_width = thumb_width
|
||||
if thumb_height:
|
||||
self.thumb_height = thumb_height
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data, bot):
|
||||
data = super(InlineQueryResultVenue, cls).de_json(data, bot)
|
||||
|
||||
if not data:
|
||||
return None
|
||||
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||
data['input_message_content'] = InputMessageContent.de_json(
|
||||
data.get('input_message_content'), bot)
|
||||
|
||||
return cls(**data)
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains the classes that represent Telegram InlineQueryResultVideo."""
|
||||
|
||||
from telegram import InlineQueryResult, InlineKeyboardMarkup, InputMessageContent
|
||||
from telegram import InlineQueryResult
|
||||
|
||||
|
||||
class InlineQueryResultVideo(InlineQueryResult):
|
||||
|
@ -101,16 +101,3 @@ class InlineQueryResultVideo(InlineQueryResult):
|
|||
self.reply_markup = reply_markup
|
||||
if input_message_content:
|
||||
self.input_message_content = input_message_content
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data, bot):
|
||||
data = super(InlineQueryResultVideo, cls).de_json(data, bot)
|
||||
|
||||
if not data:
|
||||
return None
|
||||
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||
data['input_message_content'] = InputMessageContent.de_json(
|
||||
data.get('input_message_content'), bot)
|
||||
|
||||
return cls(**data)
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains the classes that represent Telegram InlineQueryResultVoice."""
|
||||
|
||||
from telegram import InlineQueryResult, InlineKeyboardMarkup, InputMessageContent
|
||||
from telegram import InlineQueryResult
|
||||
|
||||
|
||||
class InlineQueryResultVoice(InlineQueryResult):
|
||||
|
@ -78,16 +78,3 @@ class InlineQueryResultVoice(InlineQueryResult):
|
|||
self.reply_markup = reply_markup
|
||||
if input_message_content:
|
||||
self.input_message_content = input_message_content
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data, bot):
|
||||
data = super(InlineQueryResultVoice, cls).de_json(data, bot)
|
||||
|
||||
if not data:
|
||||
return None
|
||||
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
|
||||
data['input_message_content'] = InputMessageContent.de_json(
|
||||
data.get('input_message_content'), bot)
|
||||
|
||||
return cls(**data)
|
||||
|
|
|
@ -43,7 +43,3 @@ class InputContactMessageContent(InputMessageContent):
|
|||
self.first_name = first_name
|
||||
# Optionals
|
||||
self.last_name = last_name
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data, bot):
|
||||
return cls(**data)
|
||||
|
|
|
@ -40,7 +40,3 @@ class InputLocationMessageContent(InputMessageContent):
|
|||
# Required
|
||||
self.latitude = latitude
|
||||
self.longitude = longitude
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data, bot):
|
||||
return cls(**data)
|
||||
|
|
|
@ -29,36 +29,4 @@ class InputMessageContent(TelegramObject):
|
|||
:class:`telegram.InputVenueMessageContent` for more details.
|
||||
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data, bot):
|
||||
data = super(InputMessageContent, cls).de_json(data, bot)
|
||||
|
||||
if not data:
|
||||
return None
|
||||
|
||||
try:
|
||||
from telegram import InputTextMessageContent
|
||||
return InputTextMessageContent.de_json(data, bot)
|
||||
except TypeError:
|
||||
pass
|
||||
|
||||
try:
|
||||
from telegram import InputVenueMessageContent
|
||||
return InputVenueMessageContent.de_json(data, bot)
|
||||
except TypeError:
|
||||
pass
|
||||
|
||||
try:
|
||||
from telegram import InputLocationMessageContent
|
||||
return InputLocationMessageContent.de_json(data, bot)
|
||||
except TypeError:
|
||||
pass
|
||||
|
||||
try:
|
||||
from telegram import InputContactMessageContent
|
||||
return InputContactMessageContent.de_json(data, bot)
|
||||
except TypeError:
|
||||
pass
|
||||
|
||||
return None
|
||||
pass
|
||||
|
|
|
@ -49,7 +49,3 @@ class InputTextMessageContent(InputMessageContent):
|
|||
# Optionals
|
||||
self.parse_mode = parse_mode
|
||||
self.disable_web_page_preview = disable_web_page_preview
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data, bot):
|
||||
return cls(**data)
|
||||
|
|
|
@ -49,7 +49,3 @@ class InputVenueMessageContent(InputMessageContent):
|
|||
self.address = address
|
||||
# Optionals
|
||||
self.foursquare_id = foursquare_id
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data, bot):
|
||||
return cls(**data)
|
||||
|
|
|
@ -54,21 +54,3 @@ class KeyboardButton(TelegramObject):
|
|||
# Optionals
|
||||
self.request_contact = request_contact
|
||||
self.request_location = request_location
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data, bot):
|
||||
if not data:
|
||||
return None
|
||||
|
||||
return cls(**data)
|
||||
|
||||
@classmethod
|
||||
def de_list(cls, data, bot):
|
||||
if not data:
|
||||
return []
|
||||
|
||||
keyboards = list()
|
||||
for keyboard in data:
|
||||
keyboards.append(cls.de_json(keyboard, bot))
|
||||
|
||||
return keyboards
|
||||
|
|
|
@ -41,21 +41,3 @@ class LabeledPrice(TelegramObject):
|
|||
def __init__(self, label, amount, **kwargs):
|
||||
self.label = label
|
||||
self.amount = amount
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data, bot):
|
||||
if not data:
|
||||
return None
|
||||
|
||||
return cls(**data)
|
||||
|
||||
@classmethod
|
||||
def de_list(cls, data, bot):
|
||||
if not data:
|
||||
return []
|
||||
|
||||
labeled_prices = list()
|
||||
for labeled_price in data:
|
||||
labeled_prices.append(cls.de_json(labeled_price, bot))
|
||||
|
||||
return labeled_prices
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains an object that represents a Telegram ShippingOption."""
|
||||
|
||||
from telegram import TelegramObject, LabeledPrice
|
||||
from telegram import TelegramObject
|
||||
|
||||
|
||||
class ShippingOption(TelegramObject):
|
||||
|
@ -44,17 +44,6 @@ class ShippingOption(TelegramObject):
|
|||
|
||||
self._id_attrs = (self.id,)
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data, bot):
|
||||
if not data:
|
||||
return None
|
||||
|
||||
data = super(ShippingOption, cls).de_json(data, bot)
|
||||
|
||||
data['prices'] = LabeledPrice.de_list(data.get('prices'), bot)
|
||||
|
||||
return cls(**data)
|
||||
|
||||
def to_dict(self):
|
||||
data = super(ShippingOption, self).to_dict()
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains an object that represents a Telegram ReplyKeyboardMarkup."""
|
||||
|
||||
from telegram import ReplyMarkup, KeyboardButton
|
||||
from telegram import ReplyMarkup
|
||||
|
||||
|
||||
class ReplyKeyboardMarkup(ReplyMarkup):
|
||||
|
@ -72,17 +72,6 @@ class ReplyKeyboardMarkup(ReplyMarkup):
|
|||
self.one_time_keyboard = bool(one_time_keyboard)
|
||||
self.selective = bool(selective)
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data, bot):
|
||||
if not data:
|
||||
return None
|
||||
|
||||
data = super(ReplyKeyboardMarkup, cls).de_json(data, bot)
|
||||
|
||||
data['keyboard'] = [KeyboardButton.de_list(keyboard, bot) for keyboard in data['keyboard']]
|
||||
|
||||
return cls(**data)
|
||||
|
||||
def to_dict(self):
|
||||
data = super(ReplyKeyboardMarkup, self).to_dict()
|
||||
|
||||
|
|
|
@ -54,10 +54,3 @@ class ReplyKeyboardRemove(ReplyMarkup):
|
|||
self.remove_keyboard = True
|
||||
# Optionals
|
||||
self.selective = bool(selective)
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data, bot):
|
||||
if not data:
|
||||
return None
|
||||
|
||||
return cls(**data)
|
||||
|
|
|
@ -43,19 +43,7 @@ class TestInlineKeyboardButton(object):
|
|||
callback_game = 'callback_game'
|
||||
pay = 'pay'
|
||||
|
||||
def test_de_json(self, bot):
|
||||
json_dict = {
|
||||
'text': self.text,
|
||||
'url': self.url,
|
||||
'callback_data': self.callback_data,
|
||||
'switch_inline_query': self.switch_inline_query,
|
||||
'switch_inline_query_current_chat':
|
||||
self.switch_inline_query_current_chat,
|
||||
'callback_game': self.callback_game,
|
||||
'pay': self.pay
|
||||
}
|
||||
inline_keyboard_button = InlineKeyboardButton.de_json(json_dict, bot)
|
||||
|
||||
def test_expected_values(self, inline_keyboard_button):
|
||||
assert inline_keyboard_button.text == self.text
|
||||
assert inline_keyboard_button.url == self.url
|
||||
assert inline_keyboard_button.callback_data == self.callback_data
|
||||
|
@ -65,12 +53,6 @@ class TestInlineKeyboardButton(object):
|
|||
assert inline_keyboard_button.callback_game == self.callback_game
|
||||
assert inline_keyboard_button.pay == self.pay
|
||||
|
||||
def test_de_list(self, bot, inline_keyboard_button):
|
||||
keyboard_json = [inline_keyboard_button.to_dict(), inline_keyboard_button.to_dict()]
|
||||
inline_keyboard_buttons = InlineKeyboardButton.de_list(keyboard_json, bot)
|
||||
|
||||
assert inline_keyboard_buttons == [inline_keyboard_button, inline_keyboard_button]
|
||||
|
||||
def test_to_dict(self, inline_keyboard_button):
|
||||
inline_keyboard_button_dict = inline_keyboard_button.to_dict()
|
||||
|
||||
|
|
|
@ -41,16 +41,8 @@ class TestInlineKeyboardMarkup(object):
|
|||
|
||||
assert message.text == 'Testing InlineKeyboardMarkup'
|
||||
|
||||
def test_de_json(self, bot, inline_keyboard_markup):
|
||||
json_dict = {
|
||||
'inline_keyboard': [[
|
||||
self.inline_keyboard[0][0].to_dict(),
|
||||
self.inline_keyboard[0][1].to_dict()
|
||||
]],
|
||||
}
|
||||
inline_keyboard_markup_json = InlineKeyboardMarkup.de_json(json_dict, bot)
|
||||
|
||||
assert inline_keyboard_markup_json.to_dict() == inline_keyboard_markup.to_dict()
|
||||
def test_expected_values(self, inline_keyboard_markup):
|
||||
assert inline_keyboard_markup.inline_keyboard == self.inline_keyboard
|
||||
|
||||
def test_to_dict(self, inline_keyboard_markup):
|
||||
inline_keyboard_markup_dict = inline_keyboard_markup.to_dict()
|
||||
|
|
|
@ -19,16 +19,7 @@
|
|||
|
||||
import pytest
|
||||
|
||||
from telegram import InputContactMessageContent, InputMessageContent
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def json_dict():
|
||||
return {
|
||||
'first_name': TestInputContactMessageContent.first_name,
|
||||
'phone_number': TestInputContactMessageContent.phone_number,
|
||||
'last_name': TestInputContactMessageContent.last_name,
|
||||
}
|
||||
from telegram import InputContactMessageContent
|
||||
|
||||
|
||||
@pytest.fixture(scope='class')
|
||||
|
@ -43,25 +34,10 @@ class TestInputContactMessageContent(object):
|
|||
first_name = 'first name'
|
||||
last_name = 'last name'
|
||||
|
||||
def test_de_json(self, json_dict, bot):
|
||||
input_contact_message_content_json = InputContactMessageContent.de_json(json_dict, bot)
|
||||
|
||||
assert input_contact_message_content_json.first_name == self.first_name
|
||||
assert input_contact_message_content_json.phone_number == self.phone_number
|
||||
assert input_contact_message_content_json.last_name == self.last_name
|
||||
|
||||
def test_de_json_factory(self, json_dict, bot):
|
||||
input_contact_message_content_json = InputMessageContent.de_json(json_dict, bot)
|
||||
|
||||
assert isinstance(input_contact_message_content_json, InputContactMessageContent)
|
||||
|
||||
def test_de_json_factory_without_required_args(self, json_dict, bot):
|
||||
del (json_dict['phone_number'])
|
||||
del (json_dict['first_name'])
|
||||
|
||||
input_contact_message_content_json = InputMessageContent.de_json(json_dict, bot)
|
||||
|
||||
assert input_contact_message_content_json is None
|
||||
def test_expected_values(self, input_contact_message_content):
|
||||
assert input_contact_message_content.first_name == self.first_name
|
||||
assert input_contact_message_content.phone_number == self.phone_number
|
||||
assert input_contact_message_content.last_name == self.last_name
|
||||
|
||||
def test_to_dict(self, input_contact_message_content):
|
||||
input_contact_message_content_dict = input_contact_message_content.to_dict()
|
||||
|
|
|
@ -19,46 +19,22 @@
|
|||
|
||||
import pytest
|
||||
|
||||
from telegram import InputMessageContent, InputLocationMessageContent
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def json_dict():
|
||||
return {
|
||||
'longitude': TestInputLocationMessageContent.longitude,
|
||||
'latitude': TestInputLocationMessageContent.latitude,
|
||||
}
|
||||
from telegram import InputLocationMessageContent
|
||||
|
||||
|
||||
@pytest.fixture(scope='class')
|
||||
def input_location_message_content():
|
||||
return InputLocationMessageContent(TestInputLocationMessageContent.longitude,
|
||||
TestInputLocationMessageContent.latitude)
|
||||
return InputLocationMessageContent(TestInputLocationMessageContent.latitude,
|
||||
TestInputLocationMessageContent.longitude)
|
||||
|
||||
|
||||
class TestInputLocationMessageContent(object):
|
||||
latitude = 1.
|
||||
longitude = 2.
|
||||
latitude = -23.691288
|
||||
longitude = -46.788279
|
||||
|
||||
def test_de_json(self, json_dict, bot):
|
||||
input_location_message_content_json = InputLocationMessageContent.de_json(json_dict, bot)
|
||||
|
||||
assert input_location_message_content_json.longitude == self.longitude
|
||||
assert input_location_message_content_json.latitude == self.latitude
|
||||
|
||||
def test_input_location_message_content_json_de_json_factory(self, json_dict, bot):
|
||||
input_location_message_content_json = InputMessageContent.de_json(json_dict, bot)
|
||||
|
||||
assert isinstance(input_location_message_content_json, InputLocationMessageContent)
|
||||
|
||||
def test_de_json_factory_without_required_args(self, json_dict, bot):
|
||||
del (json_dict['longitude'])
|
||||
# If no args are passed it will fall in a different condition
|
||||
# del (json_dict['latitude'])
|
||||
|
||||
input_location_message_content_json = InputMessageContent.de_json(json_dict, bot)
|
||||
|
||||
assert input_location_message_content_json is None
|
||||
def test_expected_values(self, input_location_message_content):
|
||||
assert input_location_message_content.longitude == self.longitude
|
||||
assert input_location_message_content.latitude == self.latitude
|
||||
|
||||
def test_to_dict(self, input_location_message_content):
|
||||
input_location_message_content_dict = input_location_message_content.to_dict()
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2017
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
from telegram import InputMessageContent
|
||||
|
||||
|
||||
class TestInputMessageContent(object):
|
||||
def test_de_json(self, bot):
|
||||
input_message_content = InputMessageContent.de_json(None, bot)
|
||||
|
||||
assert input_message_content is None
|
|
@ -19,16 +19,7 @@
|
|||
|
||||
import pytest
|
||||
|
||||
from telegram import InputTextMessageContent, InputMessageContent, ParseMode
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def json_dict():
|
||||
return {
|
||||
'parse_mode': TestInputTextMessageContent.parse_mode,
|
||||
'message_text': TestInputTextMessageContent.message_text,
|
||||
'disable_web_page_preview': TestInputTextMessageContent.disable_web_page_preview,
|
||||
}
|
||||
from telegram import InputTextMessageContent, ParseMode
|
||||
|
||||
|
||||
@pytest.fixture(scope='class')
|
||||
|
@ -43,25 +34,10 @@ class TestInputTextMessageContent(object):
|
|||
parse_mode = ParseMode.MARKDOWN
|
||||
disable_web_page_preview = True
|
||||
|
||||
def test_de_json(self, json_dict, bot):
|
||||
input_text_message_content_json = InputTextMessageContent.de_json(json_dict, bot)
|
||||
|
||||
assert input_text_message_content_json.parse_mode == self.parse_mode
|
||||
assert input_text_message_content_json.message_text == self.message_text
|
||||
assert input_text_message_content_json.disable_web_page_preview == \
|
||||
self.disable_web_page_preview
|
||||
|
||||
def test_input_text_message_content_json_de_json_factory(self, json_dict, bot):
|
||||
input_text_message_content_json = InputMessageContent.de_json(json_dict, bot)
|
||||
|
||||
assert isinstance(input_text_message_content_json, InputTextMessageContent)
|
||||
|
||||
def test_de_json_factory_without_required_args(self, json_dict, bot):
|
||||
del (json_dict['message_text'])
|
||||
|
||||
input_text_message_content_json = InputMessageContent.de_json(json_dict, bot)
|
||||
|
||||
assert input_text_message_content_json is None
|
||||
def test_expected_values(self, input_text_message_content):
|
||||
assert input_text_message_content.parse_mode == self.parse_mode
|
||||
assert input_text_message_content.message_text == self.message_text
|
||||
assert input_text_message_content.disable_web_page_preview == self.disable_web_page_preview
|
||||
|
||||
def test_to_dict(self, input_text_message_content):
|
||||
input_text_message_content_dict = input_text_message_content.to_dict()
|
||||
|
|
|
@ -19,18 +19,7 @@
|
|||
|
||||
import pytest
|
||||
|
||||
from telegram import InputVenueMessageContent, InputMessageContent
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def json_dict():
|
||||
return {
|
||||
'longitude': TestInputVenueMessageContent.longitude,
|
||||
'latitude': TestInputVenueMessageContent.latitude,
|
||||
'title': TestInputVenueMessageContent.title,
|
||||
'address': TestInputVenueMessageContent.address,
|
||||
'foursquare_id': TestInputVenueMessageContent.foursquare_id,
|
||||
}
|
||||
from telegram import InputVenueMessageContent
|
||||
|
||||
|
||||
@pytest.fixture(scope='class')
|
||||
|
@ -49,31 +38,12 @@ class TestInputVenueMessageContent(object):
|
|||
address = 'address'
|
||||
foursquare_id = 'foursquare id'
|
||||
|
||||
def test_de_json(self, json_dict, bot):
|
||||
input_venue_message_content_json = InputVenueMessageContent.de_json(json_dict, bot)
|
||||
|
||||
assert input_venue_message_content_json.longitude == self.longitude
|
||||
assert input_venue_message_content_json.latitude == self.latitude
|
||||
assert input_venue_message_content_json.title == self.title
|
||||
assert input_venue_message_content_json.address == self.address
|
||||
assert input_venue_message_content_json.foursquare_id == self.foursquare_id
|
||||
|
||||
def test_de_json_factory(self, json_dict, bot):
|
||||
input_venue_message_content_json = InputMessageContent.de_json(json_dict, bot)
|
||||
|
||||
assert isinstance(input_venue_message_content_json, InputVenueMessageContent)
|
||||
|
||||
def test_de_json_factory_without_required_args(self, json_dict, bot):
|
||||
json_dict = json_dict
|
||||
|
||||
del (json_dict['longitude'])
|
||||
del (json_dict['latitude'])
|
||||
del (json_dict['title'])
|
||||
del (json_dict['address'])
|
||||
|
||||
input_venue_message_content_json = InputMessageContent.de_json(json_dict, bot)
|
||||
|
||||
assert input_venue_message_content_json is None
|
||||
def test_expected_values(self, input_venue_message_content):
|
||||
assert input_venue_message_content.longitude == self.longitude
|
||||
assert input_venue_message_content.latitude == self.latitude
|
||||
assert input_venue_message_content.title == self.title
|
||||
assert input_venue_message_content.address == self.address
|
||||
assert input_venue_message_content.foursquare_id == self.foursquare_id
|
||||
|
||||
def test_to_dict(self, input_venue_message_content):
|
||||
input_venue_message_content_dict = input_venue_message_content.to_dict()
|
||||
|
|
|
@ -39,12 +39,6 @@ class TestKeyboardButton(object):
|
|||
assert keyboard_button.request_location == self.request_location
|
||||
assert keyboard_button.request_contact == self.request_contact
|
||||
|
||||
def test_de_list(self, bot, keyboard_button):
|
||||
keyboard_json = [keyboard_button.to_dict(), keyboard_button.to_dict()]
|
||||
inline_keyboard_buttons = KeyboardButton.de_list(keyboard_json, bot)
|
||||
|
||||
assert inline_keyboard_buttons == [keyboard_button, keyboard_button]
|
||||
|
||||
def test_to_dict(self, keyboard_button):
|
||||
keyboard_button_dict = keyboard_button.to_dict()
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue