def test__get_updates_call_getUpdates_api_correctly(self): tcb = TelegramController() tcb.TOKEN = "banana" expected_response = "banana_result" tcb._send_http = MagicMock(return_value=expected_response) updates = tcb._get_updates() self.assertEqual(updates, expected_response) tcb._send_http.assert_called_once_with( "https://api.telegram.org/banana/getUpdates?offset=1&timeout=10")
def test__send_text_message_shoul_call_sendMessage_api_correctly(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") 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" )