diff --git a/telegram/inputfile.py b/telegram/inputfile.py index 5d42f734b..cdde0177d 100644 --- a/telegram/inputfile.py +++ b/telegram/inputfile.py @@ -67,7 +67,7 @@ class InputFile(object): if isinstance(self.input_file, file): self.input_file_content = self.input_file.read() - if 'filename' in self.data: + if 'filename' in data: self.filename = self.data.pop('filename') else: self.filename = os.path.basename(self.input_file.name) diff --git a/tests/test_audio.py b/tests/test_audio.py index 759c0c0c3..fa7be8b91 100644 --- a/tests/test_audio.py +++ b/tests/test_audio.py @@ -71,7 +71,7 @@ class AudioTest(BaseTest, unittest.TestCase): message = self._bot.sendAudio(self._chat_id, self.audio_file, - self.duration, + duration=self.duration, performer=self.performer, title=self.title, mime_type=self.mime_type, @@ -107,6 +107,27 @@ 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_file_custom_filename(self): + """Test telegram.Bot sendAudio method""" + print('Testing bot.sendAudio - MP3 File with custom filename') + + message = self._bot.sendAudio(chat_id=self._chat_id, + audio=self.audio_file, + duration=self.duration, + performer=self.performer, + title=self.title, + filename='telegram_custom.mp3') + + 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, self.file_size) + def test_send_audio_resend(self): """Test telegram.Bot sendAudio method""" print('Testing bot.sendAudio - Resend by file_id') @@ -123,7 +144,7 @@ class AudioTest(BaseTest, unittest.TestCase): self.assertEqual(audio.duration, self.duration) self.assertEqual(audio.performer, self.performer) self.assertEqual(audio.title, self.title) - self.assertEqual(audio.mime_type, '') + self.assertEqual(audio.mime_type, self.mime_type) self.assertEqual(audio.file_size, self.file_size) def test_audio_de_json(self): diff --git a/tests/test_document.py b/tests/test_document.py index 15aa53dc7..e606f568f 100644 --- a/tests/test_document.py +++ b/tests/test_document.py @@ -66,6 +66,23 @@ class DocumentTest(BaseTest, unittest.TestCase): self.assertEqual(document.mime_type, self.mime_type) self.assertEqual(document.file_size, self.file_size) + def test_send_document_png_file_with_custom_file_name(self): + """Test telegram.Bot sendDocument method""" + print('Testing bot.sendDocument - PNG File with custom filename') + + message = self._bot.sendDocument(self._chat_id, + self.document_file, + filename='telegram_custom.png') + + document = message.document + + self.assertTrue(isinstance(document.file_id, str)) + self.assertNotEqual(document.file_id, '') + self.assertTrue(isinstance(document.thumb, telegram.PhotoSize)) + self.assertEqual(document.file_name, 'telegram_custom.png') + self.assertEqual(document.mime_type, self.mime_type) + self.assertEqual(document.file_size, self.file_size) + def test_send_document_url_gif_file(self): """Test telegram.Bot sendDocument method""" print('Testing bot.sendDocument - GIF File by URL') @@ -93,8 +110,8 @@ class DocumentTest(BaseTest, unittest.TestCase): self.assertEqual(document.file_id, self.document_file_id) self.assertTrue(isinstance(document.thumb, telegram.PhotoSize)) - self.assertEqual(document.file_name, '') - self.assertEqual(document.mime_type, '') + self.assertEqual(document.file_name, self.file_name) + self.assertEqual(document.mime_type, self.mime_type) self.assertEqual(document.file_size, self.file_size) def test_document_de_json(self): diff --git a/tests/test_video.py b/tests/test_video.py index a27c48b3b..1c2b230ac 100644 --- a/tests/test_video.py +++ b/tests/test_video.py @@ -115,6 +115,29 @@ class VideoTest(BaseTest, unittest.TestCase): self.assertEqual(message.caption, self.caption) + def test_send_video_mp4_file_with_custom_filename(self): + """Test telegram.Bot sendVideo method""" + print('Testing bot.sendVideo - MP4 File with custom filename') + + message = self._bot.sendVideo(chat_id=self._chat_id, + video=self.video_file, + 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, 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, self.file_size) + + 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 201da9d6f..9418f1185 100644 --- a/tests/test_voice.py +++ b/tests/test_voice.py @@ -93,6 +93,23 @@ 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_file_with_custom_filename(self): + """Test telegram.Bot sendVoice method""" + print('Testing bot.sendVoice - Ogg File with custom filename') + + message = self._bot.sendVoice(chat_id=self._chat_id, + voice=self.voice_file, + duration=self.duration, + filename='telegram_custom.ogg') + + 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) + def test_send_voice_resend(self): """Test telegram.Bot sendVoice method""" print('Testing bot.sendVoice - Resend by file_id')