1717#
1818# You should have received a copy of the GNU General Public License
1919# along with this program. If not, see [http://www.gnu.org/licenses/].
20+
2021"""This module contains a object that represents Tests for Telegram Bot"""
2122
22- import sys
23- from datetime import datetime
2423import io
24+ from datetime import datetime
25+ import sys
2526
2627from flaky import flaky
2728
@@ -54,26 +55,22 @@ def testGetMe(self):
5455 @flaky (3 , 1 )
5556 @timeout (10 )
5657 def testSendMessage (self ):
57- message = self ._bot .sendMessage (
58- chat_id = self ._chat_id ,
59- text = 'Моё судно на воздушной подушке полно угрей' )
58+ message = self ._bot .sendMessage (chat_id = self ._chat_id ,
59+ text = 'Моё судно на воздушной подушке полно угрей' )
6060
6161 self .assertTrue (self .is_json (message .to_json ()))
62- self .assertEqual (message .text ,
63- u'Моё судно на воздушной подушке полно угрей' )
62+ self .assertEqual (message .text , u'Моё судно на воздушной подушке полно угрей' )
6463 self .assertTrue (isinstance (message .date , datetime ))
6564
6665 @flaky (3 , 1 )
6766 @timeout (10 )
6867 def testSilentSendMessage (self ):
69- message = self ._bot .sendMessage (
70- chat_id = self ._chat_id ,
71- text = 'Моё судно на воздушной подушке полно угрей' ,
72- disable_notification = True )
68+ message = self ._bot .sendMessage (chat_id = self ._chat_id ,
69+ text = 'Моё судно на воздушной подушке полно угрей' ,
70+ disable_notification = True )
7371
7472 self .assertTrue (self .is_json (message .to_json ()))
75- self .assertEqual (message .text ,
76- u'Моё судно на воздушной подушке полно угрей' )
73+ self .assertEqual (message .text , u'Моё судно на воздушной подушке полно угрей' )
7774 self .assertTrue (isinstance (message .date , datetime ))
7875
7976 @flaky (3 , 1 )
@@ -100,10 +97,9 @@ def testForwardMessage(self):
10097 @flaky (3 , 1 )
10198 @timeout (10 )
10299 def testSendPhoto (self ):
103- message = self ._bot .sendPhoto (
104- photo = open ('tests/data/telegram.png' , 'rb' ),
105- caption = 'testSendPhoto' ,
106- chat_id = self ._chat_id )
100+ message = self ._bot .sendPhoto (photo = open ('tests/data/telegram.png' , 'rb' ),
101+ caption = 'testSendPhoto' ,
102+ chat_id = self ._chat_id )
107103
108104 self .assertTrue (self .is_json (message .to_json ()))
109105 self .assertEqual (message .photo [0 ].file_size , 1451 )
@@ -112,11 +108,10 @@ def testSendPhoto(self):
112108 @flaky (3 , 1 )
113109 @timeout (10 )
114110 def testSilentSendPhoto (self ):
115- message = self ._bot .sendPhoto (
116- photo = open ('tests/data/telegram.png' , 'rb' ),
117- caption = 'testSendPhoto' ,
118- chat_id = self ._chat_id ,
119- disable_notification = True )
111+ message = self ._bot .sendPhoto (photo = open ('tests/data/telegram.png' , 'rb' ),
112+ caption = 'testSendPhoto' ,
113+ chat_id = self ._chat_id ,
114+ disable_notification = True )
120115
121116 self .assertTrue (self .is_json (message .to_json ()))
122117 self .assertEqual (message .photo [0 ].file_size , 1451 )
@@ -125,41 +120,35 @@ def testSilentSendPhoto(self):
125120 @flaky (3 , 1 )
126121 @timeout (10 )
127122 def testResendPhoto (self ):
128- message = self ._bot .sendPhoto (
129- photo = 'AgADAQADyKcxGx8j9Qdp6d-gpUsw4Gja1i8ABEVJsVqQk8LfJ3wAAgI' ,
130- chat_id = self ._chat_id )
123+ message = self ._bot .sendPhoto (photo = 'AgADAQADyKcxGx8j9Qdp6d-gpUsw4Gja1i8ABEVJsVqQk8LfJ3wAAgI' ,
124+ chat_id = self ._chat_id )
131125
132126 self .assertTrue (self .is_json (message .to_json ()))
133- self .assertEqual (
134- message .photo [0 ].file_id ,
135- 'AgADAQADyKcxGx8j9Qdp6d-gpUsw4Gja1i8ABEVJsVqQk8LfJ3wAAgI' )
127+ self .assertEqual (message .photo [0 ].file_id , 'AgADAQADyKcxGx8j9Qdp6d-gpUsw4Gja1i8ABEVJsVqQk8LfJ3wAAgI' )
136128
137129 @flaky (3 , 1 )
138130 @timeout (10 )
139131 def testSendJPGURLPhoto (self ):
140- message = self ._bot .sendPhoto (
141- photo = 'http://dummyimage.com/600x400/000/fff.jpg&text=telegram' ,
142- chat_id = self ._chat_id )
132+ message = self ._bot .sendPhoto (photo = 'http://dummyimage.com/600x400/000/fff.jpg&text=telegram' ,
133+ chat_id = self ._chat_id )
143134
144135 self .assertTrue (self .is_json (message .to_json ()))
145136 self .assertEqual (message .photo [0 ].file_size , 822 )
146137
147138 @flaky (3 , 1 )
148139 @timeout (10 )
149140 def testSendPNGURLPhoto (self ):
150- message = self ._bot .sendPhoto (
151- photo = 'http://dummyimage.com/600x400/000/fff.png&text=telegram' ,
152- chat_id = self ._chat_id )
141+ message = self ._bot .sendPhoto (photo = 'http://dummyimage.com/600x400/000/fff.png&text=telegram' ,
142+ chat_id = self ._chat_id )
153143
154144 self .assertTrue (self .is_json (message .to_json ()))
155145 self .assertEqual (message .photo [0 ].file_size , 684 )
156146
157147 @flaky (3 , 1 )
158148 @timeout (10 )
159149 def testSendGIFURLPhoto (self ):
160- message = self ._bot .sendPhoto (
161- photo = 'http://dummyimage.com/600x400/000/fff.gif&text=telegram' ,
162- chat_id = self ._chat_id )
150+ message = self ._bot .sendPhoto (photo = 'http://dummyimage.com/600x400/000/fff.gif&text=telegram' ,
151+ chat_id = self ._chat_id )
163152
164153 self .assertTrue (self .is_json (message .to_json ()))
165154 self .assertEqual (message .photo [0 ].file_size , 684 )
@@ -169,7 +158,8 @@ def testSendGIFURLPhoto(self):
169158 def testSendBufferedReaderPhoto (self ):
170159 photo = open ('tests/data/telegram.png' , 'rb' )
171160 br_photo = io .BufferedReader (io .BytesIO (photo .read ()))
172- message = self ._bot .sendPhoto (photo = br_photo , chat_id = self ._chat_id )
161+ message = self ._bot .sendPhoto (photo = br_photo ,
162+ chat_id = self ._chat_id )
173163
174164 self .assertTrue (self .is_json (message .to_json ()))
175165 self .assertEqual (message .photo [0 ].file_size , 1451 )
@@ -189,8 +179,7 @@ def testGetUserProfilePhotos(self):
189179 self .assertEqual (upf .photos [0 ][0 ].file_size , 12421 )
190180
191181 def _test_invalid_token (self , token ):
192- self .assertRaisesRegexp (telegram .error .InvalidToken , 'Invalid token' ,
193- telegram .Bot , token )
182+ self .assertRaisesRegexp (telegram .error .InvalidToken , 'Invalid token' , telegram .Bot , token )
194183
195184 def testInvalidToken1 (self ):
196185 self ._test_invalid_token ('123' )
@@ -202,14 +191,12 @@ def testInvalidToken3(self):
202191 self ._test_invalid_token ('12:' )
203192
204193 def testUnauthToken (self ):
205- with self .assertRaisesRegexp (telegram .error .Unauthorized ,
206- 'Unauthorized' ):
194+ with self .assertRaisesRegexp (telegram .error .Unauthorized , 'Unauthorized' ):
207195 bot = telegram .Bot ('1234:abcd1234' )
208196 bot .getMe ()
209197
210198 def testInvalidSrvResp (self ):
211- with self .assertRaisesRegexp (telegram .TelegramError ,
212- 'Invalid server response' ):
199+ with self .assertRaisesRegexp (telegram .TelegramError , 'Invalid server response' ):
213200 # bypass the valid token check
214201 bot = telegram .Bot .__new__ (telegram .Bot )
215202 bot .base_url = 'https://api.telegram.org/bot{0}' .format ('12' )
0 commit comments