mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2025-02-16 18:31:45 +01:00
fixes broken test cases with PhotoSize, Game and Animation classes (#435)
* fixes broken test with PhotoSize, Game and Animation However: testSendGame and test_set_game_score both produces *BadRequest: u'Wrong file identifier/HTTP URL specified'*. * fixes test_set_game_score * adds to_dict method to Game to prevent extra collection type checks in base.TelegramObject
This commit is contained in:
parent
7ad92dcc65
commit
8dc10fc7b2
4 changed files with 40 additions and 13 deletions
|
@ -37,10 +37,6 @@ class Animation(TelegramObject):
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
file_id,
|
file_id,
|
||||||
thumb=None,
|
|
||||||
file_name=None,
|
|
||||||
mime_type=None,
|
|
||||||
file_size=None,
|
|
||||||
**kwargs):
|
**kwargs):
|
||||||
self.file_id = file_id
|
self.file_id = file_id
|
||||||
self.thumb = kwargs.get('thumb')
|
self.thumb = kwargs.get('thumb')
|
||||||
|
|
|
@ -79,6 +79,18 @@ class Game(TelegramObject):
|
||||||
|
|
||||||
return Game(**data)
|
return Game(**data)
|
||||||
|
|
||||||
|
def to_dict(self):
|
||||||
|
"""
|
||||||
|
Returns:
|
||||||
|
dict:
|
||||||
|
"""
|
||||||
|
data = super(Game, self).to_dict()
|
||||||
|
|
||||||
|
data['photo'] = [p.to_dict() for p in self.photo]
|
||||||
|
data['text_entities'] = [x.to_dict() for x in self.text_entities]
|
||||||
|
|
||||||
|
return data
|
||||||
|
|
||||||
def parse_text_entity(self, entity):
|
def parse_text_entity(self, entity):
|
||||||
"""
|
"""
|
||||||
Returns the text from a given :class:`telegram.MessageEntity`.
|
Returns the text from a given :class:`telegram.MessageEntity`.
|
||||||
|
|
|
@ -292,7 +292,7 @@ class BotTest(BaseTest, unittest.TestCase):
|
||||||
|
|
||||||
self.assertTrue(self.is_json(game.to_json()))
|
self.assertTrue(self.is_json(game.to_json()))
|
||||||
self.assertEqual(message.game.description, game.game.description)
|
self.assertEqual(message.game.description, game.game.description)
|
||||||
self.assertEqual(message.game.animation.file_id, game.game.animation)
|
self.assertEqual(message.game.animation, game.game.animation)
|
||||||
self.assertEqual(message.game.photo[0].file_size, game.game.photo[0].file_size)
|
self.assertEqual(message.game.photo[0].file_size, game.game.photo[0].file_size)
|
||||||
self.assertNotEqual(message.game.text, game.game.text)
|
self.assertNotEqual(message.game.text, game.game.text)
|
||||||
|
|
||||||
|
|
|
@ -34,19 +34,33 @@ class GameTest(BaseTest, unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.title = 'Python-telegram-bot Test Game'
|
self.title = 'Python-telegram-bot Test Game'
|
||||||
self.description = 'description'
|
self.description = 'description'
|
||||||
self.photo = [telegram.PhotoSize(file_id='Blah', width=640, height=360)]
|
self.photo = [
|
||||||
|
{
|
||||||
|
'width': 640,
|
||||||
|
'height': 360,
|
||||||
|
'file_id': 'Blah',
|
||||||
|
'file_size': 0
|
||||||
|
}
|
||||||
|
]
|
||||||
self.text = 'Other description'
|
self.text = 'Other description'
|
||||||
self.text_entities = [telegram.MessageEntity(
|
self.text_entities = [
|
||||||
type=telegram.MessageEntity.URL, offset=13, length=17)]
|
{
|
||||||
self.animation = telegram.Animation(file_id='Bleh')
|
'offset': 13,
|
||||||
|
'length': 17,
|
||||||
|
'type': telegram.MessageEntity.URL
|
||||||
|
}
|
||||||
|
]
|
||||||
|
self.animation = {
|
||||||
|
'file_id': 'Blah'
|
||||||
|
}
|
||||||
|
|
||||||
self.json_dict = {
|
self.json_dict = {
|
||||||
'title': self.title,
|
'title': self.title,
|
||||||
'description': self.description,
|
'description': self.description,
|
||||||
'photo': self.photo,
|
'photo': self.photo,
|
||||||
'text': self.text,
|
'text': self.text,
|
||||||
'text_entities': [e.to_json() for e in self.text_entities],
|
'text_entities': self.text_entities,
|
||||||
'animation': self.animation.to_json()
|
'animation': self.animation
|
||||||
}
|
}
|
||||||
|
|
||||||
def test_game_de_json(self):
|
def test_game_de_json(self):
|
||||||
|
@ -106,7 +120,12 @@ class AnimationTest(BaseTest, unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.file_id = 'thisisafileid'
|
self.file_id = 'thisisafileid'
|
||||||
self.thumb = telegram.PhotoSize(file_id='Blah', width=640, height=360)
|
self.thumb = {
|
||||||
|
'width': 640,
|
||||||
|
'height': 360,
|
||||||
|
'file_id': 'Blah',
|
||||||
|
'file_size': 0
|
||||||
|
}
|
||||||
self.file_name = 'File name'
|
self.file_name = 'File name'
|
||||||
self.mime_type = 'something/gif'
|
self.mime_type = 'something/gif'
|
||||||
self.file_size = 42
|
self.file_size = 42
|
||||||
|
@ -123,7 +142,7 @@ class AnimationTest(BaseTest, unittest.TestCase):
|
||||||
animation = telegram.Animation.de_json(self.json_dict, self._bot)
|
animation = telegram.Animation.de_json(self.json_dict, self._bot)
|
||||||
|
|
||||||
self.assertEqual(animation.file_id, self.file_id)
|
self.assertEqual(animation.file_id, self.file_id)
|
||||||
self.assertEqual(animation.thumb, self.thumb)
|
self.assertTrue(isinstance(animation.thumb, telegram.PhotoSize))
|
||||||
self.assertEqual(animation.file_name, self.file_name)
|
self.assertEqual(animation.file_name, self.file_name)
|
||||||
self.assertEqual(animation.mime_type, self.mime_type)
|
self.assertEqual(animation.mime_type, self.mime_type)
|
||||||
self.assertEqual(animation.file_size, self.file_size)
|
self.assertEqual(animation.file_size, self.file_size)
|
||||||
|
|
Loading…
Add table
Reference in a new issue