Skip to content

Commit 354bfca

Browse files
committed
legacy tests now run using BaseTest
1 parent a1e12d4 commit 354bfca

2 files changed

Lines changed: 141 additions & 244 deletions

File tree

tests/legacy/test_bot.py

Lines changed: 0 additions & 244 deletions
This file was deleted.

tests/test_bot.py

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
#!/usr/bin/env python
2+
# encoding: utf-8
3+
#
4+
# A library that provides a Python interface to the Telegram Bot API
5+
# Copyright (C) 2015 Leandro Toledo de Souza <leandrotoeldodesouza@gmail.com>
6+
#
7+
# This program is free software: you can redistribute it and/or modify
8+
# it under the terms of the GNU General Public License as published by
9+
# the Free Software Foundation, either version 3 of the License, or
10+
# (at your option) any later version.
11+
#
12+
# This program is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU General Public License
18+
# along with this program. If not, see [http://www.gnu.org/licenses/].
19+
20+
"""This module contains a object that represents Tests for Telegram Bot"""
21+
22+
import os
23+
import unittest
24+
from datetime import datetime
25+
import sys
26+
sys.path.append('.')
27+
28+
import telegram
29+
from tests.base import BaseTest
30+
31+
32+
class BotTest(BaseTest, unittest.TestCase):
33+
"""This object represents Tests for Telegram Bot."""
34+
35+
def testGetMe(self):
36+
'''Test the telegram.Bot getMe method'''
37+
print('Testing getMe')
38+
bot = self._bot.getMe()
39+
40+
self.assertTrue(self.is_json(bot.to_json()))
41+
self.assertEqual(bot.id, 133505823)
42+
self.assertEqual(bot.first_name, 'PythonTelegramBot')
43+
self.assertEqual(bot.last_name, '')
44+
self.assertEqual(bot.username, 'PythonTelegramBot')
45+
self.assertEqual(bot.name, '@PythonTelegramBot')
46+
47+
def testSendMessage(self):
48+
'''Test the telegram.Bot sendMessage method'''
49+
print('Testing sendMessage')
50+
message = self._bot.sendMessage(chat_id=self._chat_id,
51+
text='Моё судно на воздушной подушке полно угрей')
52+
53+
self.assertTrue(self.is_json(message.to_json()))
54+
self.assertEqual(message.text, u'Моё судно на воздушной подушке полно угрей')
55+
self.assertTrue(isinstance(message.date, datetime))
56+
57+
def testGetUpdates(self):
58+
'''Test the telegram.Bot getUpdates method'''
59+
print('Testing getUpdates')
60+
updates = self._bot.getUpdates()
61+
62+
if updates:
63+
self.assertTrue(self.is_json(updates[0].to_json()))
64+
self.assertTrue(isinstance(updates[0], telegram.Update))
65+
66+
def testForwardMessage(self):
67+
'''Test the telegram.Bot forwardMessage method'''
68+
print('Testing forwardMessage')
69+
message = self._bot.forwardMessage(chat_id=self._chat_id,
70+
from_chat_id=self._chat_id,
71+
message_id=2398)
72+
73+
self.assertTrue(self.is_json(message.to_json()))
74+
self.assertEqual(message.text, 'teste')
75+
self.assertEqual(message.forward_from.username, 'leandrotoledo')
76+
self.assertTrue(isinstance(message.forward_date, datetime))
77+
78+
def testSendPhoto(self):
79+
'''Test the telegram.Bot sendPhoto method'''
80+
print('Testing sendPhoto - File')
81+
message = self._bot.sendPhoto(photo=open('tests/data/telegram.png', 'rb'),
82+
caption='testSendPhoto',
83+
chat_id=self._chat_id)
84+
85+
self.assertTrue(self.is_json(message.to_json()))
86+
self.assertEqual(message.photo[0].file_size, 1451)
87+
self.assertEqual(message.caption, 'testSendPhoto')
88+
89+
def testResendPhoto(self):
90+
'''Test the telegram.Bot sendPhoto method'''
91+
print('Testing sendPhoto - Resend')
92+
message = self._bot.sendPhoto(photo='AgADAQADyKcxGx8j9Qdp6d-gpUsw4Gja1i8ABEVJsVqQk8LfJ3wAAgI',
93+
chat_id=self._chat_id)
94+
95+
self.assertTrue(self.is_json(message.to_json()))
96+
self.assertEqual(message.photo[0].file_id, 'AgADAQADyKcxGx8j9Qdp6d-gpUsw4Gja1i8ABEVJsVqQk8LfJ3wAAgI')
97+
98+
def testSendJPGURLPhoto(self):
99+
'''Test the telegram.Bot sendPhoto method'''
100+
print('Testing testSendJPGURLPhoto - URL')
101+
message = self._bot.sendPhoto(photo='http://dummyimage.com/600x400/000/fff.jpg&text=telegram',
102+
chat_id=self._chat_id)
103+
104+
self.assertTrue(self.is_json(message.to_json()))
105+
self.assertEqual(message.photo[0].file_size, 822)
106+
107+
def testSendPNGURLPhoto(self):
108+
'''Test the telegram.Bot sendPhoto method'''
109+
print('Testing testSendPNGURLPhoto - URL')
110+
message = self._bot.sendPhoto(photo='http://dummyimage.com/600x400/000/fff.png&text=telegram',
111+
chat_id=self._chat_id)
112+
113+
self.assertTrue(self.is_json(message.to_json()))
114+
self.assertEqual(message.photo[0].file_size, 684)
115+
116+
def testSendGIFURLPhoto(self):
117+
'''Test the telegram.Bot sendPhoto method'''
118+
print('Testing testSendGIFURLPhoto - URL')
119+
message = self._bot.sendPhoto(photo='http://dummyimage.com/600x400/000/fff.gif&text=telegram',
120+
chat_id=self._chat_id)
121+
122+
self.assertTrue(self.is_json(message.to_json()))
123+
self.assertEqual(message.photo[0].file_size, 684)
124+
125+
def testSendChatAction(self):
126+
'''Test the telegram.Bot sendChatAction method'''
127+
print('Testing sendChatAction - ChatAction.TYPING')
128+
129+
self._bot.sendChatAction(action=telegram.ChatAction.TYPING,
130+
chat_id=self._chat_id)
131+
132+
def testGetUserProfilePhotos(self):
133+
'''Test the telegram.Bot getUserProfilePhotos method'''
134+
print('Testing getUserProfilePhotos')
135+
upf = self._bot.getUserProfilePhotos(user_id=self._chat_id)
136+
137+
self.assertTrue(self.is_json(upf.to_json()))
138+
self.assertEqual(upf.photos[0][0].file_size, 6547)
139+
140+
if __name__ == '__main__':
141+
unittest.main()

0 commit comments

Comments
 (0)