X Tutup
Skip to content

Commit 8c3ed7c

Browse files
committed
Adding tests
1 parent fdc913a commit 8c3ed7c

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

test.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import unittest
2+
3+
if __name__ == '__main__':
4+
testsuite = unittest.TestLoader().discover('.')
5+
unittest.TextTestRunner(verbosity=1).run(testsuite)

tests/__init__.py

Whitespace-only changes.

tests/test_bot.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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

Comments
 (0)
X Tutup