mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-11-21 22:56:38 +01:00
add tests for Bot.getChat*
This commit is contained in:
parent
7e0be09c58
commit
76b9a7d328
2 changed files with 48 additions and 0 deletions
|
@ -40,6 +40,8 @@ class BaseTest(object):
|
||||||
'133505823:AAHZFMHno3mzVLErU5b5jJvaeG--qUyLyG0'))
|
'133505823:AAHZFMHno3mzVLErU5b5jJvaeG--qUyLyG0'))
|
||||||
chat_id = os.environ.get('CHAT_ID', '12173560')
|
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._bot = bot
|
||||||
self._chat_id = chat_id
|
self._chat_id = chat_id
|
||||||
|
|
||||||
|
|
|
@ -205,6 +205,52 @@ class BotTest(BaseTest, unittest.TestCase):
|
||||||
|
|
||||||
bot.getMe()
|
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__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
Loading…
Reference in a new issue