2020
2121"""This module contains a object that represents Tests for Telegram Bot"""
2222
23- import io
24- import os
25- from datetime import datetime
2623import sys
24+ from datetime import datetime
25+
26+ import io
2727from flaky import flaky
2828
2929if sys .version_info [0 :2 ] == (2 , 6 ):
@@ -59,7 +59,8 @@ def testSendMessage(self):
5959 text = 'Моё судно на воздушной подушке полно угрей' )
6060
6161 self .assertTrue (self .is_json (message .to_json ()))
62- self .assertEqual (message .text , u'Моё судно на воздушной подушке полно угрей' )
62+ self .assertEqual (message .text ,
63+ u'Моё судно на воздушной подушке полно угрей' )
6364 self .assertTrue (isinstance (message .date , datetime ))
6465
6566 @flaky (3 , 1 )
@@ -70,7 +71,8 @@ def testSilentSendMessage(self):
7071 disable_notification = True )
7172
7273 self .assertTrue (self .is_json (message .to_json ()))
73- self .assertEqual (message .text , u'Моё судно на воздушной подушке полно угрей' )
74+ self .assertEqual (message .text ,
75+ u'Моё судно на воздушной подушке полно угрей' )
7476 self .assertTrue (isinstance (message .date , datetime ))
7577
7678 @flaky (3 , 1 )
@@ -97,9 +99,10 @@ def testForwardMessage(self):
9799 @flaky (3 , 1 )
98100 @timeout (10 )
99101 def testSendPhoto (self ):
100- message = self ._bot .sendPhoto (photo = open ('tests/data/telegram.png' , 'rb' ),
101- caption = 'testSendPhoto' ,
102- chat_id = self ._chat_id )
102+ message = self ._bot .sendPhoto (
103+ photo = open ('tests/data/telegram.png' , 'rb' ),
104+ caption = 'testSendPhoto' ,
105+ chat_id = self ._chat_id )
103106
104107 self .assertTrue (self .is_json (message .to_json ()))
105108 self .assertEqual (message .photo [0 ].file_size , 1451 )
@@ -108,10 +111,11 @@ def testSendPhoto(self):
108111 @flaky (3 , 1 )
109112 @timeout (10 )
110113 def testSilentSendPhoto (self ):
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 )
114+ message = self ._bot .sendPhoto (
115+ photo = open ('tests/data/telegram.png' , 'rb' ),
116+ caption = 'testSendPhoto' ,
117+ chat_id = self ._chat_id ,
118+ disable_notification = True )
115119
116120 self .assertTrue (self .is_json (message .to_json ()))
117121 self .assertEqual (message .photo [0 ].file_size , 1451 )
@@ -120,35 +124,40 @@ def testSilentSendPhoto(self):
120124 @flaky (3 , 1 )
121125 @timeout (10 )
122126 def testResendPhoto (self ):
123- message = self ._bot .sendPhoto (photo = 'AgADAQADyKcxGx8j9Qdp6d-gpUsw4Gja1i8ABEVJsVqQk8LfJ3wAAgI' ,
124- chat_id = self ._chat_id )
127+ message = self ._bot .sendPhoto (
128+ photo = 'AgADAQADyKcxGx8j9Qdp6d-gpUsw4Gja1i8ABEVJsVqQk8LfJ3wAAgI' ,
129+ chat_id = self ._chat_id )
125130
126131 self .assertTrue (self .is_json (message .to_json ()))
127- self .assertEqual (message .photo [0 ].file_id , 'AgADAQADyKcxGx8j9Qdp6d-gpUsw4Gja1i8ABEVJsVqQk8LfJ3wAAgI' )
132+ self .assertEqual (message .photo [0 ].file_id ,
133+ 'AgADAQADyKcxGx8j9Qdp6d-gpUsw4Gja1i8ABEVJsVqQk8LfJ3wAAgI' )
128134
129135 @flaky (3 , 1 )
130136 @timeout (10 )
131137 def testSendJPGURLPhoto (self ):
132- message = self ._bot .sendPhoto (photo = 'http://dummyimage.com/600x400/000/fff.jpg&text=telegram' ,
133- chat_id = self ._chat_id )
138+ message = self ._bot .sendPhoto (
139+ photo = 'http://dummyimage.com/600x400/000/fff.jpg&text=telegram' ,
140+ chat_id = self ._chat_id )
134141
135142 self .assertTrue (self .is_json (message .to_json ()))
136143 self .assertEqual (message .photo [0 ].file_size , 822 )
137144
138145 @flaky (3 , 1 )
139146 @timeout (10 )
140147 def testSendPNGURLPhoto (self ):
141- message = self ._bot .sendPhoto (photo = 'http://dummyimage.com/600x400/000/fff.png&text=telegram' ,
142- chat_id = self ._chat_id )
148+ message = self ._bot .sendPhoto (
149+ photo = 'http://dummyimage.com/600x400/000/fff.png&text=telegram' ,
150+ chat_id = self ._chat_id )
143151
144152 self .assertTrue (self .is_json (message .to_json ()))
145153 self .assertEqual (message .photo [0 ].file_size , 684 )
146154
147155 @flaky (3 , 1 )
148156 @timeout (10 )
149157 def testSendGIFURLPhoto (self ):
150- message = self ._bot .sendPhoto (photo = 'http://dummyimage.com/600x400/000/fff.gif&text=telegram' ,
151- chat_id = self ._chat_id )
158+ message = self ._bot .sendPhoto (
159+ photo = 'http://dummyimage.com/600x400/000/fff.gif&text=telegram' ,
160+ chat_id = self ._chat_id )
152161
153162 self .assertTrue (self .is_json (message .to_json ()))
154163 self .assertEqual (message .photo [0 ].file_size , 684 )
@@ -179,7 +188,8 @@ def testGetUserProfilePhotos(self):
179188 self .assertEqual (upf .photos [0 ][0 ].file_size , 12421 )
180189
181190 def _test_invalid_token (self , token ):
182- self .assertRaisesRegexp (telegram .error .InvalidToken , 'Invalid token' , telegram .Bot , token )
191+ self .assertRaisesRegexp (telegram .error .InvalidToken , 'Invalid token' ,
192+ telegram .Bot , token )
183193
184194 def testInvalidToken1 (self ):
185195 self ._test_invalid_token ('123' )
@@ -191,12 +201,14 @@ def testInvalidToken3(self):
191201 self ._test_invalid_token ('12:' )
192202
193203 def testUnauthToken (self ):
194- with self .assertRaisesRegexp (telegram .error .Unauthorized , 'Unauthorized' ):
204+ with self .assertRaisesRegexp (telegram .error .Unauthorized ,
205+ 'Unauthorized' ):
195206 bot = telegram .Bot ('1234:abcd1234' )
196207 bot .getMe ()
197208
198209 def testInvalidSrvResp (self ):
199- with self .assertRaisesRegexp (telegram .TelegramError , 'Invalid server response' ):
210+ with self .assertRaisesRegexp (telegram .TelegramError ,
211+ 'Invalid server response' ):
200212 # bypass the valid token check
201213 bot = telegram .Bot .__new__ (telegram .Bot )
202214 bot .base_url = 'https://api.telegram.org/bot{0}' .format ('12' )
0 commit comments