Skip to content

Commit 7b7c4a8

Browse files
committed
test_voice done
* Changed to new method of non-static file_id * removed obsolete tests.
1 parent 6b7ce7b commit 7b7c4a8

File tree

2 files changed

+31
-47
lines changed

2 files changed

+31
-47
lines changed

tests/test_video.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ def test_send_video_all_args(self):
8282
self.video_file,
8383
timeout=10,
8484
duration=self.duration,
85-
caption=self.caption)
85+
caption=self.caption,
86+
disable_notification=False)
8687

8788
video = message.video
8889

tests/test_voice.py

Lines changed: 29 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
from flaky import flaky
2626

27+
from tests.bots import get_bot
28+
2729
sys.path.append('.')
2830

2931
import telegram
@@ -33,15 +35,23 @@
3335
class VoiceTest(BaseTest, unittest.TestCase):
3436
"""This object represents Tests for Telegram Voice."""
3537

38+
@classmethod
39+
def setUpClass(cls):
40+
bot_info = get_bot()
41+
cls._chat_id = bot_info['chat_id']
42+
cls._bot = telegram.Bot(bot_info['token'])
43+
voice_file = open('tests/data/telegram.ogg', 'rb')
44+
voice = cls._bot.send_voice(cls._chat_id, voice=voice_file).voice
45+
cls.voice_file_id = voice.file_id
46+
cls.duration = voice.duration
47+
cls.mime_type = voice.mime_type
48+
cls.file_size = voice.file_size
49+
50+
3651
def setUp(self):
3752
self.voice_file = open('tests/data/telegram.ogg', 'rb')
38-
self.voice_file_id = 'AwADAQADTgADHyP1B_mbw34svXPHAg'
3953
self.voice_file_url = 'https://raw.githubusercontent.com/python-telegram-bot/python-telegram-bot/master/tests/data/telegram.ogg'
40-
self.duration = 3
4154
self.caption = "Test voice"
42-
self.mime_type = 'audio/ogg'
43-
self.file_size = 9199
44-
4555
self.json_dict = {
4656
'file_id': self.voice_file_id,
4757
'duration': self.duration,
@@ -53,15 +63,8 @@ def setUp(self):
5363
@flaky(3, 1)
5464
@timeout(10)
5565
def test_send_voice_required_args_only(self):
56-
message = self._bot.sendVoice(self._chat_id, self.voice_file)
57-
58-
voice = message.voice
59-
60-
self.assertTrue(isinstance(voice.file_id, str))
61-
self.assertNotEqual(voice.file_id, '')
62-
self.assertEqual(voice.duration, self.duration)
63-
self.assertEqual(voice.mime_type, self.mime_type)
64-
self.assertEqual(voice.file_size, self.file_size)
66+
# Obsolete, tested in setUpClass
67+
self.assertEqual(True, True)
6568

6669
@flaky(3, 1)
6770
@timeout(10)
@@ -72,7 +75,8 @@ def test_send_voice_all_args(self):
7275
duration=self.duration,
7376
caption=self.caption,
7477
mime_type=self.mime_type,
75-
file_size=self.file_size)
78+
file_size=self.file_size,
79+
disable_notification=False)
7680

7781
self.assertEqual(message.caption, self.caption)
7882

@@ -87,21 +91,8 @@ def test_send_voice_all_args(self):
8791
@flaky(3, 1)
8892
@timeout(10)
8993
def test_send_voice_ogg_file(self):
90-
message = self._bot.sendVoice(
91-
chat_id=self._chat_id,
92-
voice=self.voice_file,
93-
duration=self.duration,
94-
caption=self.caption)
95-
96-
self.assertEqual(message.caption, self.caption)
97-
98-
voice = message.voice
99-
100-
self.assertTrue(isinstance(voice.file_id, str))
101-
self.assertNotEqual(voice.file_id, '')
102-
self.assertEqual(voice.duration, self.duration)
103-
self.assertEqual(voice.mime_type, self.mime_type)
104-
self.assertEqual(voice.file_size, self.file_size)
94+
# obsolete: Same as all_args
95+
self.assertEqual(True, True)
10596

10697
@flaky(3, 1)
10798
@timeout(10)
@@ -161,16 +152,12 @@ def test_send_voice_ogg_url_file_with_caption(self):
161152
def test_send_voice_resend(self):
162153
message = self._bot.sendVoice(
163154
chat_id=self._chat_id,
164-
voice=self.voice_file_id,
165-
duration=self.duration,
166-
caption=self.caption)
167-
168-
self.assertEqual(message.caption, self.caption)
155+
voice=self.voice_file_id)
169156

170157
voice = message.voice
171158

172159
self.assertEqual(voice.file_id, self.voice_file_id)
173-
self.assertEqual(voice.duration, 0)
160+
self.assertEqual(voice.duration, self.duration)
174161
self.assertEqual(voice.mime_type, self.mime_type)
175162

176163
def test_voice_de_json(self):
@@ -203,9 +190,8 @@ def test_error_send_voice_empty_file(self):
203190
del (json_dict['file_id'])
204191
json_dict['voice'] = open(os.devnull, 'rb')
205192

206-
self.assertRaises(
207-
telegram.TelegramError,
208-
lambda: self._bot.sendVoice(chat_id=self._chat_id, **json_dict))
193+
with self.assertRaises(telegram.TelegramError):
194+
self._bot.sendVoice(chat_id=self._chat_id, **json_dict)
209195

210196
@flaky(3, 1)
211197
@timeout(10)
@@ -215,21 +201,18 @@ def test_error_send_voice_empty_file_id(self):
215201
del (json_dict['file_id'])
216202
json_dict['voice'] = ''
217203

218-
self.assertRaises(
219-
telegram.TelegramError,
220-
lambda: self._bot.sendVoice(chat_id=self._chat_id, **json_dict))
204+
with self.assertRaises(telegram.TelegramError):
205+
self._bot.sendVoice(chat_id=self._chat_id, **json_dict)
221206

222207
@flaky(3, 1)
223208
@timeout(10)
224209
def test_error_voice_without_required_args(self):
225210
json_dict = self.json_dict
226211

227212
del (json_dict['file_id'])
228-
del (json_dict['duration'])
229213

230-
self.assertRaises(
231-
TypeError,
232-
lambda: self._bot.sendVoice(chat_id=self._chat_id, **json_dict))
214+
with self.assertRaises(TypeError):
215+
self._bot.sendVoice(chat_id=self._chat_id, **json_dict)
233216

234217
@flaky(3, 1)
235218
@timeout(10)

0 commit comments

Comments
 (0)