mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-12-22 22:45:09 +01:00
First run of yapf for tests/* #259
This commit is contained in:
parent
56b1d4f5ce
commit
8ad1f330ea
9 changed files with 60 additions and 51 deletions
|
@ -3,4 +3,5 @@ nose
|
||||||
pep257
|
pep257
|
||||||
pylint
|
pylint
|
||||||
unittest2
|
unittest2
|
||||||
flaky
|
flaky
|
||||||
|
yapf
|
||||||
|
|
|
@ -16,7 +16,6 @@
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||||
|
|
||||||
"""This module contains a object that represents a Base class for tests"""
|
"""This module contains a object that represents a Base class for tests"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
@ -62,7 +61,6 @@ class BaseTest(object):
|
||||||
|
|
||||||
|
|
||||||
class TestTimedOut(AssertionError):
|
class TestTimedOut(AssertionError):
|
||||||
|
|
||||||
def __init__(self, time_limit, frame):
|
def __init__(self, time_limit, frame):
|
||||||
super(TestTimedOut, self).__init__('time_limit={0}'.format(time_limit))
|
super(TestTimedOut, self).__init__('time_limit={0}'.format(time_limit))
|
||||||
self.time_limit = time_limit
|
self.time_limit = time_limit
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||||
|
|
||||||
"""This module contains a object that represents Tests for Telegram Bot"""
|
"""This module contains a object that represents Tests for Telegram Bot"""
|
||||||
|
|
||||||
import io
|
import io
|
||||||
|
@ -55,22 +54,26 @@ class BotTest(BaseTest, unittest.TestCase):
|
||||||
@flaky(3, 1)
|
@flaky(3, 1)
|
||||||
@timeout(10)
|
@timeout(10)
|
||||||
def testSendMessage(self):
|
def testSendMessage(self):
|
||||||
message = self._bot.sendMessage(chat_id=self._chat_id,
|
message = self._bot.sendMessage(
|
||||||
text='Моё судно на воздушной подушке полно угрей')
|
chat_id=self._chat_id,
|
||||||
|
text='Моё судно на воздушной подушке полно угрей')
|
||||||
|
|
||||||
self.assertTrue(self.is_json(message.to_json()))
|
self.assertTrue(self.is_json(message.to_json()))
|
||||||
self.assertEqual(message.text, u'Моё судно на воздушной подушке полно угрей')
|
self.assertEqual(message.text,
|
||||||
|
u'Моё судно на воздушной подушке полно угрей')
|
||||||
self.assertTrue(isinstance(message.date, datetime))
|
self.assertTrue(isinstance(message.date, datetime))
|
||||||
|
|
||||||
@flaky(3, 1)
|
@flaky(3, 1)
|
||||||
@timeout(10)
|
@timeout(10)
|
||||||
def testSilentSendMessage(self):
|
def testSilentSendMessage(self):
|
||||||
message = self._bot.sendMessage(chat_id=self._chat_id,
|
message = self._bot.sendMessage(
|
||||||
text='Моё судно на воздушной подушке полно угрей',
|
chat_id=self._chat_id,
|
||||||
disable_notification=True)
|
text='Моё судно на воздушной подушке полно угрей',
|
||||||
|
disable_notification=True)
|
||||||
|
|
||||||
self.assertTrue(self.is_json(message.to_json()))
|
self.assertTrue(self.is_json(message.to_json()))
|
||||||
self.assertEqual(message.text, u'Моё судно на воздушной подушке полно угрей')
|
self.assertEqual(message.text,
|
||||||
|
u'Моё судно на воздушной подушке полно угрей')
|
||||||
self.assertTrue(isinstance(message.date, datetime))
|
self.assertTrue(isinstance(message.date, datetime))
|
||||||
|
|
||||||
@flaky(3, 1)
|
@flaky(3, 1)
|
||||||
|
@ -97,9 +100,10 @@ class BotTest(BaseTest, unittest.TestCase):
|
||||||
@flaky(3, 1)
|
@flaky(3, 1)
|
||||||
@timeout(10)
|
@timeout(10)
|
||||||
def testSendPhoto(self):
|
def testSendPhoto(self):
|
||||||
message = self._bot.sendPhoto(photo=open('tests/data/telegram.png', 'rb'),
|
message = self._bot.sendPhoto(
|
||||||
caption='testSendPhoto',
|
photo=open('tests/data/telegram.png', 'rb'),
|
||||||
chat_id=self._chat_id)
|
caption='testSendPhoto',
|
||||||
|
chat_id=self._chat_id)
|
||||||
|
|
||||||
self.assertTrue(self.is_json(message.to_json()))
|
self.assertTrue(self.is_json(message.to_json()))
|
||||||
self.assertEqual(message.photo[0].file_size, 1451)
|
self.assertEqual(message.photo[0].file_size, 1451)
|
||||||
|
@ -108,10 +112,11 @@ class BotTest(BaseTest, unittest.TestCase):
|
||||||
@flaky(3, 1)
|
@flaky(3, 1)
|
||||||
@timeout(10)
|
@timeout(10)
|
||||||
def testSilentSendPhoto(self):
|
def testSilentSendPhoto(self):
|
||||||
message = self._bot.sendPhoto(photo=open('tests/data/telegram.png', 'rb'),
|
message = self._bot.sendPhoto(
|
||||||
caption='testSendPhoto',
|
photo=open('tests/data/telegram.png', 'rb'),
|
||||||
chat_id=self._chat_id,
|
caption='testSendPhoto',
|
||||||
disable_notification=True)
|
chat_id=self._chat_id,
|
||||||
|
disable_notification=True)
|
||||||
|
|
||||||
self.assertTrue(self.is_json(message.to_json()))
|
self.assertTrue(self.is_json(message.to_json()))
|
||||||
self.assertEqual(message.photo[0].file_size, 1451)
|
self.assertEqual(message.photo[0].file_size, 1451)
|
||||||
|
@ -120,17 +125,21 @@ class BotTest(BaseTest, unittest.TestCase):
|
||||||
@flaky(3, 1)
|
@flaky(3, 1)
|
||||||
@timeout(10)
|
@timeout(10)
|
||||||
def testResendPhoto(self):
|
def testResendPhoto(self):
|
||||||
message = self._bot.sendPhoto(photo='AgADAQADyKcxGx8j9Qdp6d-gpUsw4Gja1i8ABEVJsVqQk8LfJ3wAAgI',
|
message = self._bot.sendPhoto(
|
||||||
chat_id=self._chat_id)
|
photo='AgADAQADyKcxGx8j9Qdp6d-gpUsw4Gja1i8ABEVJsVqQk8LfJ3wAAgI',
|
||||||
|
chat_id=self._chat_id)
|
||||||
|
|
||||||
self.assertTrue(self.is_json(message.to_json()))
|
self.assertTrue(self.is_json(message.to_json()))
|
||||||
self.assertEqual(message.photo[0].file_id, 'AgADAQADyKcxGx8j9Qdp6d-gpUsw4Gja1i8ABEVJsVqQk8LfJ3wAAgI')
|
self.assertEqual(
|
||||||
|
message.photo[0].file_id,
|
||||||
|
'AgADAQADyKcxGx8j9Qdp6d-gpUsw4Gja1i8ABEVJsVqQk8LfJ3wAAgI')
|
||||||
|
|
||||||
@flaky(3, 1)
|
@flaky(3, 1)
|
||||||
@timeout(10)
|
@timeout(10)
|
||||||
def testSendJPGURLPhoto(self):
|
def testSendJPGURLPhoto(self):
|
||||||
message = self._bot.sendPhoto(photo='http://dummyimage.com/600x400/000/fff.jpg&text=telegram',
|
message = self._bot.sendPhoto(
|
||||||
chat_id=self._chat_id)
|
photo='http://dummyimage.com/600x400/000/fff.jpg&text=telegram',
|
||||||
|
chat_id=self._chat_id)
|
||||||
|
|
||||||
self.assertTrue(self.is_json(message.to_json()))
|
self.assertTrue(self.is_json(message.to_json()))
|
||||||
self.assertEqual(message.photo[0].file_size, 822)
|
self.assertEqual(message.photo[0].file_size, 822)
|
||||||
|
@ -138,8 +147,9 @@ class BotTest(BaseTest, unittest.TestCase):
|
||||||
@flaky(3, 1)
|
@flaky(3, 1)
|
||||||
@timeout(10)
|
@timeout(10)
|
||||||
def testSendPNGURLPhoto(self):
|
def testSendPNGURLPhoto(self):
|
||||||
message = self._bot.sendPhoto(photo='http://dummyimage.com/600x400/000/fff.png&text=telegram',
|
message = self._bot.sendPhoto(
|
||||||
chat_id=self._chat_id)
|
photo='http://dummyimage.com/600x400/000/fff.png&text=telegram',
|
||||||
|
chat_id=self._chat_id)
|
||||||
|
|
||||||
self.assertTrue(self.is_json(message.to_json()))
|
self.assertTrue(self.is_json(message.to_json()))
|
||||||
self.assertEqual(message.photo[0].file_size, 684)
|
self.assertEqual(message.photo[0].file_size, 684)
|
||||||
|
@ -147,8 +157,9 @@ class BotTest(BaseTest, unittest.TestCase):
|
||||||
@flaky(3, 1)
|
@flaky(3, 1)
|
||||||
@timeout(10)
|
@timeout(10)
|
||||||
def testSendGIFURLPhoto(self):
|
def testSendGIFURLPhoto(self):
|
||||||
message = self._bot.sendPhoto(photo='http://dummyimage.com/600x400/000/fff.gif&text=telegram',
|
message = self._bot.sendPhoto(
|
||||||
chat_id=self._chat_id)
|
photo='http://dummyimage.com/600x400/000/fff.gif&text=telegram',
|
||||||
|
chat_id=self._chat_id)
|
||||||
|
|
||||||
self.assertTrue(self.is_json(message.to_json()))
|
self.assertTrue(self.is_json(message.to_json()))
|
||||||
self.assertEqual(message.photo[0].file_size, 684)
|
self.assertEqual(message.photo[0].file_size, 684)
|
||||||
|
@ -158,8 +169,7 @@ class BotTest(BaseTest, unittest.TestCase):
|
||||||
def testSendBufferedReaderPhoto(self):
|
def testSendBufferedReaderPhoto(self):
|
||||||
photo = open('tests/data/telegram.png', 'rb')
|
photo = open('tests/data/telegram.png', 'rb')
|
||||||
br_photo = io.BufferedReader(io.BytesIO(photo.read()))
|
br_photo = io.BufferedReader(io.BytesIO(photo.read()))
|
||||||
message = self._bot.sendPhoto(photo=br_photo,
|
message = self._bot.sendPhoto(photo=br_photo, chat_id=self._chat_id)
|
||||||
chat_id=self._chat_id)
|
|
||||||
|
|
||||||
self.assertTrue(self.is_json(message.to_json()))
|
self.assertTrue(self.is_json(message.to_json()))
|
||||||
self.assertEqual(message.photo[0].file_size, 1451)
|
self.assertEqual(message.photo[0].file_size, 1451)
|
||||||
|
@ -179,7 +189,8 @@ class BotTest(BaseTest, unittest.TestCase):
|
||||||
self.assertEqual(upf.photos[0][0].file_size, 12421)
|
self.assertEqual(upf.photos[0][0].file_size, 12421)
|
||||||
|
|
||||||
def _test_invalid_token(self, token):
|
def _test_invalid_token(self, token):
|
||||||
self.assertRaisesRegexp(telegram.error.InvalidToken, 'Invalid token', telegram.Bot, token)
|
self.assertRaisesRegexp(telegram.error.InvalidToken, 'Invalid token',
|
||||||
|
telegram.Bot, token)
|
||||||
|
|
||||||
def testInvalidToken1(self):
|
def testInvalidToken1(self):
|
||||||
self._test_invalid_token('123')
|
self._test_invalid_token('123')
|
||||||
|
@ -191,12 +202,14 @@ class BotTest(BaseTest, unittest.TestCase):
|
||||||
self._test_invalid_token('12:')
|
self._test_invalid_token('12:')
|
||||||
|
|
||||||
def testUnauthToken(self):
|
def testUnauthToken(self):
|
||||||
with self.assertRaisesRegexp(telegram.error.Unauthorized, 'Unauthorized'):
|
with self.assertRaisesRegexp(telegram.error.Unauthorized,
|
||||||
|
'Unauthorized'):
|
||||||
bot = telegram.Bot('1234:abcd1234')
|
bot = telegram.Bot('1234:abcd1234')
|
||||||
bot.getMe()
|
bot.getMe()
|
||||||
|
|
||||||
def testInvalidSrvResp(self):
|
def testInvalidSrvResp(self):
|
||||||
with self.assertRaisesRegexp(telegram.TelegramError, 'Invalid server response'):
|
with self.assertRaisesRegexp(telegram.TelegramError,
|
||||||
|
'Invalid server response'):
|
||||||
# bypass the valid token check
|
# bypass the valid token check
|
||||||
bot = telegram.Bot.__new__(telegram.Bot)
|
bot = telegram.Bot.__new__(telegram.Bot)
|
||||||
bot.base_url = 'https://api.telegram.org/bot{0}'.format('12')
|
bot.base_url = 'https://api.telegram.org/bot{0}'.format('12')
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
#
|
#
|
||||||
# A library that provides a Python interface to the Telegram Bot API
|
# A library that provides a Python interface to the Telegram Bot API
|
||||||
# Copyright (C) 2015-2016
|
# Copyright (C) 2015-2016
|
||||||
|
@ -16,7 +16,6 @@
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||||
|
|
||||||
"""This module contains a object that represents Tests for Telegram Chat"""
|
"""This module contains a object that represents Tests for Telegram Chat"""
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
@ -66,5 +65,6 @@ class ChatTest(BaseTest, unittest.TestCase):
|
||||||
self.assertEqual(group_chat['title'], self.title)
|
self.assertEqual(group_chat['title'], self.title)
|
||||||
self.assertEqual(group_chat['type'], self.type)
|
self.assertEqual(group_chat['type'], self.type)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
#
|
#
|
||||||
# A library that provides a Python interface to the Telegram Bot API
|
# A library that provides a Python interface to the Telegram Bot API
|
||||||
# Copyright (C) 2015-2016
|
# Copyright (C) 2015-2016
|
||||||
|
@ -16,7 +16,6 @@
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||||
|
|
||||||
"""This module contains a object that represents Tests for Telegram Contact"""
|
"""This module contains a object that represents Tests for Telegram Contact"""
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
@ -65,5 +64,6 @@ class ContactTest(BaseTest, unittest.TestCase):
|
||||||
self.assertEqual(contact['last_name'], self.last_name)
|
self.assertEqual(contact['last_name'], self.last_name)
|
||||||
self.assertEqual(contact['user_id'], self.user_id)
|
self.assertEqual(contact['user_id'], self.user_id)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -16,7 +16,6 @@
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||||
|
|
||||||
"""This module contains a object that represents Tests for Telegram Emoji"""
|
"""This module contains a object that represents Tests for Telegram Emoji"""
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
|
@ -16,7 +16,6 @@
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||||
|
|
||||||
"""This module contains a object that represents Tests for Telegram Location"""
|
"""This module contains a object that represents Tests for Telegram Location"""
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
@ -40,8 +39,7 @@ class LocationTest(BaseTest, unittest.TestCase):
|
||||||
}
|
}
|
||||||
|
|
||||||
def test_send_location_implicit_args(self):
|
def test_send_location_implicit_args(self):
|
||||||
message = self._bot.sendLocation(self._chat_id,
|
message = self._bot.sendLocation(self._chat_id, self.latitude,
|
||||||
self.latitude,
|
|
||||||
self.longitude)
|
self.longitude)
|
||||||
|
|
||||||
location = message.location
|
location = message.location
|
||||||
|
|
|
@ -499,8 +499,8 @@ class UpdaterTest(BaseTest, unittest.TestCase):
|
||||||
bootstrap_retries=retries,
|
bootstrap_retries=retries,
|
||||||
bootstrap_err=Unauthorized())
|
bootstrap_err=Unauthorized())
|
||||||
|
|
||||||
self.assertRaises(Unauthorized, self.updater._bootstrap,
|
self.assertRaises(Unauthorized, self.updater._bootstrap, retries,
|
||||||
retries, False, 'path', None)
|
False, 'path', None)
|
||||||
self.assertEqual(self.updater.bot.bootstrap_attempts, 1)
|
self.assertEqual(self.updater.bot.bootstrap_attempts, 1)
|
||||||
|
|
||||||
def test_bootstrap_retries_invalid_token(self):
|
def test_bootstrap_retries_invalid_token(self):
|
||||||
|
@ -510,8 +510,8 @@ class UpdaterTest(BaseTest, unittest.TestCase):
|
||||||
bootstrap_retries=retries,
|
bootstrap_retries=retries,
|
||||||
bootstrap_err=InvalidToken())
|
bootstrap_err=InvalidToken())
|
||||||
|
|
||||||
self.assertRaises(InvalidToken, self.updater._bootstrap,
|
self.assertRaises(InvalidToken, self.updater._bootstrap, retries,
|
||||||
retries, False, 'path', None)
|
False, 'path', None)
|
||||||
self.assertEqual(self.updater.bot.bootstrap_attempts, 1)
|
self.assertEqual(self.updater.bot.bootstrap_attempts, 1)
|
||||||
|
|
||||||
def test_bootstrap_retries_fail(self):
|
def test_bootstrap_retries_fail(self):
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
#
|
#
|
||||||
# A library that provides a Python interface to the Telegram Bot API
|
# A library that provides a Python interface to the Telegram Bot API
|
||||||
# Copyright (C) 2015-2016
|
# Copyright (C) 2015-2016
|
||||||
|
@ -16,7 +16,6 @@
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||||
|
|
||||||
"""This module contains a object that represents Tests for Telegram User"""
|
"""This module contains a object that represents Tests for Telegram User"""
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
@ -59,7 +58,7 @@ class UserTest(BaseTest, unittest.TestCase):
|
||||||
def test_user_de_json_without_username(self):
|
def test_user_de_json_without_username(self):
|
||||||
json_dict = self.json_dict
|
json_dict = self.json_dict
|
||||||
|
|
||||||
del(json_dict['username'])
|
del (json_dict['username'])
|
||||||
|
|
||||||
user = telegram.User.de_json(self.json_dict)
|
user = telegram.User.de_json(self.json_dict)
|
||||||
|
|
||||||
|
@ -68,14 +67,14 @@ class UserTest(BaseTest, unittest.TestCase):
|
||||||
self.assertEqual(user.last_name, self.last_name)
|
self.assertEqual(user.last_name, self.last_name)
|
||||||
self.assertEqual(user.type, self.type)
|
self.assertEqual(user.type, self.type)
|
||||||
|
|
||||||
self.assertEqual(user.name, '%s %s' % (self.first_name, self.last_name))
|
self.assertEqual(user.name, '%s %s' %
|
||||||
|
(self.first_name, self.last_name))
|
||||||
|
|
||||||
def test_user_de_json_without_username_and_lastname(self):
|
def test_user_de_json_without_username_and_lastname(self):
|
||||||
json_dict = self.json_dict
|
json_dict = self.json_dict
|
||||||
|
|
||||||
del(json_dict['username'])
|
del (json_dict['username'])
|
||||||
del(json_dict['last_name'])
|
del (json_dict['last_name'])
|
||||||
|
|
||||||
user = telegram.User.de_json(self.json_dict)
|
user = telegram.User.de_json(self.json_dict)
|
||||||
|
|
||||||
|
@ -99,5 +98,6 @@ class UserTest(BaseTest, unittest.TestCase):
|
||||||
self.assertEqual(user['username'], self.username)
|
self.assertEqual(user['username'], self.username)
|
||||||
self.assertEqual(user['type'], self.type)
|
self.assertEqual(user['type'], self.type)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
Loading…
Reference in a new issue