def test__send_text_message_shoul_call_sendMessage_api_correctly_with_keyboard( self): tcb = TelegramController() tcb.post_worker = MagicMock() tcb.TOKEN = "banana" tcb.CHAT_ID = "to_banana" tcb._send_http = MagicMock() tcb._send_text_message("hello~ banana", "banana_keyboard_markup") tcb.post_worker.post_task.assert_called_once_with(ANY) task = tcb.post_worker.post_task.call_args[0][0] tcb.post_worker.post_task.call_args[0][0]["runnable"](task) tcb._send_http.assert_called_once_with( "https://api.telegram.org/banana/sendMessage?chat_id=to_banana&text=hello%7E%20banana&reply_markup=banana_keyboard_markup" )
def test__terminate_should_set_terminating_flag_True(self): tcb = TelegramController() tcb.post_worker = MagicMock() tcb._terminate() self.assertEqual(tcb.terminating, True) tcb.post_worker.stop.assert_called_once()