def test_Client_call_api_existing_thread(): """ The client will ignore attempt to call API if an existing request is in progress. """ mock_gui = mock.MagicMock() mock_session = mock.MagicMock() cl = Client('http://localhost', mock_gui, mock_session) cl.api_thread = True cl.call_api(mock.MagicMock(), mock.MagicMock(), mock.MagicMock()) assert cl.api_thread is True
def test_Client_call_reset_no_thread(): """ The client will ignore an attempt to reset an API call is there's no such call "in flight". """ mock_gui = mock.MagicMock() mock_session = mock.MagicMock() cl = Client('http://localhost', mock_gui, mock_session) cl.finish_api_call = mock.MagicMock() cl.api_thread = None cl.call_reset() assert cl.finish_api_call.emit.call_count == 0
def test_Client_call_reset(): """ Call reset emits the expected signal and resets the state of client attributes. """ mock_gui = mock.MagicMock() mock_session = mock.MagicMock() cl = Client('http://localhost', mock_gui, mock_session) cl.finish_api_call = mock.MagicMock() cl.api_thread = True cl.call_reset() assert cl.finish_api_call.emit.call_count == 1 assert cl.api_runner is None assert cl.api_thread is None
def test_Client_call_reset(safe_tmpdir): """ Call reset emits the expected signal and resets the state of client attributes. """ mock_gui = mock.MagicMock() mock_session = mock.MagicMock() cl = Client('http://localhost', mock_gui, mock_session, str(safe_tmpdir)) cl.timeout_api_call = mock.MagicMock() cl.api_thread = True cl.call_reset() assert cl.timeout_api_call.disconnect.call_count == 1 assert cl.api_runner is None assert cl.api_thread is None assert cl.timer is None
def test_Client_timeout_cleanup_with_current_object(safe_tmpdir): """ Ensure that cleanup is performed if an API call times out. """ mock_gui = mock.MagicMock() mock_session = mock.MagicMock() cl = Client('http://localhost', mock_gui, mock_session, str(safe_tmpdir)) cl.api_thread = mock.MagicMock() cl.api_runner = mock.MagicMock() cl.api_runner.current_object = mock.MagicMock() cl.call_reset = mock.MagicMock() mock_user_callback = mock.MagicMock() cl.timeout_cleanup(mock_user_callback) assert cl.api_runner.i_timed_out is True cl.call_reset.assert_called_once_with() mock_user_callback.call_count == 1
def test_Client_completed_api_call_with_current_object(safe_tmpdir): """ Ensure that cleanup is performed if an API call returns in the expected time. """ mock_gui = mock.MagicMock() mock_session = mock.MagicMock() cl = Client('http://localhost', mock_gui, mock_session, str(safe_tmpdir)) cl.timer = mock.MagicMock() cl.api_thread = mock.MagicMock() cl.api_runner = mock.MagicMock() cl.api_runner.current_object = mock.MagicMock() cl.call_reset = mock.MagicMock() mock_user_callback = mock.MagicMock() cl.result = mock.MagicMock() cl.completed_api_call(mock_user_callback) cl.call_reset.assert_called_once_with() mock_user_callback.call_count == 1 cl.timer.stop.assert_called_once_with()