def test_Client_start_message_thread(safe_tmpdir): """ When starting message-fetching thread, make sure we do a few things. """ mock_gui = mock.MagicMock() mock_session = mock.MagicMock() cl = Client('http://localhost', mock_gui, mock_session, str(safe_tmpdir)) with mock.patch('securedrop_client.logic.QThread') as mock_qthread, \ mock.patch('securedrop_client.logic.MessageSync'): cl.message_sync = mock.MagicMock() cl.start_message_thread() cl.message_sync.moveToThread.assert_called_once_with(mock_qthread()) cl.message_thread.started.connect.assert_called_once_with( cl.message_sync.run) cl.message_thread.start.assert_called_once_with()
def test_Client_start_message_thread(homedir, config, mocker): """ When starting message-fetching thread, make sure we do a few things. 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_qthread = mocker.patch('securedrop_client.logic.QThread') mocker.patch('securedrop_client.logic.MessageSync') cl.message_sync = mocker.MagicMock() cl.start_message_thread() cl.message_sync.moveToThread.assert_called_once_with(mock_qthread()) cl.message_thread.started.connect.assert_called_once_with( cl.message_sync.run) cl.message_thread.start.assert_called_once_with()
def test_Client_start_message_thread_if_already_running( homedir, config, mocker): """ Ensure that when starting the message thread, we don't start another thread if it's already running. Instead, we just authenticate the existing thread. 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) cl.api = 'api object' cl.message_sync = mocker.MagicMock() cl.message_thread = mocker.MagicMock() cl.message_thread.api = None cl.start_message_thread() cl.message_sync.api = cl.api cl.message_thread.start.assert_not_called()
def test_Client_logout(homedir, config, mocker): """ The API is reset to None and the UI is set to logged out state. The message and reply threads should also have the 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) cl.api = mocker.MagicMock() cl.message_sync = mocker.MagicMock() cl.reply_sync = mocker.MagicMock() cl.message_sync.api = mocker.MagicMock() cl.reply_sync.api = mocker.MagicMock() cl.logout() assert cl.api is None assert cl.message_sync.api is None assert cl.reply_sync.api is None cl.gui.logout.assert_called_once_with()