Add tests for captions in audio and voice

This commit is contained in:
Jacob Bom 2016-10-05 17:50:48 +02:00
parent 1f9d3163dd
commit 6b7788570c
4 changed files with 83 additions and 5 deletions

View file

@ -40,6 +40,7 @@ class AudioTest(BaseTest, unittest.TestCase):
self.duration = 4
self.performer = 'Leandro Toledo'
self.title = 'Teste'
self.caption = "Test audio"
self.mime_type = 'audio/mpeg'
self.file_size = 28232
@ -48,6 +49,7 @@ class AudioTest(BaseTest, unittest.TestCase):
'duration': self.duration,
'performer': self.performer,
'title': self.title,
'caption': self.caption,
'mime_type': self.mime_type,
'file_size': self.file_size
}
@ -57,6 +59,8 @@ class AudioTest(BaseTest, unittest.TestCase):
def test_send_audio_required_args_only(self):
message = self._bot.sendAudio(self._chat_id, self.audio_file)
self.assertEqual(message.caption, '')
audio = message.audio
self.assertTrue(isinstance(audio.file_id, str))
@ -76,9 +80,12 @@ class AudioTest(BaseTest, unittest.TestCase):
duration=self.duration,
performer=self.performer,
title=self.title,
caption=self.caption,
mime_type=self.mime_type,
file_size=self.file_size)
self.assertEqual(message.caption, self.caption)
audio = message.audio
self.assertTrue(isinstance(audio.file_id, str))
@ -97,7 +104,10 @@ class AudioTest(BaseTest, unittest.TestCase):
audio=self.audio_file,
duration=self.duration,
performer=self.performer,
title=self.title)
title=self.title,
caption=self.caption)
self.assertEqual(message.caption, self.caption)
audio = message.audio
@ -118,8 +128,11 @@ class AudioTest(BaseTest, unittest.TestCase):
duration=self.duration,
performer=self.performer,
title=self.title,
caption=self.caption,
filename='telegram_custom.mp3')
self.assertEqual(message.caption, self.caption)
audio = message.audio
self.assertTrue(isinstance(audio.file_id, str))
@ -144,6 +157,25 @@ class AudioTest(BaseTest, unittest.TestCase):
self.assertEqual(audio.mime_type, self.mime_type)
self.assertEqual(audio.file_size, self.file_size)
@flaky(3, 1)
@timeout(10)
def test_send_audio_mp3_url_file_with_caption(self):
message = self._bot.sendAudio(
chat_id=self._chat_id,
audio=self.audio_file_url,
duration=self.duration,
caption=self.caption)
self.assertEqual(message.caption, self.caption)
audio = message.audio
self.assertTrue(isinstance(audio.file_id, str))
self.assertNotEqual(audio.file_id, '')
self.assertEqual(audio.duration, self.duration)
self.assertEqual(audio.mime_type, self.mime_type)
self.assertEqual(audio.file_size, self.file_size)
@flaky(3, 1)
@timeout(10)
def test_send_audio_resend(self):
@ -152,7 +184,10 @@ class AudioTest(BaseTest, unittest.TestCase):
audio=self.audio_file_id,
duration=self.duration,
performer=self.performer,
title=self.title)
title=self.title,
caption=self.caption)
self.assertEqual(message.caption, self.caption)
audio = message.audio

View file

