Skip to content

Commit

Permalink
test_video.py: adapt to latest changes in the API
Browse files Browse the repository at this point in the history
  • Loading branch information
tsnoam committed Feb 27, 2016
1 parent ca8404a commit ec8cd37
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 20 deletions.
8 changes: 8 additions & 0 deletions telegram/photosize.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ def __init__(self,
# Optionals
self.file_size = int(kwargs.get('file_size', 0))

def __eq__(self, other):
if not isinstance(other, self.__class__):
return False
return (self.file_id == other.file_id and
self.width == other.width and
self.height == other.height and
self.file_size == other.file_size)

@staticmethod
def de_json(data):
"""
Expand Down
43 changes: 23 additions & 20 deletions tests/test_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,12 @@ def setUp(self):
self.video_file_url = 'https://raw.githubusercontent.com/python-telegram-bot/python-telegram-bot/master/tests/data/telegram.mp4'
self.width = 360
self.height = 640
self.duration = 4
self.thumb = telegram.PhotoSize.de_json({})
self.duration = 5
self.thumb = telegram.PhotoSize.de_json(
{'file_id': 'AAQBABOMsecvAAQqqoY1Pee_MqcyAAIC',
'file_size': 645,
'height': 90,
'width': 51})
self.mime_type = 'video/mp4'
self.file_size = 326534

Expand All @@ -52,7 +56,7 @@ def setUp(self):
'width': self.width,
'height': self.height,
'duration': self.duration,
'thumb': self.thumb,
'thumb': self.thumb.to_dict(),
'mime_type': self.mime_type,
'file_size': self.file_size
}
Expand All @@ -67,10 +71,10 @@ def test_send_video_required_args_only(self):

self.assertTrue(isinstance(video.file_id, str))
self.assertNotEqual(video.file_id, '')
self.assertEqual(video.width, 0)
self.assertEqual(video.height, 0)
self.assertEqual(video.duration, 0)
self.assertEqual(video.thumb, None)
self.assertEqual(video.width, self.width)
self.assertEqual(video.height, self.height)
self.assertEqual(video.duration, self.duration)
self.assertEqual(video.thumb, self.thumb)
self.assertEqual(video.mime_type, '')
self.assertEqual(video.file_size, self.file_size)

Expand All @@ -86,10 +90,10 @@ def test_send_video_all_args(self):

self.assertTrue(isinstance(video.file_id, str))
self.assertNotEqual(video.file_id, '')
self.assertEqual(video.width, 0)
self.assertEqual(video.height, 0)
self.assertEqual(video.width, self.width)
self.assertEqual(video.height, self.height)
self.assertEqual(video.duration, self.duration)
self.assertEqual(video.thumb, None)
self.assertEqual(video.thumb, self.thumb)
self.assertEqual(video.mime_type, '')
self.assertEqual(video.file_size, self.file_size)

Expand All @@ -107,10 +111,10 @@ def test_send_video_mp4_file(self):

self.assertTrue(isinstance(video.file_id, str))
self.assertNotEqual(video.file_id, '')
self.assertEqual(video.width, 0)
self.assertEqual(video.height, 0)
self.assertEqual(video.width, self.width)
self.assertEqual(video.height, self.height)
self.assertEqual(video.duration, self.duration)
self.assertEqual(video.thumb, None)
self.assertEqual(video.thumb, self.thumb)
self.assertEqual(video.mime_type, '')
self.assertEqual(video.file_size, self.file_size)

Expand All @@ -129,10 +133,10 @@ def test_send_video_mp4_file_with_custom_filename(self):

self.assertTrue(isinstance(video.file_id, str))
self.assertNotEqual(video.file_id, '')
self.assertEqual(video.width, 0)
self.assertEqual(video.height, 0)
self.assertEqual(video.width, self.width)
self.assertEqual(video.height, self.height)
self.assertEqual(video.duration, self.duration)
self.assertEqual(video.thumb, None)
self.assertEqual(video.thumb, self.thumb)
self.assertEqual(video.mime_type, '')
self.assertEqual(video.file_size, self.file_size)

Expand All @@ -150,10 +154,9 @@ def test_send_video_mp4_file_url(self):

self.assertTrue(isinstance(video.file_id, str))
self.assertNotEqual(video.file_id, '')
self.assertEqual(video.width, 0)
self.assertEqual(video.height, 0)
self.assertEqual(video.height, self.height)
self.assertEqual(video.duration, self.duration)
self.assertEqual(video.thumb, None)
self.assertEqual(video.thumb, self.thumb)
self.assertEqual(video.mime_type, '')
self.assertEqual(video.file_size, self.file_size)

Expand Down Expand Up @@ -183,7 +186,7 @@ def test_video_de_json(self):
self.assertEqual(video.width, self.width)
self.assertEqual(video.height, self.height)
self.assertEqual(video.duration, self.duration)
self.assertEqual(video.thumb, None)
self.assertEqual(video.thumb, self.thumb)
self.assertEqual(video.mime_type, self.mime_type)
self.assertEqual(video.file_size, self.file_size)

Expand Down

0 comments on commit ec8cd37

Please sign in to comment.