mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2025-03-17 04:39:55 +01:00
test_voice done
* Changed to new method of non-static file_id * removed obsolete tests.
This commit is contained in:
parent
6b7ce7b8f0
commit
7b7c4a81bb
2 changed files with 31 additions and 47 deletions
|
@ -82,7 +82,8 @@ class VideoTest(BaseTest, unittest.TestCase):
|
|||
self.video_file,
|
||||
timeout=10,
|
||||
duration=self.duration,
|
||||
caption=self.caption)
|
||||
caption=self.caption,
|
||||
disable_notification=False)
|
||||
|
||||
video = message.video
|
||||
|
||||
|
|
|
@ -24,6 +24,8 @@ import os
|
|||
|
||||
from flaky import flaky
|
||||
|
||||
from tests.bots import get_bot
|
||||
|
||||
sys.path.append('.')
|
||||
|
||||
import telegram
|
||||
|
@ -33,15 +35,23 @@ from tests.base import BaseTest, timeout
|
|||
class VoiceTest(BaseTest, unittest.TestCase):
|
||||
"""This object represents Tests for Telegram Voice."""
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
bot_info = get_bot()
|
||||
cls._chat_id = bot_info['chat_id']
|
||||
cls._bot = telegram.Bot(bot_info['token'])
|
||||
voice_file = open('tests/data/telegram.ogg', 'rb')
|
||||
voice = cls._bot.send_voice(cls._chat_id, voice=voice_file).voice
|
||||
cls.voice_file_id = voice.file_id
|
||||
cls.duration = voice.duration
|
||||
cls.mime_type = voice.mime_type
|
||||
cls.file_size = voice.file_size
|
||||
|
||||
|
||||
def setUp(self):
|
||||
self.voice_file = open('tests/data/telegram.ogg', 'rb')
|
||||
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,
|
||||
|
@ -53,15 +63,8 @@ class VoiceTest(BaseTest, unittest.TestCase):
|
|||
@flaky(3, 1)
|
||||
@timeout(10)
|
||||
def test_send_voice_required_args_only(self):
|
||||
message = self._bot.sendVoice(self._chat_id, self.voice_file)
|
||||
|
||||
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)
|
||||
# Obsolete, tested in setUpClass
|
||||
self.assertEqual(True, True)
|
||||
|
||||
@flaky(3, 1)
|
||||
@timeout(10)
|
||||
|
@ -72,7 +75,8 @@ class VoiceTest(BaseTest, unittest.TestCase):
|
|||
duration=self.duration,
|
||||
caption=self.caption,
|
||||
mime_type=self.mime_type,
|
||||
file_size=self.file_size)
|
||||
file_size=self.file_size,
|
||||
disable_notification=False)
|
||||
|
||||
self.assertEqual(message.caption, self.caption)
|
||||
|
||||
|
@ -87,21 +91,8 @@ class VoiceTest(BaseTest, unittest.TestCase):
|
|||
@flaky(3, 1)
|
||||
@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,
|
||||
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)
|
||||
# obsolete: Same as all_args
|
||||
self.assertEqual(True, True)
|
||||
|
||||
@flaky(3, 1)
|
||||
@timeout(10)
|
||||
|
@ -161,16 +152,12 @@ class VoiceTest(BaseTest, unittest.TestCase):
|
|||
def test_send_voice_resend(self):
|
||||
message = self._bot.sendVoice(
|
||||
chat_id=self._chat_id,
|
||||
voice=self.voice_file_id,
|
||||
duration=self.duration,
|
||||
caption=self.caption)
|
||||
|
||||
self.assertEqual(message.caption, self.caption)
|
||||
voice=self.voice_file_id)
|
||||
|
||||
voice = message.voice
|
||||
|
||||
self.assertEqual(voice.file_id, self.voice_file_id)
|
||||
self.assertEqual(voice.duration, 0)
|
||||
self.assertEqual(voice.duration, self.duration)
|
||||
self.assertEqual(voice.mime_type, self.mime_type)
|
||||
|
||||
def test_voice_de_json(self):
|
||||
|
@ -203,9 +190,8 @@ class VoiceTest(BaseTest, unittest.TestCase):
|
|||
del (json_dict['file_id'])
|
||||
json_dict['voice'] = open(os.devnull, 'rb')
|
||||
|
||||
self.assertRaises(
|
||||
telegram.TelegramError,
|
||||
lambda: self._bot.sendVoice(chat_id=self._chat_id, **json_dict))
|
||||
with self.assertRaises(telegram.TelegramError):
|
||||
self._bot.sendVoice(chat_id=self._chat_id, **json_dict)
|
||||
|
||||
@flaky(3, 1)
|
||||
@timeout(10)
|
||||
|
@ -215,9 +201,8 @@ class VoiceTest(BaseTest, unittest.TestCase):
|
|||
del (json_dict['file_id'])
|
||||
json_dict['voice'] = ''
|
||||
|
||||
self.assertRaises(
|
||||
telegram.TelegramError,
|
||||
lambda: self._bot.sendVoice(chat_id=self._chat_id, **json_dict))
|
||||
with self.assertRaises(telegram.TelegramError):
|
||||
self._bot.sendVoice(chat_id=self._chat_id, **json_dict)
|
||||
|
||||
@flaky(3, 1)
|
||||
@timeout(10)
|
||||
|
@ -225,11 +210,9 @@ class VoiceTest(BaseTest, unittest.TestCase):
|
|||
json_dict = self.json_dict
|
||||
|
||||
del (json_dict['file_id'])
|
||||
del (json_dict['duration'])
|
||||
|
||||
self.assertRaises(
|
||||
TypeError,
|
||||
lambda: self._bot.sendVoice(chat_id=self._chat_id, **json_dict))
|
||||
with self.assertRaises(TypeError):
|
||||
self._bot.sendVoice(chat_id=self._chat_id, **json_dict)
|
||||
|
||||
@flaky(3, 1)
|
||||
@timeout(10)
|
||||
|
|
Loading…
Add table
Reference in a new issue