mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2025-03-17 04:39:55 +01:00
Clean up after conversation
Clean setUpClass + add assertions remove obsolete tests add test_expected_values
This commit is contained in:
parent
4bf63d7358
commit
4fe805ee0c
3 changed files with 156 additions and 204 deletions
|
@ -33,44 +33,40 @@ class VideoTest(BaseTest, unittest.TestCase):
|
|||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.caption = u'VideoTest - Caption'
|
||||
cls.video_file_url = 'https://python-telegram-bot.org/static/website/telegram.mp4'
|
||||
|
||||
bot_info = get_bot()
|
||||
cls._chat_id = bot_info['chat_id']
|
||||
cls._bot = telegram.Bot(bot_info['token'])
|
||||
|
||||
video_file = open('tests/data/telegram.mp4', 'rb')
|
||||
video = cls._bot.send_video(cls._chat_id, video=video_file, timeout=10).video
|
||||
cls.video_file_id = video.file_id
|
||||
cls.width = video.width
|
||||
cls.height = video.height
|
||||
cls.duration = video.duration
|
||||
cls.thumb = video.thumb
|
||||
cls.mime_type = video.mime_type
|
||||
cls.file_size = video.file_size
|
||||
cls.video_file_url = 'https://python-telegram-bot.org/static/website/telegram.mp4'
|
||||
cls.caption = u'VideoTest - Caption'
|
||||
cls.thumb_from_url = telegram.PhotoSize.de_json({
|
||||
'file_id': 'AAQEABPZU2EZAAQ_tPcvcRTF4i1GAQABAg',
|
||||
'file_size': 645,
|
||||
'height': 90,
|
||||
'width': 51
|
||||
}, cls._bot)
|
||||
cls.video = video
|
||||
|
||||
# Make sure file has been uploaded.
|
||||
cls.assertIsInstance(cls(), cls.video, telegram.Video)
|
||||
cls.assertIsInstance(cls(), cls.video.file_id, str)
|
||||
cls.assertNotEqual(cls(), cls.video.file_id, '')
|
||||
|
||||
def setUp(self):
|
||||
self.video_file = open('tests/data/telegram.mp4', 'rb')
|
||||
self.json_dict = {
|
||||
'file_id': self.video_file_id,
|
||||
'width': self.width,
|
||||
'height': self.height,
|
||||
'duration': self.duration,
|
||||
'thumb': self.thumb.to_dict(),
|
||||
'mime_type': self.mime_type,
|
||||
'file_size': self.file_size
|
||||
'file_id': self.video.file_id,
|
||||
'width': self.video.width,
|
||||
'height': self.video.height,
|
||||
'duration': self.video.duration,
|
||||
'thumb': self.video.thumb.to_dict(),
|
||||
'mime_type': self.video.mime_type,
|
||||
'file_size': self.video.file_size
|
||||
}
|
||||
|
||||
@flaky(3, 1)
|
||||
@timeout(10)
|
||||
def test_send_video_required_args_only(self):
|
||||
# obsolete since it's done in the setUpClass
|
||||
self.assertEqual(True, True)
|
||||
def test_expected_values(self):
|
||||
self.assertEqual(self.video.width, 360)
|
||||
self.assertEqual(self.video.height, 640)
|
||||
self.assertEqual(self.video.duration, 5)
|
||||
self.assertEqual(self.video.file_size, 326534)
|
||||
self.assertEqual(self.video.mime_type, 'video/mp4')
|
||||
|
||||
@flaky(3, 1)
|
||||
@timeout(10)
|
||||
|
@ -79,7 +75,7 @@ class VideoTest(BaseTest, unittest.TestCase):
|
|||
self._chat_id,
|
||||
self.video_file,
|
||||
timeout=10,
|
||||
duration=self.duration,
|
||||
duration=self.video.duration,
|
||||
caption=self.caption,
|
||||
disable_notification=False)
|
||||
|
||||
|
@ -87,42 +83,12 @@ class VideoTest(BaseTest, unittest.TestCase):
|
|||
|
||||
self.assertTrue(isinstance(video.file_id, str))
|
||||
self.assertNotEqual(video.file_id, 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.mime_type)
|
||||
self.assertEqual(video.file_size, self.file_size)
|
||||
|
||||
self.assertEqual(message.caption, self.caption)
|
||||
|
||||
@flaky(3, 1)
|
||||
@timeout(10)
|
||||
def test_send_video_mp4_file(self):
|
||||
# identical to all_args so obsolete
|
||||
self.assertEqual(True, True)
|
||||
|
||||
@flaky(3, 1)
|
||||
@timeout(10)
|
||||
def test_send_video_mp4_file_with_custom_filename(self):
|
||||
message = self._bot.sendVideo(
|
||||
chat_id=self._chat_id,
|
||||
video=self.video_file,
|
||||
timeout=10,
|
||||
duration=self.duration,
|
||||
caption=self.caption,
|
||||
filename='telegram_custom.mp4')
|
||||
|
||||
video = message.video
|
||||
|
||||
self.assertTrue(isinstance(video.file_id, str))
|
||||
self.assertNotEqual(video.file_id, '')
|
||||
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.mime_type)
|
||||
self.assertEqual(video.file_size, self.file_size)
|
||||
self.assertEqual(video.width, self.video.width)
|
||||
self.assertEqual(video.height, self.video.height)
|
||||
self.assertEqual(video.duration, self.video.duration)
|
||||
self.assertEqual(video.thumb, self.video.thumb)
|
||||
self.assertEqual(video.mime_type, self.video.mime_type)
|
||||
self.assertEqual(video.file_size, self.video.file_size)
|
||||
|
||||
self.assertEqual(message.caption, self.caption)
|
||||
|
||||
|
@ -139,43 +105,45 @@ class VideoTest(BaseTest, unittest.TestCase):
|
|||
|
||||
self.assertTrue(isinstance(video.file_id, str))
|
||||
self.assertNotEqual(video.file_id, None)
|
||||
self.assertEqual(video.height, self.height)
|
||||
self.assertEqual(video.duration, self.duration)
|
||||
self.assertEqual(video.thumb, self.thumb_from_url)
|
||||
self.assertEqual(video.mime_type, self.mime_type)
|
||||
self.assertEqual(video.file_size, self.file_size)
|
||||
|
||||
self.assertEqual(video.height, self.video.height)
|
||||
self.assertEqual(video.duration, self.video.duration)
|
||||
self.assertEqual(video.mime_type, self.video.mime_type)
|
||||
self.assertEqual(video.file_size, self.video.file_size)
|
||||
self.assertEqual(message.caption, self.caption)
|
||||
thumb = video.thumb
|
||||
self.assertEqual(thumb.height, self.video.thumb.height)
|
||||
self.assertEqual(thumb.width, self.video.thumb.width)
|
||||
self.assertEqual(thumb.file_size, self.video.thumb.file_size)
|
||||
|
||||
@flaky(3, 1)
|
||||
@timeout(10)
|
||||
def test_send_video_resend(self):
|
||||
message = self._bot.sendVideo(
|
||||
chat_id=self._chat_id,
|
||||
video=self.video_file_id,
|
||||
video=self.video.file_id,
|
||||
timeout=10,
|
||||
duration=self.duration,
|
||||
duration=self.video.duration,
|
||||
caption=self.caption)
|
||||
|
||||
video = message.video
|
||||
|
||||
self.assertEqual(video.file_id, self.video_file_id)
|
||||
self.assertEqual(video.duration, self.duration)
|
||||
self.assertEqual(video.thumb, self.thumb)
|
||||
self.assertEqual(video.mime_type, self.mime_type)
|
||||
self.assertEqual(video.file_id, self.video.file_id)
|
||||
self.assertEqual(video.duration, self.video.duration)
|
||||
self.assertEqual(video.thumb, self.video.thumb)
|
||||
self.assertEqual(video.mime_type, self.video.mime_type)
|
||||
|
||||
self.assertEqual(message.caption, self.caption)
|
||||
|
||||
def test_video_de_json(self):
|
||||
video = telegram.Video.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertEqual(video.file_id, self.video_file_id)
|
||||
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.mime_type)
|
||||
self.assertEqual(video.file_size, self.file_size)
|
||||
self.assertEqual(video.file_id, self.video.file_id)
|
||||
self.assertEqual(video.width, self.video.width)
|
||||
self.assertEqual(video.height, self.video.height)
|
||||
self.assertEqual(video.duration, self.video.duration)
|
||||
self.assertEqual(video.thumb, self.video.thumb)
|
||||
self.assertEqual(video.mime_type, self.video.mime_type)
|
||||
self.assertEqual(video.file_size, self.video.file_size)
|
||||
|
||||
def test_video_to_json(self):
|
||||
video = telegram.Video.de_json(self.json_dict, self._bot)
|
||||
|
@ -186,12 +154,12 @@ class VideoTest(BaseTest, unittest.TestCase):
|
|||
video = telegram.Video.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertTrue(self.is_dict(video.to_dict()))
|
||||
self.assertEqual(video['file_id'], self.video_file_id)
|
||||
self.assertEqual(video['width'], self.width)
|
||||
self.assertEqual(video['height'], self.height)
|
||||
self.assertEqual(video['duration'], self.duration)
|
||||
self.assertEqual(video['mime_type'], self.mime_type)
|
||||
self.assertEqual(video['file_size'], self.file_size)
|
||||
self.assertEqual(video['file_id'], self.video.file_id)
|
||||
self.assertEqual(video['width'], self.video.width)
|
||||
self.assertEqual(video['height'], self.video.height)
|
||||
self.assertEqual(video['duration'], self.video.duration)
|
||||
self.assertEqual(video['mime_type'], self.video.mime_type)
|
||||
self.assertEqual(video['file_size'], self.video.file_size)
|
||||
|
||||
@flaky(3, 1)
|
||||
@timeout(10)
|
||||
|
@ -231,11 +199,11 @@ class VideoTest(BaseTest, unittest.TestCase):
|
|||
self.assertNotEqual(message.video.file_id, None)
|
||||
|
||||
def test_equality(self):
|
||||
a = telegram.Video(self.video_file_id, self.width, self.height, self.duration)
|
||||
b = telegram.Video(self.video_file_id, self.width, self.height, self.duration)
|
||||
c = telegram.Video(self.video_file_id, 0, 0, 0)
|
||||
d = telegram.Video("", self.width, self.height, self.duration)
|
||||
e = telegram.Voice(self.video_file_id, self.duration)
|
||||
a = telegram.Video(self.video.file_id, self.video.width, self.video.height, self.video.duration)
|
||||
b = telegram.Video(self.video.file_id, self.video.width, self.video.height, self.video.duration)
|
||||
c = telegram.Video(self.video.file_id, 0, 0, 0)
|
||||
d = telegram.Video("", self.video.width, self.video.height, self.video.duration)
|
||||
e = telegram.Voice(self.video.file_id, self.video.duration)
|
||||
|
||||
self.assertEqual(a, b)
|
||||
self.assertEqual(hash(a), hash(b))
|
||||
|
|
|
@ -35,29 +35,33 @@ class VideoNoteTest(BaseTest, unittest.TestCase):
|
|||
bot_info = get_bot()
|
||||
cls._chat_id = bot_info['chat_id']
|
||||
cls._bot = telegram.Bot(bot_info['token'])
|
||||
|
||||
videonote_file = open('tests/data/telegram2.mp4', 'rb')
|
||||
video_note = cls._bot.send_video_note(cls._chat_id, video_note=videonote_file, timeout=10).video_note
|
||||
cls.videonote_file_id = video_note.file_id
|
||||
cls.duration = video_note.duration
|
||||
cls.length = video_note.length
|
||||
cls.thumb = video_note.thumb
|
||||
cls.file_size = video_note.file_size
|
||||
|
||||
cls.videonote = video_note
|
||||
|
||||
# Make sure file has been uploaded.
|
||||
cls.assertIsInstance(cls(), cls.videonote, telegram.VideoNote)
|
||||
cls.assertIsInstance(cls(), cls.videonote.file_id, str)
|
||||
cls.assertNotEqual(cls(), cls.videonote.file_id, '')
|
||||
|
||||
def setUp(self):
|
||||
self.videonote_file = open('tests/data/telegram2.mp4', 'rb')
|
||||
self.json_dict = {
|
||||
'file_id': self.videonote_file_id,
|
||||
'duration': self.duration,
|
||||
'length': self.length,
|
||||
'thumb': self.thumb.to_dict(),
|
||||
'file_size': self.file_size
|
||||
'file_id': self.videonote.file_id,
|
||||
'duration': self.videonote.duration,
|
||||
'length': self.videonote.length,
|
||||
'thumb': self.videonote.thumb.to_dict(),
|
||||
'file_size': self.videonote.file_size
|
||||
}
|
||||
|
||||
@flaky(3, 1)
|
||||
@timeout(10)
|
||||
def test_send_videonote_required_args_only(self):
|
||||
# obsolete, testen in setUpClass
|
||||
self.assertEqual(True, True)
|
||||
def test_expected_values(self):
|
||||
self.assertEqual(self.videonote.duration, 3)
|
||||
self.assertEqual(self.videonote.length, 240)
|
||||
self.assertEqual(self.videonote.file_size, 132084)
|
||||
|
||||
@flaky(3, 1)
|
||||
@timeout(10)
|
||||
|
@ -66,44 +70,44 @@ class VideoNoteTest(BaseTest, unittest.TestCase):
|
|||
self._chat_id,
|
||||
self.videonote_file,
|
||||
timeout=10,
|
||||
duration=self.duration,
|
||||
length=self.length,
|
||||
duration=self.videonote.duration,
|
||||
length=self.videonote.length,
|
||||
disable_notification=False)
|
||||
|
||||
videonote = message.video_note
|
||||
|
||||
self.assertTrue(isinstance(videonote.file_id, str))
|
||||
self.assertNotEqual(videonote.file_id, None)
|
||||
self.assertEqual(videonote.length, self.length)
|
||||
self.assertEqual(videonote.duration, self.duration)
|
||||
self.assertEqual(videonote.thumb, self.thumb)
|
||||
self.assertEqual(videonote.file_size, self.file_size)
|
||||
self.assertEqual(videonote.length, self.videonote.length)
|
||||
self.assertEqual(videonote.duration, self.videonote.duration)
|
||||
self.assertEqual(videonote.thumb, self.videonote.thumb)
|
||||
self.assertEqual(videonote.file_size, self.videonote.file_size)
|
||||
|
||||
@flaky(3, 1)
|
||||
@timeout(10)
|
||||
def test_send_videonote_resend(self):
|
||||
message = self._bot.sendVideoNote(
|
||||
chat_id=self._chat_id,
|
||||
video_note=self.videonote_file_id,
|
||||
video_note=self.videonote.file_id,
|
||||
timeout=10
|
||||
)
|
||||
|
||||
videonote = message.video_note
|
||||
|
||||
self.assertEqual(videonote.file_id, self.videonote_file_id)
|
||||
self.assertEqual(videonote.length, self.length)
|
||||
self.assertEqual(videonote.duration, self.duration)
|
||||
self.assertEqual(videonote.thumb, self.thumb)
|
||||
self.assertEqual(videonote.file_size, self.file_size)
|
||||
self.assertEqual(videonote.file_id, self.videonote.file_id)
|
||||
self.assertEqual(videonote.length, self.videonote.length)
|
||||
self.assertEqual(videonote.duration, self.videonote.duration)
|
||||
self.assertEqual(videonote.thumb, self.videonote.thumb)
|
||||
self.assertEqual(videonote.file_size, self.videonote.file_size)
|
||||
|
||||
def test_videonote_de_json(self):
|
||||
videonote = telegram.VideoNote.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertEqual(videonote.file_id, self.videonote_file_id)
|
||||
self.assertEqual(videonote.duration, self.duration)
|
||||
self.assertEqual(videonote.thumb, self.thumb)
|
||||
self.assertEqual(videonote.length, self.length)
|
||||
self.assertEqual(videonote.file_size, self.file_size)
|
||||
self.assertEqual(videonote.file_id, self.videonote.file_id)
|
||||
self.assertEqual(videonote.duration, self.videonote.duration)
|
||||
self.assertEqual(videonote.thumb, self.videonote.thumb)
|
||||
self.assertEqual(videonote.length, self.videonote.length)
|
||||
self.assertEqual(videonote.file_size, self.videonote.file_size)
|
||||
|
||||
def test_videonote_to_json(self):
|
||||
videonote = telegram.VideoNote.de_json(self.json_dict, self._bot)
|
||||
|
@ -114,10 +118,10 @@ class VideoNoteTest(BaseTest, unittest.TestCase):
|
|||
videonote = telegram.VideoNote.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertTrue(self.is_dict(videonote.to_dict()))
|
||||
self.assertEqual(videonote['file_id'], self.videonote_file_id)
|
||||
self.assertEqual(videonote['duration'], self.duration)
|
||||
self.assertEqual(videonote['length'], self.length)
|
||||
self.assertEqual(videonote['file_size'], self.file_size)
|
||||
self.assertEqual(videonote['file_id'], self.videonote.file_id)
|
||||
self.assertEqual(videonote['duration'], self.videonote.duration)
|
||||
self.assertEqual(videonote['length'], self.videonote.length)
|
||||
self.assertEqual(videonote['file_size'], self.videonote.file_size)
|
||||
|
||||
@flaky(3, 1)
|
||||
@timeout(10)
|
||||
|
@ -151,11 +155,11 @@ class VideoNoteTest(BaseTest, unittest.TestCase):
|
|||
self.assertNotEqual(message.video_note.file_id, None)
|
||||
|
||||
def test_equality(self):
|
||||
a = telegram.VideoNote(self.videonote_file_id, self.length, self.duration)
|
||||
b = telegram.VideoNote(self.videonote_file_id, self.length, self.duration)
|
||||
c = telegram.VideoNote(self.videonote_file_id, 0, 0, 0)
|
||||
d = telegram.VideoNote("", self.length, self.duration)
|
||||
e = telegram.Voice(self.videonote_file_id, self.duration)
|
||||
a = telegram.VideoNote(self.videonote.file_id, self.videonote.length, self.videonote.duration)
|
||||
b = telegram.VideoNote(self.videonote.file_id, self.videonote.length, self.videonote.duration)
|
||||
c = telegram.VideoNote(self.videonote.file_id, 0, 0, 0)
|
||||
d = telegram.VideoNote("", self.videonote.length, self.videonote.duration)
|
||||
e = telegram.Voice(self.videonote.file_id, self.videonote.duration)
|
||||
|
||||
self.assertEqual(a, b)
|
||||
self.assertEqual(hash(a), hash(b))
|
||||
|
|
|
@ -33,33 +33,39 @@ class VoiceTest(BaseTest, unittest.TestCase):
|
|||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.voice_file_url = 'https://raw.githubusercontent.com/python-telegram-bot/python-telegram-bot/master/tests/data/telegram.ogg'
|
||||
cls.caption = u"Test voice"
|
||||
|
||||
voice_file = open('tests/data/telegram.ogg', 'rb')
|
||||
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
|
||||
cls.voice = voice
|
||||
|
||||
# Make sure file has been uploaded.
|
||||
cls.assertIsInstance(cls(), cls.voice, telegram.Voice)
|
||||
cls.assertIsInstance(cls(), cls.voice.file_id, str)
|
||||
cls.assertNotEqual(cls(), cls.voice.file_id, '')
|
||||
|
||||
def setUp(self):
|
||||
self.voice_file = open('tests/data/telegram.ogg', 'rb')
|
||||
self.voice_file_url = 'https://raw.githubusercontent.com/python-telegram-bot/python-telegram-bot/master/tests/data/telegram.ogg'
|
||||
self.caption = "Test voice"
|
||||
|
||||
self.json_dict = {
|
||||
'file_id': self.voice_file_id,
|
||||
'duration': self.duration,
|
||||
'file_id': self.voice.file_id,
|
||||
'duration': self.voice.duration,
|
||||
'caption': self.caption,
|
||||
'mime_type': self.mime_type,
|
||||
'file_size': self.file_size
|
||||
'mime_type': self.voice.mime_type,
|
||||
'file_size': self.voice.file_size
|
||||
}
|
||||
|
||||
@flaky(3, 1)
|
||||
@timeout(10)
|
||||
def test_send_voice_required_args_only(self):
|
||||
# Obsolete, tested in setUpClass
|
||||
self.assertEqual(True, True)
|
||||
def test_expected_values(self):
|
||||
self.assertEqual(self.voice.duration, 3)
|
||||
self.assertEqual(self.voice.mime_type, 'audio/ogg')
|
||||
self.assertEqual(self.voice.file_size, 9199)
|
||||
|
||||
@flaky(3, 1)
|
||||
@timeout(10)
|
||||
|
@ -67,10 +73,10 @@ class VoiceTest(BaseTest, unittest.TestCase):
|
|||
message = self._bot.sendVoice(
|
||||
self._chat_id,
|
||||
self.voice_file,
|
||||
duration=self.duration,
|
||||
duration=self.voice.duration,
|
||||
caption=self.caption,
|
||||
mime_type=self.mime_type,
|
||||
file_size=self.file_size,
|
||||
mime_type=self.voice.mime_type,
|
||||
file_size=self.voice.file_size,
|
||||
disable_notification=False)
|
||||
|
||||
self.assertEqual(message.caption, self.caption)
|
||||
|
@ -79,49 +85,23 @@ class VoiceTest(BaseTest, unittest.TestCase):
|
|||
|
||||
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_ogg_file(self):
|
||||
# obsolete: Same as all_args
|
||||
self.assertEqual(True, True)
|
||||
|
||||
@flaky(3, 1)
|
||||
@timeout(10)
|
||||
def test_send_voice_ogg_file_with_custom_filename(self):
|
||||
message = self._bot.sendVoice(
|
||||
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))
|
||||
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)
|
||||
self.assertEqual(voice.duration, self.voice.duration)
|
||||
self.assertEqual(voice.mime_type, self.voice.mime_type)
|
||||
self.assertEqual(voice.file_size, self.voice.file_size)
|
||||
|
||||
@flaky(3, 1)
|
||||
@timeout(10)
|
||||
def test_send_voice_ogg_url_file(self):
|
||||
message = self._bot.sendVoice(
|
||||
chat_id=self._chat_id, voice=self.voice_file_url, duration=self.duration)
|
||||
chat_id=self._chat_id, voice=self.voice_file_url, duration=self.voice.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, self.file_size)
|
||||
self.assertEqual(voice.duration, self.voice.duration)
|
||||
self.assertEqual(voice.mime_type, self.voice.mime_type)
|
||||
self.assertEqual(voice.file_size, self.voice.file_size)
|
||||
|
||||
@flaky(3, 1)
|
||||
@timeout(10)
|
||||
|
@ -129,7 +109,7 @@ class VoiceTest(BaseTest, unittest.TestCase):
|
|||
message = self._bot.sendVoice(
|
||||
chat_id=self._chat_id,
|
||||
voice=self.voice_file_url,
|
||||
duration=self.duration,
|
||||
duration=self.voice.duration,
|
||||
caption=self.caption)
|
||||
|
||||
self.assertEqual(message.caption, self.caption)
|
||||
|
@ -138,30 +118,30 @@ class VoiceTest(BaseTest, unittest.TestCase):
|
|||
|
||||
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)
|
||||
self.assertEqual(voice.duration, self.voice.duration)
|
||||
self.assertEqual(voice.mime_type, self.voice.mime_type)
|
||||
self.assertEqual(voice.file_size, self.voice.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)
|
||||
voice=self.voice.file_id)
|
||||
|
||||
voice = message.voice
|
||||
|
||||
self.assertEqual(voice.file_id, self.voice_file_id)
|
||||
self.assertEqual(voice.duration, self.duration)
|
||||
self.assertEqual(voice.mime_type, self.mime_type)
|
||||
self.assertEqual(voice.file_id, self.voice.file_id)
|
||||
self.assertEqual(voice.duration, self.voice.duration)
|
||||
self.assertEqual(voice.mime_type, self.voice.mime_type)
|
||||
|
||||
def test_voice_de_json(self):
|
||||
voice = telegram.Voice.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertEqual(voice.file_id, self.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)
|
||||
self.assertEqual(voice.file_id, self.voice.file_id)
|
||||
self.assertEqual(voice.duration, self.voice.duration)
|
||||
self.assertEqual(voice.mime_type, self.voice.mime_type)
|
||||
self.assertEqual(voice.file_size, self.voice.file_size)
|
||||
|
||||
def test_voice_to_json(self):
|
||||
voice = telegram.Voice.de_json(self.json_dict, self._bot)
|
||||
|
@ -172,10 +152,10 @@ class VoiceTest(BaseTest, unittest.TestCase):
|
|||
voice = telegram.Voice.de_json(self.json_dict, self._bot)
|
||||
|
||||
self.assertTrue(self.is_dict(voice.to_dict()))
|
||||
self.assertEqual(voice['file_id'], self.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)
|
||||
self.assertEqual(voice['file_id'], self.voice.file_id)
|
||||
self.assertEqual(voice['duration'], self.voice.duration)
|
||||
self.assertEqual(voice['mime_type'], self.voice.mime_type)
|
||||
self.assertEqual(voice['file_size'], self.voice.file_size)
|
||||
|
||||
@flaky(3, 1)
|
||||
@timeout(10)
|
||||
|
@ -219,11 +199,11 @@ class VoiceTest(BaseTest, unittest.TestCase):
|
|||
self.assertNotEqual(message.voice.file_id, '')
|
||||
|
||||
def test_equality(self):
|
||||
a = telegram.Voice(self.voice_file_id, self.duration)
|
||||
b = telegram.Voice(self.voice_file_id, self.duration)
|
||||
c = telegram.Voice(self.voice_file_id, 0)
|
||||
d = telegram.Voice("", self.duration)
|
||||
e = telegram.Audio(self.voice_file_id, self.duration)
|
||||
a = telegram.Voice(self.voice.file_id, self.voice.duration)
|
||||
b = telegram.Voice(self.voice.file_id, self.voice.duration)
|
||||
c = telegram.Voice(self.voice.file_id, 0)
|
||||
d = telegram.Voice("", self.voice.duration)
|
||||
e = telegram.Audio(self.voice.file_id, self.voice.duration)
|
||||
|
||||
self.assertEqual(a, b)
|
||||
self.assertEqual(hash(a), hash(b))
|
||||
|
|
Loading…
Add table
Reference in a new issue