def test_conversation_pending_message(): """ Test that a conversation with a message that's not yet downloaded shows the right placeholder text """ w = Window() w.controller = mock.MagicMock() w.main_view = mock.MagicMock() w._add_item_content_or = mock.MagicMock() mock_conview = mock.MagicMock() mock_source = mock.MagicMock() mock_source.journalistic_designation = 'Testy McTestface' submission = Submission(source=mock_source, uuid="test", size=123, filename="test.msg.gpg", download_url='http://test/test') submission.is_downloaded = False mock_source.collection = [submission] with mock.patch('securedrop_client.gui.main.ConversationView', mock_conview): w.show_conversation_for(mock_source) conv = mock_conview() # once for source name, once for message assert conv.add_message.call_count == 2 assert conv.add_message.call_args == \ mock.call("<Message not yet downloaded>")
def test_conversation_pending_message(mocker): """ Test that a conversation with a message that's not yet downloaded shows the right placeholder text """ w = Window('mock') w.controller = mocker.MagicMock() w.main_view = mocker.MagicMock() w._add_item_content_or = mocker.MagicMock() mock_source = mocker.MagicMock() mock_source.journalistic_designation = 'Testy McTestface' msg_uuid = str(uuid4()) submission = Submission(source=mock_source, uuid=msg_uuid, size=123, filename="test.msg.gpg", download_url='http://test/test') submission.is_downloaded = False mock_source.collection = [submission] mocked_add_message = mocker.patch( 'securedrop_client.gui.widgets.ConversationView.add_message') mocker.patch('securedrop_client.gui.main.QVBoxLayout') mocker.patch('securedrop_client.gui.main.QWidget') w.show_conversation_for(mock_source) assert mocked_add_message.call_count == 1 assert mocked_add_message.call_args == mocker.call( msg_uuid, "<Message not yet downloaded>")
def test_conversation_for(mocker): """ Test that the source collection is displayed in the conversation view. """ w = Window('mock') w.controller = mocker.MagicMock() w.main_view = mocker.MagicMock() mock_source = mocker.MagicMock() mock_source.journalistic_designation = 'Testy McTestface' mock_file = mocker.MagicMock() mock_file.filename = '1-my-source-doc.gpg' mock_message = mocker.MagicMock() mock_message.filename = '2-my-source-msg.gpg' mock_reply = mocker.MagicMock() mock_reply.filename = '3-my-source-reply.gpg' mock_source.collection = [mock_file, mock_message, mock_reply] mocked_add_message = mocker.patch( 'securedrop_client.gui.widgets.ConversationView.add_message', new=mocker.Mock()) mocked_add_reply = mocker.patch( 'securedrop_client.gui.widgets.ConversationView.add_reply', new=mocker.Mock()) mocked_add_file = mocker.patch( 'securedrop_client.gui.widgets.ConversationView.add_file', new=mocker.Mock()) w.show_conversation_for(mock_source) assert mocked_add_message.call_count > 0 assert mocked_add_reply.call_count > 0 assert mocked_add_file.call_count > 0 # check that showing the conversation a second time doesn't break anything # stop the old mockers mocked_add_message.stop() mocked_add_reply.stop() mocked_add_file.stop() # use new mocks to check the count again mocked_add_message = mocker.patch( 'securedrop_client.gui.widgets.ConversationView.add_message', new=mocker.Mock()) mocked_add_reply = mocker.patch( 'securedrop_client.gui.widgets.ConversationView.add_reply', new=mocker.Mock()) mocked_add_file = mocker.patch( 'securedrop_client.gui.widgets.ConversationView.add_file', new=mocker.Mock()) w.show_conversation_for(mock_source) # because the conversation was cached, we don't call these functions again assert mocked_add_message.call_count == 0 assert mocked_add_reply.call_count == 0 assert mocked_add_file.call_count == 0
def test_show_login(mocker): """ The login dialog is displayed with a clean state. """ w = Window() w.controller = mocker.MagicMock() mock_ld = mocker.patch('securedrop_client.gui.main.LoginDialog') w.show_login() mock_ld.assert_called_once_with(w) w.login_dialog.reset.assert_called_once_with() w.login_dialog.show.assert_called_once_with()
def test_show_login_with_error_message(mocker): """ The login dialog is displayed with a clean state. """ w = Window() w.controller = mocker.MagicMock() mock_ld = mocker.patch('securedrop_client.gui.main.LoginDialog') w.show_login('this-is-an-error-message-to-show-on-login-window') mock_ld.assert_called_once_with(w) w.login_dialog.reset.assert_called_once_with() w.login_dialog.show.assert_called_once_with() w.login_dialog.error.assert_called_once_with('this-is-an-error-message-to-show-on-login-window')
def functional_test_logged_out_context(homedir, reply_status_codes, session, config): """ Returns a tuple containing a Window instance and a Controller instance that have been correctly set up and isolated from any other instances of the application to be run in the test suite. """ gui = Window() # Configure test keys. create_gpg_test_context(homedir) # Configure and create the database. session_maker = make_session_maker(homedir) # Create the controller. controller = Controller(HOSTNAME, gui, session_maker, homedir, False, False) # Link the gui and controller together. gui.controller = controller # Et Voila... return (gui, controller, homedir)
def get_test_context(sdc_home): """ Returns a tuple containing a Window instance and a Controller instance that have been correctly set up and isolated from any other instances of the application to be run in the test suite. """ # The application's window. gui = Window() # Create all app assets in a new temp directory and sub-directories. safe_mkdir(os.path.join(sdc_home.name, "gpg")) safe_mkdir(os.path.join(sdc_home.name, "data")) # Configure test keys. create_gpg_test_context(sdc_home) # Configure and create the database. session_maker = make_session_maker(sdc_home.name) create_dev_data(sdc_home.name) # Create the controller. controller = Controller(HOSTNAME, gui, session_maker, sdc_home.name, False, False) # Link the gui and controller together. gui.controller = controller # Et Voila... return (gui, controller)
def test_conversation_for(): """ Test that the source collection is displayed in the conversation view. """ w = Window() w.controller = mock.MagicMock() w.main_view = mock.MagicMock() mock_conview = mock.MagicMock() mock_source = mock.MagicMock() mock_source.journalistic_designation = 'Testy McTestface' mock_file = mock.MagicMock() mock_file.filename = '1-my-source-doc.gpg' mock_message = mock.MagicMock() mock_message.filename = '2-my-source-msg.gpg' mock_reply = mock.MagicMock() mock_reply.filename = '3-my-source-reply.gpg' mock_source.collection = [mock_file, mock_message, mock_reply] with mock.patch('securedrop_client.gui.main.ConversationView', mock_conview): w.show_conversation_for(mock_source) conv = mock_conview() assert conv.add_message.call_count > 0 assert conv.add_reply.call_count > 0 assert conv.add_file.call_count > 0