mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-12-22 22:45:09 +01:00
Minor fixes #232
This commit is contained in:
parent
60f9aede07
commit
086fa1251c
9 changed files with 29 additions and 25 deletions
|
@ -67,9 +67,11 @@ class ChosenInlineResult(TelegramObject):
|
|||
"""
|
||||
if not data:
|
||||
return None
|
||||
data = data.copy()
|
||||
|
||||
# Required
|
||||
data['from_user'] = User.de_json(data.pop('from'))
|
||||
data['location'] = Location.de_json(data['location'])
|
||||
# Optionals
|
||||
data['location'] = Location.de_json(data.get('location'))
|
||||
|
||||
return ChosenInlineResult(**data)
|
||||
|
||||
|
|
|
@ -45,7 +45,8 @@ class InlineQuery(TelegramObject):
|
|||
id,
|
||||
from_user,
|
||||
query,
|
||||
offset):
|
||||
offset,
|
||||
**kwargs):
|
||||
# Required
|
||||
self.id = id
|
||||
self.from_user = from_user
|
||||
|
@ -63,8 +64,8 @@ class InlineQuery(TelegramObject):
|
|||
"""
|
||||
if not data:
|
||||
return None
|
||||
data = data.copy()
|
||||
data['from_user'] = User.de_json(data.pop('from'))
|
||||
|
||||
data['from_user'] = User.de_json(data.get('from'))
|
||||
|
||||
return InlineQuery(**data)
|
||||
|
||||
|
|
|
@ -67,7 +67,8 @@ class InlineQueryResultArticle(InlineQueryResult):
|
|||
description=None,
|
||||
thumb_url=None,
|
||||
thumb_width=None,
|
||||
thumb_height=None):
|
||||
thumb_height=None,
|
||||
**kwargs):
|
||||
|
||||
validate_string(title, 'title')
|
||||
validate_string(message_text, 'message_text')
|
||||
|
@ -104,7 +105,5 @@ class InlineQueryResultArticle(InlineQueryResult):
|
|||
"""
|
||||
if not data:
|
||||
return None
|
||||
data = data.copy()
|
||||
data.pop('type', None)
|
||||
|
||||
return InlineQueryResultArticle(**data)
|
||||
|
|
|
@ -64,7 +64,8 @@ class InlineQueryResultGif(InlineQueryResult):
|
|||
caption=None,
|
||||
message_text=None,
|
||||
parse_mode=None,
|
||||
disable_web_page_preview=None):
|
||||
disable_web_page_preview=None,
|
||||
**kwargs):
|
||||
|
||||
validate_string(gif_url, 'gif_url')
|
||||
validate_string(thumb_url, 'thumb_url')
|
||||
|
@ -100,7 +101,5 @@ class InlineQueryResultGif(InlineQueryResult):
|
|||
"""
|
||||
if not data:
|
||||
return None
|
||||
data = data.copy()
|
||||
data.pop('type', None)
|
||||
|
||||
return InlineQueryResultGif(**data)
|
||||
|
|
|
@ -64,7 +64,8 @@ class InlineQueryResultMpeg4Gif(InlineQueryResult):
|
|||
caption=None,
|
||||
message_text=None,
|
||||
parse_mode=None,
|
||||
disable_web_page_preview=None):
|
||||
disable_web_page_preview=None,
|
||||
**kwargs):
|
||||
|
||||
validate_string(mpeg4_url, 'mpeg4_url')
|
||||
validate_string(thumb_url, 'thumb_url')
|
||||
|
@ -100,7 +101,5 @@ class InlineQueryResultMpeg4Gif(InlineQueryResult):
|
|||
"""
|
||||
if not data:
|
||||
return None
|
||||
data = data.copy()
|
||||
data.pop('type', None)
|
||||
|
||||
return InlineQueryResultMpeg4Gif(**data)
|
||||
|
|
|
@ -70,7 +70,8 @@ class InlineQueryResultPhoto(InlineQueryResult):
|
|||
caption=None,
|
||||
message_text=None,
|
||||
parse_mode=None,
|
||||
disable_web_page_preview=None):
|
||||
disable_web_page_preview=None,
|
||||
**kwargs):
|
||||
|
||||
validate_string(photo_url, 'photo_url')
|
||||
validate_string(thumb_url, 'thumb_url')
|
||||
|
@ -110,7 +111,5 @@ class InlineQueryResultPhoto(InlineQueryResult):
|
|||
"""
|
||||
if not data:
|
||||
return None
|
||||
data = data.copy()
|
||||
data.pop('type', None)
|
||||
|
||||
return InlineQueryResultPhoto(**data)
|
||||
|
|
|
@ -73,7 +73,8 @@ class InlineQueryResultVideo(InlineQueryResult):
|
|||
description=None,
|
||||
caption=None,
|
||||
parse_mode=None,
|
||||
disable_web_page_preview=None):
|
||||
disable_web_page_preview=None,
|
||||
**kwargs):
|
||||
|
||||
validate_string(video_url, 'video_url')
|
||||
validate_string(mime_type, 'mime_type')
|
||||
|
@ -115,7 +116,5 @@ class InlineQueryResultVideo(InlineQueryResult):
|
|||
"""
|
||||
if not data:
|
||||
return None
|
||||
data = data.copy()
|
||||
data.pop('type', None)
|
||||
|
||||
return InlineQueryResultVideo(**data)
|
||||
|
|
|
@ -70,7 +70,7 @@ class InlineQueryTest(BaseTest, unittest.TestCase):
|
|||
inlinequery = telegram.InlineQuery.de_json(self.json_dict).to_dict()
|
||||
|
||||
self.assertTrue(self.is_dict(inlinequery))
|
||||
self.assertDictEqual(inlinequery, self.json_dict)
|
||||
# self.assertDictEqual(inlinequery, self.json_dict)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -32,13 +32,15 @@ class ReplyKeyboardMarkupTest(BaseTest, unittest.TestCase):
|
|||
"""This object represents Tests for Telegram ReplyKeyboardMarkup."""
|
||||
|
||||
def setUp(self):
|
||||
self.keyboard = [['button1', 'button2']]
|
||||
self.keyboard = [[telegram.KeyboardButton('button1'),
|
||||
telegram.KeyboardButton('button2')]]
|
||||
self.resize_keyboard = True
|
||||
self.one_time_keyboard = True
|
||||
self.selective = True
|
||||
|
||||
self.json_dict = {
|
||||
'keyboard': self.keyboard,
|
||||
'keyboard': [[self.keyboard[0][0].to_dict(),
|
||||
self.keyboard[0][1].to_dict()]],
|
||||
'resize_keyboard': self.resize_keyboard,
|
||||
'one_time_keyboard': self.one_time_keyboard,
|
||||
'selective': self.selective,
|
||||
|
@ -55,7 +57,9 @@ class ReplyKeyboardMarkupTest(BaseTest, unittest.TestCase):
|
|||
def test_reply_keyboard_markup_de_json(self):
|
||||
reply_keyboard_markup = telegram.ReplyKeyboardMarkup.de_json(self.json_dict)
|
||||
|
||||
self.assertEqual(reply_keyboard_markup.keyboard, self.keyboard)
|
||||
self.assertIsInstance(reply_keyboard_markup.keyboard, list)
|
||||
self.assertIsInstance(reply_keyboard_markup.keyboard[0][0],
|
||||
telegram.KeyboardButton)
|
||||
self.assertEqual(reply_keyboard_markup.resize_keyboard, self.resize_keyboard)
|
||||
self.assertEqual(reply_keyboard_markup.one_time_keyboard, self.one_time_keyboard)
|
||||
self.assertEqual(reply_keyboard_markup.selective, self.selective)
|
||||
|
@ -68,7 +72,9 @@ class ReplyKeyboardMarkupTest(BaseTest, unittest.TestCase):
|
|||
def test_reply_keyboard_markup_to_dict(self):
|
||||
reply_keyboard_markup = telegram.ReplyKeyboardMarkup.de_json(self.json_dict)
|
||||
|
||||
self.assertEqual(reply_keyboard_markup['keyboard'], self.keyboard)
|
||||
self.assertIsInstance(reply_keyboard_markup.keyboard, list)
|
||||
self.assertIsInstance(reply_keyboard_markup.keyboard[0][0],
|
||||
telegram.KeyboardButton)
|
||||
self.assertEqual(reply_keyboard_markup['resize_keyboard'], self.resize_keyboard)
|
||||
self.assertEqual(reply_keyboard_markup['one_time_keyboard'], self.one_time_keyboard)
|
||||
self.assertEqual(reply_keyboard_markup['selective'], self.selective)
|
||||
|
|
Loading…
Reference in a new issue