finalising

* Added telegram.jpg to gitignore since we're downloading it now
* moved download tests to the right tests to make test_file file_id free
This commit is contained in:
Eldin 2017-06-22 18:29:21 +02:00
parent ac0793caa2
commit cedc38dcdf
9 changed files with 116 additions and 83 deletions

1
.gitignore vendored
View file

@ -69,6 +69,7 @@ telegram2.mp4
telegram.ogg
telegram.png
telegram.webp
telegram.jpg
# original files from merges
*.orig

View file

@ -96,6 +96,19 @@ class AudioTest(BaseTest, unittest.TestCase):
self.assertEqual(audio.mime_type, self.audio.mime_type)
self.assertEqual(audio.file_size, self.audio.file_size)
@flaky(3, 1)
@timeout(10)
def test_get_and_download_audio(self):
new_file = self._bot.getFile(self.audio.file_id)
self.assertEqual(new_file.file_size, self.audio.file_size)
self.assertEqual(new_file.file_id, self.audio.file_id)
self.assertTrue(new_file.file_path.startswith('https://'))
new_file.download('telegram.mp3')
self.assertTrue(os.path.isfile('telegram.mp3'))
@flaky(3, 1)
@timeout(10)
def test_send_audio_mp3_url_file(self):

View file

@ -85,6 +85,19 @@ class DocumentTest(BaseTest, unittest.TestCase):
self.assertEqual(document.thumb, self.document.thumb)
self.assertEqual(message.caption, self.caption)
@flaky(3, 1)
@timeout(10)
def test_get_and_download_document(self):
new_file = self._bot.getFile(self.document.file_id)
self.assertEqual(new_file.file_size, self.document.file_size)
self.assertEqual(new_file.file_id, self.document.file_id)
self.assertTrue(new_file.file_path.startswith('https://'))
new_file.download('telegram.png')
self.assertTrue(os.path.isfile('telegram.png'))
@flaky(3, 1)
@timeout(10)
def test_send_document_png_file_with_custom_file_name(self):

View file

