From 8c3ed7c62917a94b90b3fb50b3217550b8eea84b Mon Sep 17 00:00:00 2001 From: Leandro Toledo Date: Tue, 7 Jul 2015 17:04:42 -0300 Subject: [PATCH] Adding tests --- test.py | 5 +++++ tests/__init__.py | 0 tests/test_bot.py | 52 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 test.py create mode 100644 tests/__init__.py create mode 100644 tests/test_bot.py diff --git a/test.py b/test.py new file mode 100644 index 000000000..d00c23f48 --- /dev/null +++ b/test.py @@ -0,0 +1,5 @@ +import unittest + +if __name__ == '__main__': + testsuite = unittest.TestLoader().discover('.') + unittest.TextTestRunner(verbosity=1).run(testsuite) diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/test_bot.py b/tests/test_bot.py new file mode 100644 index 000000000..a0c2b1dca --- /dev/null +++ b/tests/test_bot.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python +# encoding: utf-8 + +import os +import telegram +import unittest + +from token import TOKEN + + +@unittest.skipIf(not TOKEN, "No tokens provided") +class BotTest(unittest.TestCase): + def setUp(self): + bot = telegram.Bot(token=os.environ.get('TOKEN')) + self._bot = bot + print 'Testing the Bot API class' + + def testGetMe(self): + '''Test the telegram.Bot getMe method''' + print 'Testing getMe' + user = self._bot.getMe() + self.assertEqual(120405045, user.id) + self.assertEqual('Toledo\'s Palace Bot', user.first_name) + self.assertEqual(None, user.last_name) + self.assertEqual('ToledosPalaceBot', user.username) + + def testSendMessage(self): + '''Test the telegram.Bot sendMessage method''' + print 'Testing sendMessage' + message = self._bot.sendMessage(chat_id=12173560, + text=u'Моё судно на воздушной подушке полно угрей'.encode('utf8')) + self.assertEqual(u'Моё судно на воздушной подушке полно угрей', message.text) + + def testGetUpdates(self): + '''Test the telegram.Bot getUpdates method''' + print 'Testing getUpdates' + updates = self._bot.getUpdates() + self.assertEqual(129566481, updates[0].update_id) + + def testForwardMessage(self): + '''Test the telegram.Bot forwardMessage method''' + print 'Testing forwardMessage' + message = self._bot.forwardMessage(chat_id=12173560, + from_chat_id=12173560, + message_id=138) + self.assertEqual(u'Oi', message.text) + self.assertEqual(u'leandrotoledo', message.forward_from.username) + + # def testSendPhoto(self): + # '''Test the telegram.Bot sendPhoto method''' + # print 'Testing sendPhoto' + # message = self._bot.sendPhoto()