2015-07-07 22:04:42 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# encoding: utf-8
|
|
|
|
import os
|
|
|
|
import telegram
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
|
|
|
|
class BotTest(unittest.TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
bot = telegram.Bot(token=os.environ.get('TOKEN'))
|
|
|
|
self._bot = bot
|
2015-07-12 15:31:18 +02:00
|
|
|
print('Testing the Bot API class')
|
2015-07-07 22:04:42 +02:00
|
|
|
|
|
|
|
def testGetMe(self):
|
|
|
|
'''Test the telegram.Bot getMe method'''
|
2015-07-12 15:31:18 +02:00
|
|
|
print('Testing getMe')
|
2015-07-14 10:24:08 +02:00
|
|
|
bot = self._bot.getMe()
|
|
|
|
self.assertEqual(120405045, bot.id)
|
|
|
|
self.assertEqual('Toledo\'s Palace Bot', bot.first_name)
|
|
|
|
self.assertEqual(None, bot.last_name)
|
|
|
|
self.assertEqual('ToledosPalaceBot', bot.username)
|
2015-07-07 22:04:42 +02:00
|
|
|
|
|
|
|
def testSendMessage(self):
|
|
|
|
'''Test the telegram.Bot sendMessage method'''
|
2015-07-12 15:31:18 +02:00
|
|
|
print('Testing sendMessage')
|
2015-07-07 22:04:42 +02:00
|
|
|
message = self._bot.sendMessage(chat_id=12173560,
|
2015-07-12 15:31:18 +02:00
|
|
|
text='Моё судно на воздушной подушке полно угрей')
|
2015-07-15 15:05:31 +02:00
|
|
|
self.assertEqual(u'Моё судно на воздушной подушке полно угрей', message.text)
|
2015-07-07 22:04:42 +02:00
|
|
|
|
|
|
|
def testGetUpdates(self):
|
|
|
|
'''Test the telegram.Bot getUpdates method'''
|
2015-07-12 15:31:18 +02:00
|
|
|
print('Testing getUpdates')
|
2015-07-07 22:04:42 +02:00
|
|
|
updates = self._bot.getUpdates()
|
2015-07-14 10:24:08 +02:00
|
|
|
self.assertIsInstance(updates[0], telegram.Update)
|
2015-07-07 22:04:42 +02:00
|
|
|
|
|
|
|
def testForwardMessage(self):
|
|
|
|
'''Test the telegram.Bot forwardMessage method'''
|
2015-07-12 15:31:18 +02:00
|
|
|
print('Testing forwardMessage')
|
2015-07-07 22:04:42 +02:00
|
|
|
message = self._bot.forwardMessage(chat_id=12173560,
|
|
|
|
from_chat_id=12173560,
|
|
|
|
message_id=138)
|
2015-07-12 15:31:18 +02:00
|
|
|
self.assertEqual('Oi', message.text)
|
|
|
|
self.assertEqual('leandrotoledo', message.forward_from.username)
|
2015-07-07 22:04:42 +02:00
|
|
|
|
2015-07-07 23:46:32 +02:00
|
|
|
def testSendPhoto(self):
|
|
|
|
'''Test the telegram.Bot sendPhoto method'''
|
2015-07-12 15:31:18 +02:00
|
|
|
print('Testing sendPhoto - File')
|
2015-07-07 23:46:32 +02:00
|
|
|
message = self._bot.sendPhoto(photo=open('tests/telegram.png', 'rb'),
|
|
|
|
chat_id=12173560)
|
2015-07-11 15:01:07 +02:00
|
|
|
self.assertEqual(1451, message.photo[0].file_size)
|
2015-07-08 00:06:17 +02:00
|
|
|
|
2015-07-08 01:10:43 +02:00
|
|
|
def testResendPhoto(self):
|
2015-07-08 00:06:17 +02:00
|
|
|
'''Test the telegram.Bot sendPhoto method'''
|
2015-07-12 15:31:18 +02:00
|
|
|
print('Testing sendPhoto - Resend')
|
2015-07-11 15:01:07 +02:00
|
|
|
message = self._bot.sendPhoto(photo=str('AgADAQADr6cxGzU8LQe6q0dMJD2rHYkP2ykABFymiQqJgjxRGGMAAgI'),
|
2015-07-08 00:06:17 +02:00
|
|
|
chat_id=12173560)
|
2015-07-12 15:31:18 +02:00
|
|
|
self.assertEqual('AgADAQADr6cxGzU8LQe6q0dMJD2rHYkP2ykABFymiQqJgjxRGGMAAgI', message.photo[0].file_id)
|
2015-07-08 01:10:43 +02:00
|
|
|
|
2015-07-14 10:24:08 +02:00
|
|
|
def testSendURLPhoto(self):
|
|
|
|
'''Test the telegram.Bot sendPhoto method'''
|
|
|
|
print('Testing sendPhoto - URL')
|
|
|
|
message = self._bot.sendPhoto(photo=str('http://dummyimage.com/600x400/000/fff.jpg&text=telegram'),
|
|
|
|
chat_id=12173560)
|
|
|
|
self.assertEqual(822, message.photo[0].file_size)
|
|
|
|
|
2015-07-08 01:10:43 +02:00
|
|
|
def testSendAudio(self):
|
|
|
|
'''Test the telegram.Bot sendAudio method'''
|
2015-07-12 15:31:18 +02:00
|
|
|
print('Testing sendAudio - File')
|
2015-07-08 01:10:43 +02:00
|
|
|
message = self._bot.sendAudio(audio=open('tests/telegram.ogg', 'rb'),
|
|
|
|
chat_id=12173560)
|
2015-07-08 01:52:57 +02:00
|
|
|
self.assertEqual(9199, message.audio.file_size)
|
2015-07-08 01:10:43 +02:00
|
|
|
|
|
|
|
def testResendAudio(self):
|
|
|
|
'''Test the telegram.Bot sendAudio method'''
|
2015-07-12 15:31:18 +02:00
|
|
|
print('Testing sendAudio - Resend')
|
2015-07-08 01:10:43 +02:00
|
|
|
message = self._bot.sendAudio(audio=str('AwADAQADIQEAAvjAuQABSAXg_GhkhZcC'),
|
|
|
|
chat_id=12173560)
|
2015-07-12 15:31:18 +02:00
|
|
|
self.assertEqual('AwADAQADIQEAAvjAuQABSAXg_GhkhZcC', message.audio.file_id)
|
2015-07-08 02:12:51 +02:00
|
|
|
|
|
|
|
def testSendDocument(self):
|
|
|
|
'''Test the telegram.Bot sendDocument method'''
|
2015-07-12 15:31:18 +02:00
|
|
|
print('Testing sendDocument - File')
|
2015-07-08 02:12:51 +02:00
|
|
|
message = self._bot.sendDocument(document=open('tests/telegram.png', 'rb'),
|
|
|
|
chat_id=12173560)
|
|
|
|
self.assertEqual(12948, message.document.file_size)
|
|
|
|
|
|
|
|
def testResendDocument(self):
|
|
|
|
'''Test the telegram.Bot sendDocument method'''
|
2015-07-12 15:31:18 +02:00
|
|
|
print('Testing sendDocument - Resend')
|
2015-07-08 02:12:51 +02:00
|
|
|
message = self._bot.sendDocument(document=str('BQADAQADHAADNTwtBxZxUGKyxYbYAg'),
|
|
|
|
chat_id=12173560)
|
2015-07-12 15:31:18 +02:00
|
|
|
self.assertEqual('BQADAQADHAADNTwtBxZxUGKyxYbYAg', message.document.file_id)
|
2015-07-08 04:52:12 +02:00
|
|
|
|
2015-07-10 18:43:35 +02:00
|
|
|
def testSendVideo(self):
|
|
|
|
'''Test the telegram.Bot sendVideo method'''
|
2015-07-12 15:31:18 +02:00
|
|
|
print('Testing sendVideo - File')
|
2015-07-10 18:43:35 +02:00
|
|
|
message = self._bot.sendVideo(video=open('tests/telegram.mp4', 'rb'),
|
|
|
|
chat_id=12173560)
|
|
|
|
self.assertEqual(326534, message.video.file_size)
|
|
|
|
|
2015-07-08 14:17:18 +02:00
|
|
|
def testResendVideo(self):
|
|
|
|
'''Test the telegram.Bot sendVideo method'''
|
2015-07-12 15:31:18 +02:00
|
|
|
print('Testing sendVideo - Resend')
|
2015-07-08 14:17:18 +02:00
|
|
|
message = self._bot.sendVideo(video=str('BAADAQADIgEAAvjAuQABOuTB937fPTgC'),
|
2015-07-08 14:37:25 +02:00
|
|
|
chat_id=12173560)
|
2015-07-08 14:17:18 +02:00
|
|
|
self.assertEqual(4, message.video.duration)
|
2015-07-08 14:37:25 +02:00
|
|
|
|
2015-07-14 10:24:08 +02:00
|
|
|
def testResendSticker(self):
|
|
|
|
'''Test the telegram.Bot sendSticker method'''
|
|
|
|
print('Testing sendSticker - Resend')
|
|
|
|
message = self._bot.sendSticker(sticker=str('BQADAQADHAADyIsGAAFZfq1bphjqlgI'),
|
|
|
|
chat_id=12173560)
|
|
|
|
self.assertEqual(39518, message.sticker.file_size)
|
|
|
|
|
2015-07-08 14:37:25 +02:00
|
|
|
def testSendLocation(self):
|
|
|
|
'''Test the telegram.Bot sendLocation method'''
|
2015-07-12 15:31:18 +02:00
|
|
|
print('Testing sendLocation')
|
2015-07-08 14:37:25 +02:00
|
|
|
message = self._bot.sendLocation(latitude=-23.558873,
|
|
|
|
longitude=-46.659732,
|
|
|
|
chat_id=12173560)
|
|
|
|
self.assertEqual(-23.558873, message.location.latitude)
|
|
|
|
self.assertEqual(-46.659732, message.location.longitude)
|
2015-07-08 14:55:06 +02:00
|
|
|
|
|
|
|
def testSendChatAction(self):
|
|
|
|
'''Test the telegram.Bot sendChatAction method'''
|
2015-07-12 15:31:18 +02:00
|
|
|
print('Testing sendChatAction - ChatAction.TYPING')
|
2015-07-08 22:58:50 +02:00
|
|
|
self._bot.sendChatAction(action=telegram.ChatAction.TYPING,
|
|
|
|
chat_id=12173560)
|
2015-07-08 15:10:08 +02:00
|
|
|
|
|
|
|
def testGetUserProfilePhotos(self):
|
|
|
|
'''Test the telegram.Bot getUserProfilePhotos method'''
|
2015-07-12 15:31:18 +02:00
|
|
|
print('Testing getUserProfilePhotos')
|
2015-07-08 15:10:08 +02:00
|
|
|
upf = self._bot.getUserProfilePhotos(user_id=12173560)
|
|
|
|
self.assertEqual(8314, upf.photos[0][0].file_size)
|