Update test to support UTF8 text messages

This commit is contained in:
Leandro Toledo 2015-07-12 10:31:18 -03:00
parent 649fbc40c8
commit 20b856a05f

View file

@ -11,11 +11,11 @@ class BotTest(unittest.TestCase):
def setUp(self): def setUp(self):
bot = telegram.Bot(token=os.environ.get('TOKEN')) bot = telegram.Bot(token=os.environ.get('TOKEN'))
self._bot = bot self._bot = bot
print 'Testing the Bot API class' print('Testing the Bot API class')
def testGetMe(self): def testGetMe(self):
'''Test the telegram.Bot getMe method''' '''Test the telegram.Bot getMe method'''
print 'Testing getMe' print('Testing getMe')
user = self._bot.getMe() user = self._bot.getMe()
self.assertEqual(120405045, user.id) self.assertEqual(120405045, user.id)
self.assertEqual('Toledo\'s Palace Bot', user.first_name) self.assertEqual('Toledo\'s Palace Bot', user.first_name)
@ -24,92 +24,92 @@ class BotTest(unittest.TestCase):
def testSendMessage(self): def testSendMessage(self):
'''Test the telegram.Bot sendMessage method''' '''Test the telegram.Bot sendMessage method'''
print 'Testing sendMessage' print('Testing sendMessage')
message = self._bot.sendMessage(chat_id=12173560, message = self._bot.sendMessage(chat_id=12173560,
text=u'Моё судно на воздушной подушке полно угрей'.encode('utf8')) text='Моё судно на воздушной подушке полно угрей')
self.assertEqual(u'Моё судно на воздушной подушке полно угрей', message.text) self.assertEqual('Моё судно на воздушной подушке полно угрей', message.text)
def testGetUpdates(self): def testGetUpdates(self):
'''Test the telegram.Bot getUpdates method''' '''Test the telegram.Bot getUpdates method'''
print 'Testing getUpdates' print('Testing getUpdates')
updates = self._bot.getUpdates() updates = self._bot.getUpdates()
self.assertEqual(129566590, updates[0].update_id) self.assertEqual(129566611, updates[0].update_id)
def testForwardMessage(self): def testForwardMessage(self):
'''Test the telegram.Bot forwardMessage method''' '''Test the telegram.Bot forwardMessage method'''
print 'Testing forwardMessage' print('Testing forwardMessage')
message = self._bot.forwardMessage(chat_id=12173560, message = self._bot.forwardMessage(chat_id=12173560,
from_chat_id=12173560, from_chat_id=12173560,
message_id=138) message_id=138)
self.assertEqual(u'Oi', message.text) self.assertEqual('Oi', message.text)
self.assertEqual(u'leandrotoledo', message.forward_from.username) self.assertEqual('leandrotoledo', message.forward_from.username)
def testSendPhoto(self): def testSendPhoto(self):
'''Test the telegram.Bot sendPhoto method''' '''Test the telegram.Bot sendPhoto method'''
print 'Testing sendPhoto - File' print('Testing sendPhoto - File')
message = self._bot.sendPhoto(photo=open('tests/telegram.png', 'rb'), message = self._bot.sendPhoto(photo=open('tests/telegram.png', 'rb'),
chat_id=12173560) chat_id=12173560)
self.assertEqual(1451, message.photo[0].file_size) self.assertEqual(1451, message.photo[0].file_size)
def testResendPhoto(self): def testResendPhoto(self):
'''Test the telegram.Bot sendPhoto method''' '''Test the telegram.Bot sendPhoto method'''
print 'Testing sendPhoto - Resend' print('Testing sendPhoto - Resend')
message = self._bot.sendPhoto(photo=str('AgADAQADr6cxGzU8LQe6q0dMJD2rHYkP2ykABFymiQqJgjxRGGMAAgI'), message = self._bot.sendPhoto(photo=str('AgADAQADr6cxGzU8LQe6q0dMJD2rHYkP2ykABFymiQqJgjxRGGMAAgI'),
chat_id=12173560) chat_id=12173560)
self.assertEqual(u'AgADAQADr6cxGzU8LQe6q0dMJD2rHYkP2ykABFymiQqJgjxRGGMAAgI', message.photo[0].file_id) self.assertEqual('AgADAQADr6cxGzU8LQe6q0dMJD2rHYkP2ykABFymiQqJgjxRGGMAAgI', message.photo[0].file_id)
def testSendAudio(self): def testSendAudio(self):
'''Test the telegram.Bot sendAudio method''' '''Test the telegram.Bot sendAudio method'''
print 'Testing sendAudio - File' print('Testing sendAudio - File')
message = self._bot.sendAudio(audio=open('tests/telegram.ogg', 'rb'), message = self._bot.sendAudio(audio=open('tests/telegram.ogg', 'rb'),
chat_id=12173560) chat_id=12173560)
self.assertEqual(9199, message.audio.file_size) self.assertEqual(9199, message.audio.file_size)
def testResendAudio(self): def testResendAudio(self):
'''Test the telegram.Bot sendAudio method''' '''Test the telegram.Bot sendAudio method'''
print 'Testing sendAudio - Resend' print('Testing sendAudio - Resend')
message = self._bot.sendAudio(audio=str('AwADAQADIQEAAvjAuQABSAXg_GhkhZcC'), message = self._bot.sendAudio(audio=str('AwADAQADIQEAAvjAuQABSAXg_GhkhZcC'),
chat_id=12173560) chat_id=12173560)
self.assertEqual(u'AwADAQADIQEAAvjAuQABSAXg_GhkhZcC', message.audio.file_id) self.assertEqual('AwADAQADIQEAAvjAuQABSAXg_GhkhZcC', message.audio.file_id)
def testSendDocument(self): def testSendDocument(self):
'''Test the telegram.Bot sendDocument method''' '''Test the telegram.Bot sendDocument method'''
print 'Testing sendDocument - File' print('Testing sendDocument - File')
message = self._bot.sendDocument(document=open('tests/telegram.png', 'rb'), message = self._bot.sendDocument(document=open('tests/telegram.png', 'rb'),
chat_id=12173560) chat_id=12173560)
self.assertEqual(12948, message.document.file_size) self.assertEqual(12948, message.document.file_size)
def testResendDocument(self): def testResendDocument(self):
'''Test the telegram.Bot sendDocument method''' '''Test the telegram.Bot sendDocument method'''
print 'Testing sendDocument - Resend' print('Testing sendDocument - Resend')
message = self._bot.sendDocument(document=str('BQADAQADHAADNTwtBxZxUGKyxYbYAg'), message = self._bot.sendDocument(document=str('BQADAQADHAADNTwtBxZxUGKyxYbYAg'),
chat_id=12173560) chat_id=12173560)
self.assertEqual(u'BQADAQADHAADNTwtBxZxUGKyxYbYAg', message.document.file_id) self.assertEqual('BQADAQADHAADNTwtBxZxUGKyxYbYAg', message.document.file_id)
def testResendSticker(self): def testResendSticker(self):
'''Test the telegram.Bot sendSticker method''' '''Test the telegram.Bot sendSticker method'''
print 'Testing sendSticker - Resend' print('Testing sendSticker - Resend')
message = self._bot.sendSticker(sticker=str('BQADAQADHAADyIsGAAFZfq1bphjqlgI'), message = self._bot.sendSticker(sticker=str('BQADAQADHAADyIsGAAFZfq1bphjqlgI'),
chat_id=12173560) chat_id=12173560)
self.assertEqual(39518, message.sticker.file_size) self.assertEqual(39518, message.sticker.file_size)
def testSendVideo(self): def testSendVideo(self):
'''Test the telegram.Bot sendVideo method''' '''Test the telegram.Bot sendVideo method'''
print 'Testing sendVideo - File' print('Testing sendVideo - File')
message = self._bot.sendVideo(video=open('tests/telegram.mp4', 'rb'), message = self._bot.sendVideo(video=open('tests/telegram.mp4', 'rb'),
chat_id=12173560) chat_id=12173560)
self.assertEqual(326534, message.video.file_size) self.assertEqual(326534, message.video.file_size)
def testResendVideo(self): def testResendVideo(self):
'''Test the telegram.Bot sendVideo method''' '''Test the telegram.Bot sendVideo method'''
print 'Testing sendVideo - Resend' print('Testing sendVideo - Resend')
message = self._bot.sendVideo(video=str('BAADAQADIgEAAvjAuQABOuTB937fPTgC'), message = self._bot.sendVideo(video=str('BAADAQADIgEAAvjAuQABOuTB937fPTgC'),
chat_id=12173560) chat_id=12173560)
self.assertEqual(4, message.video.duration) self.assertEqual(4, message.video.duration)
def testSendLocation(self): def testSendLocation(self):
'''Test the telegram.Bot sendLocation method''' '''Test the telegram.Bot sendLocation method'''
print 'Testing sendLocation' print('Testing sendLocation')
message = self._bot.sendLocation(latitude=-23.558873, message = self._bot.sendLocation(latitude=-23.558873,
longitude=-46.659732, longitude=-46.659732,
chat_id=12173560) chat_id=12173560)
@ -118,12 +118,12 @@ class BotTest(unittest.TestCase):
def testSendChatAction(self): def testSendChatAction(self):
'''Test the telegram.Bot sendChatAction method''' '''Test the telegram.Bot sendChatAction method'''
print 'Testing sendChatAction - ChatAction.TYPING' print('Testing sendChatAction - ChatAction.TYPING')
self._bot.sendChatAction(action=telegram.ChatAction.TYPING, self._bot.sendChatAction(action=telegram.ChatAction.TYPING,
chat_id=12173560) chat_id=12173560)
def testGetUserProfilePhotos(self): def testGetUserProfilePhotos(self):
'''Test the telegram.Bot getUserProfilePhotos method''' '''Test the telegram.Bot getUserProfilePhotos method'''
print 'Testing getUserProfilePhotos' print('Testing getUserProfilePhotos')
upf = self._bot.getUserProfilePhotos(user_id=12173560) upf = self._bot.getUserProfilePhotos(user_id=12173560)
self.assertEqual(8314, upf.photos[0][0].file_size) self.assertEqual(8314, upf.photos[0][0].file_size)