@ -32,93 +32,32 @@ class FileTest(BaseTest, unittest.TestCase):
"""This object represents Tests for Telegram File."""
def setUp(self):
self.audio_file_id = 'BQADAQADDwADHyP1B6PSPq2HjX8kAg'
self.document_file_id = 'BQADAQADpAADHyP1B04ipZxJTe2BAg'
self.sticker_file_id = 'BQADAQADHAADyIsGAAFZfq1bphjqlgI'
self.video_file_id = 'BAADAQADXwADHyP1BwJFTcmY2RYCAg'
self.voice_file_id = 'AwADAQADTgADHyP1B_mbw34svXPHAg'
self.json_dict = {
'file_id': self.audio_file_id,
'file_id': "NOTVALIDDONTMATTER",
'file_path':
'https://api.telegram.org/file/bot133505823:AAHZFMHno3mzVLErU5b5jJvaeG--qUyLyG0/document/file_3',
'file_size': 28232
}
def test_get_and_download_file_audio(self):
newFile = self._bot.getFile(self.audio_file_id)
self.assertEqual(newFile.file_size, 28232)
self.assertEqual(newFile.file_id, self.audio_file_id)
self.assertTrue(newFile.file_path.startswith('https://'))
newFile.download('telegram.mp3')
self.assertTrue(os.path.isfile('telegram.mp3'))
def test_get_and_download_file_document(self):
newFile = self._bot.getFile(self.document_file_id)
self.assertEqual(newFile.file_size, 12948)
self.assertEqual(newFile.file_id, self.document_file_id)
self.assertTrue(newFile.file_path.startswith('https://'))
newFile.download('telegram.png')
self.assertTrue(os.path.isfile('telegram.png'))
def test_get_and_download_file_sticker(self):
newFile = self._bot.getFile(self.sticker_file_id)
self.assertEqual(newFile.file_size, 39518)
self.assertEqual(newFile.file_id, self.sticker_file_id)
self.assertTrue(newFile.file_path.startswith('https://'))
newFile.download('telegram.webp')
self.assertTrue(os.path.isfile('telegram.webp'))
def test_get_and_download_file_video(self):
newFile = self._bot.getFile(self.video_file_id)
self.assertEqual(newFile.file_size, 326534)
self.assertEqual(newFile.file_id, self.video_file_id)
self.assertTrue(newFile.file_path.startswith('https://'))
newFile.download('telegram.mp4')
self.assertTrue(os.path.isfile('telegram.mp4'))
def test_get_and_download_file_voice(self):
newFile = self._bot.getFile(self.voice_file_id)
self.assertEqual(newFile.file_size, 9199)
self.assertEqual(newFile.file_id, self.voice_file_id)
self.assertTrue(newFile.file_path.startswith('https://'))
newFile.download('telegram.ogg')
self.assertTrue(os.path.isfile('telegram.ogg'))
def test_file_de_json(self):
newFile = telegram.File.de_json(self.json_dict, self._bot)
new_file = telegram.File.de_json(self.json_dict, self._bot)
self.assertEqual(newFile.file_id, self.json_dict['file_id'])
self.assertEqual(newFile.file_path, self.json_dict['file_path'])
self.assertEqual(newFile.file_size, self.json_dict['file_size'])
self.assertEqual(new_file.file_id, self.json_dict['file_id'])
self.assertEqual(new_file.file_path, self.json_dict['file_path'])
self.assertEqual(new_file.file_size, self.json_dict['file_size'])
def test_file_to_json(self):
newFile = telegram.File.de_json(self.json_dict, self._bot)
new_file = telegram.File.de_json(self.json_dict, self._bot)
self.assertTrue(self.is_json(newFile.to_json()))
self.assertTrue(self.is_json(new_file.to_json()))
def test_file_to_dict(self):
newFile = telegram.File.de_json(self.json_dict, self._bot)
new_file = telegram.File.de_json(self.json_dict, self._bot).to_dict()
self.assertTrue(self.is_dict(newFile.to_dict()))
self.assertEqual(newFile['file_id'], self.json_dict['file_id'])
self.assertEqual(newFile['file_path'], self.json_dict['file_path'])
self.assertEqual(newFile['file_size'], self.json_dict['file_size'])
self.assertTrue(self.is_dict(new_file))
self.assertEqual(new_file['file_id'], self.json_dict['file_id'])
self.assertEqual(new_file['file_path'], self.json_dict['file_path'])
self.assertEqual(new_file['file_size'], self.json_dict['file_size'])
def test_error_get_empty_file_id(self):
json_dict = self.json_dict
@ -126,7 +65,8 @@ class FileTest(BaseTest, unittest.TestCase):
del (json_dict['file_path'])
del (json_dict['file_size'])
self.assertRaises(telegram.TelegramError, lambda: self._bot.getFile(**json_dict))
with self.assertRaises(telegram.TelegramError):
self._bot.getFile(**json_dict)
def test_error_file_without_required_args(self):
json_dict = self.json_dict
@ -135,14 +75,16 @@ class FileTest(BaseTest, unittest.TestCase):
del (json_dict['file_path'])
del (json_dict['file_size'])
self.assertRaises(TypeError, lambda: self._bot.getFile(**json_dict))
with self.assertRaises(TypeError):
self._bot.getFile(**json_dict)
def test_equality(self):
a = telegram.File(self.audio_file_id, self._bot)
b = telegram.File(self.audio_file_id, self._bot)
c = telegram.File(self.audio_file_id, None)
d = telegram.File(self.document_file_id, self._bot)
e = telegram.Voice(self.audio_file_id, 0)
a = telegram.File("DOESNTMATTER", self._bot)
b = telegram.File("DOESNTMATTER", self._bot)
c = telegram.File("DOESNTMATTER", None)
d = telegram.File("DOESNTMATTER2", self._bot)
e = telegram.Voice("DOESNTMATTER", 0)
self.assertEqual(a, b)
self.assertEqual(hash(a), hash(b))

View file

