From 7227ca3aab57abc707c0a6ae059cdccc7847fdd7 Mon Sep 17 00:00:00 2001 From: Leandro Toledo Date: Mon, 11 Jan 2016 20:19:55 -0200 Subject: [PATCH] Tests for send(Audio,Voice,Video) by URL --- tests/test_audio.py | 21 +++++++++++++++++++++ tests/test_video.py | 23 +++++++++++++++++++++++ tests/test_voice.py | 17 +++++++++++++++++ 3 files changed, 61 insertions(+) diff --git a/tests/test_audio.py b/tests/test_audio.py index 03163af05..c50025ffd 100644 --- a/tests/test_audio.py +++ b/tests/test_audio.py @@ -34,6 +34,7 @@ class AudioTest(BaseTest, unittest.TestCase): def setUp(self): self.audio_file = open('tests/data/telegram.mp3', 'rb') 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.performer = 'Leandro Toledo' self.title = 'Teste' @@ -129,6 +130,26 @@ class AudioTest(BaseTest, unittest.TestCase): self.assertEqual(audio.mime_type, self.mime_type) 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): """Test telegram.Bot sendAudio method""" print('Testing bot.sendAudio - Resend by file_id') diff --git a/tests/test_video.py b/tests/test_video.py index 925ef619a..20aa2cc3d 100644 --- a/tests/test_video.py +++ b/tests/test_video.py @@ -34,6 +34,7 @@ class VideoTest(BaseTest, unittest.TestCase): def setUp(self): self.video_file = open('tests/data/telegram.mp4', 'rb') 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.height = 640 self.duration = 4 @@ -139,6 +140,28 @@ class VideoTest(BaseTest, unittest.TestCase): 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): """Test telegram.Bot sendVideo method""" print('Testing bot.sendVideo - Resend by file_id') diff --git a/tests/test_voice.py b/tests/test_voice.py index f5ab8b706..44ed0c15e 100644 --- a/tests/test_voice.py +++ b/tests/test_voice.py @@ -34,6 +34,7 @@ class VoiceTest(BaseTest, unittest.TestCase): def setUp(self): self.voice_file = open('tests/data/telegram.ogg', 'rb') 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.mime_type = 'audio/ogg' self.file_size = 9199 @@ -111,6 +112,22 @@ class VoiceTest(BaseTest, unittest.TestCase): self.assertEqual(voice.mime_type, self.mime_type) 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): """Test telegram.Bot sendVoice method""" print('Testing bot.sendVoice - Resend by file_id')