@ -38,6 +38,7 @@ class InlineQueryResultAudioTest(BaseTest, unittest.TestCase):
self.title = 'title'
self.performer = 'performer'
self.audio_duration = 'audio_duration'
self.caption = 'caption'
self.input_message_content = telegram.InputTextMessageContent('input_message_content')
self.reply_markup = telegram.InlineKeyboardMarkup([[
telegram.InlineKeyboardButton('reply_markup')
@ -50,6 +51,7 @@ class InlineQueryResultAudioTest(BaseTest, unittest.TestCase):
'title': self.title,
'performer': self.performer,
'audio_duration': self.audio_duration,
'caption': self.caption,
'input_message_content': self.input_message_content.to_dict(),
'reply_markup': self.reply_markup.to_dict(),
}
@ -63,6 +65,7 @@ class InlineQueryResultAudioTest(BaseTest, unittest.TestCase):
self.assertEqual(audio.title, self.title)
self.assertEqual(audio.performer, self.performer)
self.assertEqual(audio.audio_duration, self.audio_duration)
self.assertEqual(audio.caption, self.caption)
self.assertDictEqual(audio.input_message_content.to_dict(),
self.input_message_content.to_dict())
self.assertDictEqual(audio.reply_markup.to_dict(), self.reply_markup.to_dict())

View file

@ -36,6 +36,7 @@ class InlineQueryResultCachedAudioTest(BaseTest, unittest.TestCase):
self.id = 'id'
self.type = 'audio'
self.audio_file_id = 'audio file id'
self.caption = 'caption'
self.input_message_content = telegram.InputTextMessageContent('input_message_content')
self.reply_markup = telegram.InlineKeyboardMarkup([[
telegram.InlineKeyboardButton('reply_markup')
@ -45,6 +46,7 @@ class InlineQueryResultCachedAudioTest(BaseTest, unittest.TestCase):
'type': self.type,
'id': self.id,
'audio_file_id': self.audio_file_id,
'caption': self.caption,
'input_message_content': self.input_message_content.to_dict(),
'reply_markup': self.reply_markup.to_dict(),
}
@ -55,6 +57,7 @@ class InlineQueryResultCachedAudioTest(BaseTest, unittest.TestCase):
self.assertEqual(audio.type, self.type)
self.assertEqual(audio.id, self.id)
self.assertEqual(audio.audio_file_id, self.audio_file_id)
self.assertEqual(audio.caption, self.caption)
self.assertDictEqual(audio.input_message_content.to_dict(),
self.input_message_content.to_dict())
self.assertDictEqual(audio.reply_markup.to_dict(), self.reply_markup.to_dict())

View file

@ -38,12 +38,14 @@ class VoiceTest(BaseTest, unittest.TestCase):
self.voice_file_id = 'AwADAQADTgADHyP1B_mbw34svXPHAg'
self.voice_file_url = 'https://raw.githubusercontent.com/python-telegram-bot/python-telegram-bot/master/tests/data/telegram.ogg'
self.duration = 3
self.caption = "Test voice"
self.mime_type = 'audio/ogg'
self.file_size = 9199
self.json_dict = {
'file_id': self.voice_file_id,
'duration': self.duration,
'caption': self.caption,
'mime_type': self.mime_type,
'file_size': self.file_size
}
@ -67,10 +69,13 @@ class VoiceTest(BaseTest, unittest.TestCase):
message = self._bot.sendVoice(
self._chat_id,
self.voice_file,
self.duration,
duration=self.duration,
caption=self.caption,
mime_type=self.mime_type,
file_size=self.file_size)
self.assertEqual(message.caption, self.caption)
voice = message.voice
self.assertTrue(isinstance(voice.file_id, str))
@ -83,7 +88,12 @@ class VoiceTest(BaseTest, unittest.TestCase):
@timeout(10)
def test_send_voice_ogg_file(self):
message = self._bot.sendVoice(
chat_id=self._chat_id, voice=self.voice_file, duration=self.duration)
chat_id=self._chat_id,
voice=self.voice_file,
duration=self.duration,
caption=self.caption)
self.assertEqual(message.caption, self.caption)
voice = message.voice
@ -100,8 +110,11 @@ class VoiceTest(BaseTest, unittest.TestCase):
chat_id=self._chat_id,
voice=self.voice_file,
duration=self.duration,
caption=self.caption,
filename='telegram_custom.ogg')
self.assertEqual(message.caption, self.caption)
voice = message.voice
self.assertTrue(isinstance(voice.file_id, str))
@ -124,11 +137,35 @@ class VoiceTest(BaseTest, unittest.TestCase):
self.assertEqual(voice.mime_type, self.mime_type)
self.assertEqual(voice.file_size, self.file_size)
@flaky(3, 1)
@timeout(10)
def test_send_voice_ogg_url_file_with_caption(self):
message = self._bot.sendVoice(
chat_id=self._chat_id,
voice=self.voice_file_url,
duration=self.duration,
caption=self.caption)
self.assertEqual(message.caption, self.caption)
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, self.file_size)
@flaky(3, 1)
@timeout(10)
def test_send_voice_resend(self):
message = self._bot.sendVoice(
chat_id=self._chat_id, voice=self.voice_file_id, duration=self.duration)
chat_id=self._chat_id,
voice=self.voice_file_id,
duration=self.duration,
caption=self.caption)
self.assertEqual(message.caption, self.caption)
voice = message.voice