Tests for send(Audio,Voice,Video) by URL

This commit is contained in:
Leandro Toledo 2016-01-11 20:19:55 -02:00
parent 307d2621d7
commit 7227ca3aab
3 changed files with 61 additions and 0 deletions

View file

@ -34,6 +34,7 @@ class AudioTest(BaseTest, unittest.TestCase):
def setUp(self): def setUp(self):
self.audio_file = open('tests/data/telegram.mp3', 'rb') self.audio_file = open('tests/data/telegram.mp3', 'rb')
self.audio_file_id = 'BQADAQADDwADHyP1B6PSPq2HjX8kAg' self.audio_file_id = 'BQADAQADDwADHyP1B6PSPq2HjX8kAg'
self.audio_file_url = 'https://github.com/python-telegram-bot/python-telegram-bot/blob/master/tests/data/telegram.mp3'
self.duration = 4 self.duration = 4
self.performer = 'Leandro Toledo' self.performer = 'Leandro Toledo'
self.title = 'Teste' self.title = 'Teste'
@ -129,6 +130,26 @@ class AudioTest(BaseTest, unittest.TestCase):
self.assertEqual(audio.mime_type, self.mime_type) self.assertEqual(audio.mime_type, self.mime_type)
self.assertEqual(audio.file_size, self.file_size) self.assertEqual(audio.file_size, self.file_size)
def test_send_audio_mp3_url_file(self):
"""Test telegram.Bot sendAudio method"""
print('Testing bot.sendAudio - MP3 File by URL')
message = self._bot.sendAudio(chat_id=self._chat_id,
audio=self.audio_file_url,
duration=self.duration,
performer=self.performer,
title=self.title)
audio = message.audio
self.assertTrue(isinstance(audio.file_id, str))
self.assertNotEqual(audio.file_id, '')
self.assertEqual(audio.duration, self.duration)
self.assertEqual(audio.performer, self.performer)
self.assertEqual(audio.title, self.title)
self.assertEqual(audio.mime_type, self.mime_type)
self.assertEqual(audio.file_size, 36320)
def test_send_audio_resend(self): def test_send_audio_resend(self):
"""Test telegram.Bot sendAudio method""" """Test telegram.Bot sendAudio method"""
print('Testing bot.sendAudio - Resend by file_id') print('Testing bot.sendAudio - Resend by file_id')

View file

@ -34,6 +34,7 @@ class VideoTest(BaseTest, unittest.TestCase):
def setUp(self): def setUp(self):
self.video_file = open('tests/data/telegram.mp4', 'rb') self.video_file = open('tests/data/telegram.mp4', 'rb')
self.video_file_id = 'BAADAQADXwADHyP1BwJFTcmY2RYCAg' self.video_file_id = 'BAADAQADXwADHyP1BwJFTcmY2RYCAg'
self.video_file_url = 'https://github.com/python-telegram-bot/python-telegram-bot/blob/urls/tests/data/telegram.mp4'
self.width = 360 self.width = 360
self.height = 640 self.height = 640
self.duration = 4 self.duration = 4
@ -139,6 +140,28 @@ class VideoTest(BaseTest, unittest.TestCase):
self.assertEqual(message.caption, self.caption) self.assertEqual(message.caption, self.caption)
def test_send_video_mp4_file_url(self):
"""Test telegram.Bot sendVideo method"""
print('Testing bot.sendVideo - MP4 File by URL')
message = self._bot.sendVideo(chat_id=self._chat_id,
video=self.video_file_url,
duration=self.duration,
caption=self.caption)
video = message.video
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, self.duration)
self.assertEqual(video.thumb, None)
self.assertEqual(video.mime_type, '')
self.assertEqual(video.file_size, 36315)
self.assertEqual(message.caption, self.caption)
def test_send_video_resend(self): def test_send_video_resend(self):
"""Test telegram.Bot sendVideo method""" """Test telegram.Bot sendVideo method"""
print('Testing bot.sendVideo - Resend by file_id') print('Testing bot.sendVideo - Resend by file_id')

View file

@ -34,6 +34,7 @@ class VoiceTest(BaseTest, unittest.TestCase):
def setUp(self): def setUp(self):
self.voice_file = open('tests/data/telegram.ogg', 'rb') self.voice_file = open('tests/data/telegram.ogg', 'rb')
self.voice_file_id = 'AwADAQADTgADHyP1B_mbw34svXPHAg' self.voice_file_id = 'AwADAQADTgADHyP1B_mbw34svXPHAg'
self.voice_file_url = 'https://github.com/python-telegram-bot/python-telegram-bot/blob/urls/tests/data/telegram.ogg'
self.duration = 0 self.duration = 0
self.mime_type = 'audio/ogg' self.mime_type = 'audio/ogg'
self.file_size = 9199 self.file_size = 9199
@ -111,6 +112,22 @@ class VoiceTest(BaseTest, unittest.TestCase):
self.assertEqual(voice.mime_type, self.mime_type) self.assertEqual(voice.mime_type, self.mime_type)
self.assertEqual(voice.file_size, self.file_size) self.assertEqual(voice.file_size, self.file_size)
def test_send_voice_ogg_url_file(self):
"""Test telegram.Bot sendVoice method"""
print('Testing bot.sendVoice - Ogg File by URL')
message = self._bot.sendVoice(chat_id=self._chat_id,
voice=self.voice_file_url,
duration=self.duration)
voice = message.voice
self.assertTrue(isinstance(voice.file_id, str))
self.assertNotEqual(voice.file_id, '')
self.assertEqual(voice.duration, self.duration)
self.assertEqual(voice.mime_type, self.mime_type)
self.assertEqual(voice.file_size, 36316)
def test_send_voice_resend(self): def test_send_voice_resend(self):
"""Test telegram.Bot sendVoice method""" """Test telegram.Bot sendVoice method"""
print('Testing bot.sendVoice - Resend by file_id') print('Testing bot.sendVoice - Resend by file_id')