X Tutup
Skip to content

Commit 8dc10fc

Browse files
PH89jh0ker
authored andcommitted
fixes broken test cases with PhotoSize, Game and Animation classes (python-telegram-bot#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
1 parent 7ad92dc commit 8dc10fc

File tree

4 files changed

+40
-13
lines changed

4 files changed

+40
-13
lines changed

telegram/animation.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ class Animation(TelegramObject):
3737

3838
def __init__(self,
3939
file_id,
40-
thumb=None,
41-
file_name=None,
42-
mime_type=None,
43-
file_size=None,
4440
**kwargs):
4541
self.file_id = file_id
4642
self.thumb = kwargs.get('thumb')

telegram/game.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,18 @@ def de_json(data, bot):
7979

8080
return Game(**data)
8181

82+
def to_dict(self):
83+
"""
84+
Returns:
85+
dict:
86+
"""
87+
data = super(Game, self).to_dict()
88+
89+
data['photo'] = [p.to_dict() for p in self.photo]
90+
data['text_entities'] = [x.to_dict() for x in self.text_entities]
91+
92+
return data
93+
8294
def parse_text_entity(self, entity):
8395
"""
8496
Returns the text from a given :class:`telegram.MessageEntity`.

tests/test_bot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ def test_set_game_score(self):
292292

293293
self.assertTrue(self.is_json(game.to_json()))
294294
self.assertEqual(message.game.description, game.game.description)
295-
self.assertEqual(message.game.animation.file_id, game.game.animation)
295+
self.assertEqual(message.game.animation, game.game.animation)
296296
self.assertEqual(message.game.photo[0].file_size, game.game.photo[0].file_size)
297297
self.assertNotEqual(message.game.text, game.game.text)
298298

tests/test_game.py

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,33 @@ class GameTest(BaseTest, unittest.TestCase):
3434
def setUp(self):
3535
self.title = 'Python-telegram-bot Test Game'
3636
self.description = 'description'
37-
self.photo = [telegram.PhotoSize(file_id='Blah', width=640, height=360)]
37+
self.photo = [
38+
{
39+
'width': 640,
40+
'height': 360,
41+
'file_id': 'Blah',
42+
'file_size': 0
43+
}
44+
]
3845
self.text = 'Other description'
39-
self.text_entities = [telegram.MessageEntity(
40-
type=telegram.MessageEntity.URL, offset=13, length=17)]
41-
self.animation = telegram.Animation(file_id='Bleh')
46+
self.text_entities = [
47+
{
48+
'offset': 13,
49+
'length': 17,
50+
'type': telegram.MessageEntity.URL
51+
}
52+
]
53+
self.animation = {
54+
'file_id': 'Blah'
55+
}
4256

4357
self.json_dict = {
4458
'title': self.title,
4559
'description': self.description,
4660
'photo': self.photo,
4761
'text': self.text,
48-
'text_entities': [e.to_json() for e in self.text_entities],
49-
'animation': self.animation.to_json()
62+
'text_entities': self.text_entities,
63+
'animation': self.animation
5064
}
5165

5266
def test_game_de_json(self):
@@ -106,7 +120,12 @@ class AnimationTest(BaseTest, unittest.TestCase):
106120

107121
def setUp(self):
108122
self.file_id = 'thisisafileid'
109-
self.thumb = telegram.PhotoSize(file_id='Blah', width=640, height=360)
123+
self.thumb = {
124+
'width': 640,
125+
'height': 360,
126+
'file_id': 'Blah',
127+
'file_size': 0
128+
}
110129
self.file_name = 'File name'
111130
self.mime_type = 'something/gif'
112131
self.file_size = 42
@@ -123,7 +142,7 @@ def test_animation_de_json(self):
123142
animation = telegram.Animation.de_json(self.json_dict, self._bot)
124143

125144
self.assertEqual(animation.file_id, self.file_id)
126-
self.assertEqual(animation.thumb, self.thumb)
145+
self.assertTrue(isinstance(animation.thumb, telegram.PhotoSize))
127146
self.assertEqual(animation.file_name, self.file_name)
128147
self.assertEqual(animation.mime_type, self.mime_type)
129148
self.assertEqual(animation.file_size, self.file_size)

0 commit comments

Comments
 (0)
X Tutup