|
| 1 | +#!/usr/bin/env python |
| 2 | +# encoding: utf-8 |
| 3 | + |
| 4 | +import os |
| 5 | +import telegram |
| 6 | +import unittest |
| 7 | + |
| 8 | +from token import TOKEN |
| 9 | + |
| 10 | + |
| 11 | +@unittest.skipIf(not TOKEN, "No tokens provided") |
| 12 | +class BotTest(unittest.TestCase): |
| 13 | + def setUp(self): |
| 14 | + bot = telegram.Bot(token=os.environ.get('TOKEN')) |
| 15 | + self._bot = bot |
| 16 | + print 'Testing the Bot API class' |
| 17 | + |
| 18 | + def testGetMe(self): |
| 19 | + '''Test the telegram.Bot getMe method''' |
| 20 | + print 'Testing getMe' |
| 21 | + user = self._bot.getMe() |
| 22 | + self.assertEqual(120405045, user.id) |
| 23 | + self.assertEqual('Toledo\'s Palace Bot', user.first_name) |
| 24 | + self.assertEqual(None, user.last_name) |
| 25 | + self.assertEqual('ToledosPalaceBot', user.username) |
| 26 | + |
| 27 | + def testSendMessage(self): |
| 28 | + '''Test the telegram.Bot sendMessage method''' |
| 29 | + print 'Testing sendMessage' |
| 30 | + message = self._bot.sendMessage(chat_id=12173560, |
| 31 | + text=u'Моё судно на воздушной подушке полно угрей'.encode('utf8')) |
| 32 | + self.assertEqual(u'Моё судно на воздушной подушке полно угрей', message.text) |
| 33 | + |
| 34 | + def testGetUpdates(self): |
| 35 | + '''Test the telegram.Bot getUpdates method''' |
| 36 | + print 'Testing getUpdates' |
| 37 | + updates = self._bot.getUpdates() |
| 38 | + self.assertEqual(129566481, updates[0].update_id) |
| 39 | + |
| 40 | + def testForwardMessage(self): |
| 41 | + '''Test the telegram.Bot forwardMessage method''' |
| 42 | + print 'Testing forwardMessage' |
| 43 | + message = self._bot.forwardMessage(chat_id=12173560, |
| 44 | + from_chat_id=12173560, |
| 45 | + message_id=138) |
| 46 | + self.assertEqual(u'Oi', message.text) |
| 47 | + self.assertEqual(u'leandrotoledo', message.forward_from.username) |
| 48 | + |
| 49 | + # def testSendPhoto(self): |
| 50 | + # '''Test the telegram.Bot sendPhoto method''' |
| 51 | + # print 'Testing sendPhoto' |
| 52 | + # message = self._bot.sendPhoto() |
0 commit comments