def testSendMessage(self): bot = TelegramBot('FAKE-TOKEN') params = { 'chat_id': 'a', 'text': 'b'} bot.telegramBot = Mock() bot.telegramBot.sendMessage = Mock() self.assertIsNone(bot.sendMessage(**params)) bot.telegramBot.sendMessage.assert_called_once_with(**params)
def testGetInfo(self): bot = TelegramBot('FAKE-TOKEN') info = Mock() bot.telegramBot = Mock() bot.telegramBot.getMe = Mock(return_value=info) infoResult = bot.getInfo() self.assertEqual(infoResult, info)
def testSendAudio(self): bot = TelegramBot('FAKE-TOKEN') params = { 'chat_id': 'a', 'audio': 'b'} with patch('requests.post') as mockRequestPost, patch('__builtin__.open') as mockOpen: mockRequestPost.return_value = None self.assertIsNone(bot.sendAudio(**params)) mockOpen.assert_called_once_with('b', 'rb') self.assertEqual(mockRequestPost.call_count, 1)
def testGetInfo(self): bot = TelegramBot(self.token) info = bot.getInfo() self.assertTrue(info.id) self.assertTrue(info.username) self.assertTrue(info.first_name)
def testListen(self): bot = TelegramBot('FAKE-TOKEN') bot.updater = Mock() bot.updater.start_polling = Mock() bot.listen() bot.updater.start_polling.assert_called_once_with()