add tests for Bot.getChat*

This commit is contained in:
Rahiel Kasim 2016-05-25 01:31:10 +02:00
parent 7e0be09c58
commit 76b9a7d328
2 changed files with 48 additions and 0 deletions

View file

@ -40,6 +40,8 @@ class BaseTest(object):
'133505823:AAHZFMHno3mzVLErU5b5jJvaeG--qUyLyG0'))
chat_id = os.environ.get('CHAT_ID', '12173560')
self._group_id = os.environ.get('GROUP_ID', '-49740850')
self._channel_id = os.environ.get('CHANNEL_ID', '@pythontelegrambottests')
self._bot = bot
self._chat_id = chat_id

View file

@ -205,6 +205,52 @@ class BotTest(BaseTest, unittest.TestCase):
bot.getMe()
@flaky(3, 1)
@timeout(10)
def testGetChat(self):
chat = self._bot.getChat(self._group_id)
self.assertTrue(self.is_json(chat.to_json()))
self.assertEqual(chat.type, "group")
self.assertEqual(chat.title, ">>> telegram.Bot() - Developers")
self.assertEqual(chat.id, int(self._group_id))
@flaky(3, 1)
@timeout(10)
def testGetChatAdministrators(self):
admins = self._bot.getChatAdministrators(self._channel_id)
self.assertTrue(isinstance(admins, list))
self.assertTrue(self.is_json(admins[0].to_json()))
for a in admins:
self.assertTrue(a.status in ("administrator", "creator"))
bot = [a.user for a in admins if a.user.id == 133505823][0]
self.assertEqual(bot.first_name, 'PythonTelegramBot')
self.assertEqual(bot.last_name, '')
self.assertEqual(bot.username, 'PythonTelegramBot')
self.assertEqual(bot.name, '@PythonTelegramBot')
@flaky(3, 1)
@timeout(10)
def testGetChatMembersCount(self):
count = self._bot.getChatMembersCount(self._channel_id)
self.assertTrue(isinstance(count, int))
self.assertTrue(count > 3)
@flaky(3, 1)
@timeout(10)
def testGetChatMember(self):
chat_member = self._bot.getChatMember(self._channel_id, 133505823)
bot = chat_member.user
self.assertTrue(self.is_json(chat_member.to_json()))
self.assertEqual(chat_member.status, "administrator")
self.assertEqual(bot.id, 133505823)
self.assertEqual(bot.first_name, 'PythonTelegramBot')
self.assertEqual(bot.last_name, '')
self.assertEqual(bot.username, 'PythonTelegramBot')
self.assertEqual(bot.name, '@PythonTelegramBot')
if __name__ == '__main__':
unittest.main()