예제 #1
0
 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)
예제 #2
0
 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)
예제 #3
0
 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)
예제 #4
0
 def testGetInfo(self):
     bot = TelegramBot(self.token)
     info = bot.getInfo()
     self.assertTrue(info.id)
     self.assertTrue(info.username)
     self.assertTrue(info.first_name)
예제 #5
0
 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()