@ -94,6 +94,20 @@ class PhotoTest(BaseTest, unittest.TestCase):
self.assertEqual(message.caption, self.caption)
@flaky(3, 1)
@timeout(10)
def test_get_and_download_photo(self):
new_file = self._bot.getFile(self.photo.file_id)
self.assertEqual(new_file.file_size, self.photo.file_size)
self.assertEqual(new_file.file_id, self.photo.file_id)
self.assertTrue(new_file.file_path.startswith('https://'))
new_file.download('telegram.jpg')
self.assertTrue(os.path.isfile('telegram.jpg'))
@flaky(3, 1)
@timeout(10)
def test_send_photo_url_jpg_file(self):

View file

@ -82,6 +82,19 @@ class StickerTest(BaseTest, unittest.TestCase):
self.assertEqual(sticker, self.sticker)
@flaky(3, 1)
@timeout(10)
def test_get_and_download_sticker(self):
new_file = self._bot.getFile(self.sticker.file_id)
self.assertEqual(new_file.file_size, self.sticker.file_size)
self.assertEqual(new_file.file_id, self.sticker.file_id)
self.assertTrue(new_file.file_path.startswith('https://'))
new_file.download('telegram.webp')
self.assertTrue(os.path.isfile('telegram.webp'))
@flaky(3, 1)
@timeout(10)
def test_send_sticker_resend(self):
@ -146,7 +159,7 @@ class StickerTest(BaseTest, unittest.TestCase):
self.assertEqual(sticker['file_id'], self.sticker.file_id)
self.assertEqual(sticker['width'], self.sticker.width)
self.assertEqual(sticker['height'], self.sticker.height)
self.assertIsInstance(sticker['thumb'], telegram.PhotoSize)
self.assertIsInstance(sticker['thumb'], dict)
self.assertEqual(sticker['file_size'], self.sticker.file_size)
@flaky(3, 1)

View file

@ -93,6 +93,19 @@ class VideoTest(BaseTest, unittest.TestCase):
self.assertEqual(message.caption, self.caption)
@flaky(3, 1)
@timeout(10)
def test_get_and_download_video(self):
new_file = self._bot.getFile(self.video.file_id)
self.assertEqual(new_file.file_size, self.video.file_size)
self.assertEqual(new_file.file_id, self.video.file_id)
self.assertTrue(new_file.file_path.startswith('https://'))
new_file.download('telegram.mp4')
self.assertTrue(os.path.isfile('telegram.mp4'))
@flaky(3, 1)
@timeout(10)
def test_send_video_mp4_file_url(self):
@ -131,8 +144,6 @@ class VideoTest(BaseTest, unittest.TestCase):
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)

View file

@ -84,6 +84,19 @@ class VideoNoteTest(BaseTest, unittest.TestCase):
self.assertEqual(videonote.thumb, self.videonote.thumb)
self.assertEqual(videonote.file_size, self.videonote.file_size)
@flaky(3, 1)
@timeout(10)
def test_get_and_download_videonote(self):
new_file = self._bot.getFile(self.videonote.file_id)
self.assertEqual(new_file.file_size, self.videonote.file_size)
self.assertEqual(new_file.file_id, self.videonote.file_id)
self.assertTrue(new_file.file_path.startswith('https://'))
new_file.download('telegram2.mp4')
self.assertTrue(os.path.isfile('telegram2.mp4'))
@flaky(3, 1)
@timeout(10)
def test_send_videonote_resend(self):

View file

@ -90,6 +90,19 @@ class VoiceTest(BaseTest, unittest.TestCase):
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_get_and_download_voice(self):
new_file = self._bot.getFile(self.voice.file_id)
self.assertEqual(new_file.file_size, self.voice.file_size)
self.assertEqual(new_file.file_id, self.voice.file_id)
self.assertTrue(new_file.file_path.startswith('https://'))
new_file.download('telegram.ogg')
self.assertTrue(os.path.isfile('telegram.ogg'))
@flaky(3, 1)
@timeout(10)
def test_send_voice_ogg_url_file(self):