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_conversation_for(): """ TODO: Finish this once we have data. Currently checks only the GUI layer is called in the expected manner with dummy data. """ w = Window() w.main_view = mock.MagicMock() mock_conview = mock.MagicMock() mock_source = mock.MagicMock() mock_source.journalistic_designation = 'Testy McTestface' 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
def test_on_source_changed(): """ Ensure the event handler for when a source is changed calls the show_conversation_for method with the expected source object. """ w = Window() w.main_view = mock.MagicMock() mock_si = w.main_view.source_list.currentItem() mock_sw = w.main_view.source_list.itemWidget() w.show_conversation_for = mock.MagicMock() w.on_source_changed() w.show_conversation_for.assert_called_once_with(mock_sw.source)
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