def test_Client_completed_api_call_without_current_object(
        homedir, config, mocker):
    """
    Ensure that cleanup is performed if an API call returns in the expected
    time.
    Using the `config` fixture to ensure the config is written to disk.
    """
    mock_gui = mocker.MagicMock()
    mock_session = mocker.MagicMock()
    cl = Client('http://localhost', mock_gui, mock_session, homedir)
    mock_thread = mocker.MagicMock()
    mock_runner = mocker.MagicMock()
    mock_runner.result = 'result'
    mock_runner.current_object = None
    mock_timer = mocker.MagicMock()
    cl.api_threads = {
        'thread_uuid': {
            'thread': mock_thread,
            'runner': mock_runner,
            'timer': mock_timer,
        }
    }
    cl.clean_thread = mocker.MagicMock()
    mock_user_callback = mocker.MagicMock()
    cl.completed_api_call('thread_uuid', mock_user_callback)
    cl.clean_thread.assert_called_once_with('thread_uuid')
    mock_user_callback.assert_called_once_with('result')
    mock_timer.stop.assert_called_once_with()
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))
    mock_thread = mock.MagicMock()
    mock_runner = mock.MagicMock()
    mock_runner.result = 'result'
    mock_runner.current_object = 'current_object'
    mock_timer = mock.MagicMock()
    cl.api_threads = {
        'thread_uuid': {
            'thread': mock_thread,
            'runner': mock_runner,
            'timer': mock_timer,
        }
    }
    cl.clean_thread = mock.MagicMock()
    mock_user_callback = mock.MagicMock()
    cl.completed_api_call('thread_uuid', mock_user_callback)
    cl.clean_thread.assert_called_once_with('thread_uuid')
    mock_user_callback.assert_called_once_with('result',
                                               current_object='current_object')
    mock_timer.stop.assert_called_once_with()
Beispiel #3
0
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()