def test_ConversationView_add_not_downloaded_file(mocker, homedir): """ Adding a file results in a new FileWidget added to the layout with the proper QLabel. """ mocked_source = mocker.MagicMock() mocked_controller = mocker.MagicMock() cv = ConversationView(mocked_source, homedir, mocked_controller) cv.conversation_layout = mocker.MagicMock() mock_source = mocker.MagicMock() mock_file = mocker.MagicMock() mock_file.is_downloaded = False mock_file.size = 123 mock_label = mocker.patch('securedrop_client.gui.widgets.QLabel') mocker.patch('securedrop_client.gui.widgets.QHBoxLayout.addWidget') mocker.patch('securedrop_client.gui.widgets.FileWidget.setLayout') cv.add_file(mock_source, mock_file) mock_label.assert_called_with("Download (123 bytes)") assert cv.conversation_layout.addWidget.call_count == 1 cal = cv.conversation_layout.addWidget.call_args_list assert isinstance(cal[0][0][0], FileWidget)
def test_ConversationView_setup(): """ Ensure the controller is set """ cv = ConversationView(None) mock_controller = mock.MagicMock() cv.setup(mock_controller) assert cv.controller == mock_controller
def test_ConversationView_move_to_bottom(): """ Check the signal handler sets the correct value for the scrollbar to be the maximum possible value. """ cv = ConversationView(None) cv.scroll = mock.MagicMock() cv.move_to_bottom(0, 6789) cv.scroll.verticalScrollBar().setValue.assert_called_once_with(6789)
def test_ConversationView_move_to_bottom(mocker, homedir): """ Check the signal handler sets the correct value for the scrollbar to be the maximum possible value. """ mocked_source = mocker.MagicMock() mocked_controller = mocker.MagicMock() cv = ConversationView(mocked_source, homedir, mocked_controller) cv.scroll = mocker.MagicMock() cv.move_to_bottom(0, 6789) cv.scroll.verticalScrollBar().setValue.assert_called_once_with(6789)
def test_ConversationView_add_reply(): """ Adding a reply results in a new ReplyWidget added to the layout. Any associated files are added as FileWidgets. """ cv = ConversationView(None) cv.conversation_layout = mock.MagicMock() cv.add_reply('hello', [ 'file1.pdf', ]) assert cv.conversation_layout.addWidget.call_count == 2 cal = cv.conversation_layout.addWidget.call_args_list assert isinstance(cal[0][0][0], ReplyWidget) assert isinstance(cal[1][0][0], FileWidget)
def show_conversation_for(self, source): """ Show conversation of messages and replies between a source and journalists. """ conversation = ConversationView(self) conversation.setup(self.controller) conversation.add_message('Source name: {}'.format( source.journalist_designation)) # Display each conversation item in the source collection. for conversation_item in source.collection: if conversation_item.filename.endswith('msg.gpg'): self.add_item_content_or(conversation.add_message, conversation_item, "<Message not yet downloaded>") elif conversation_item.filename.endswith('reply.gpg'): self.add_item_content_or(conversation.add_reply, conversation_item, "<Reply not yet downloaded>") else: conversation.add_file(source, conversation_item) self.main_view.update_view(conversation)
def test_ConversationView_add_reply(mocker, homedir): """ Adding a reply results in a new ReplyWidget added to the layout. """ mocked_source = mocker.MagicMock() mocked_controller = mocker.MagicMock() cv = ConversationView(mocked_source, homedir, mocked_controller) cv.conversation_layout = mocker.MagicMock() cv.add_reply('mock id', 'hello') assert cv.conversation_layout.addWidget.call_count == 1 cal = cv.conversation_layout.addWidget.call_args_list assert isinstance(cal[0][0][0], ReplyWidget)
def test_ConversationView_init(mocker, homedir): """ Ensure the conversation view has a layout to add widgets to. """ mocked_source = mocker.MagicMock() mocked_controller = mocker.MagicMock() cv = ConversationView(mocked_source, homedir, mocked_controller) assert isinstance(cv.conversation_layout, QVBoxLayout)
def test_ConversationView_add_reply(): """ Adding a reply results in a new ReplyWidget added to the layout. """ cv = ConversationView(None) cv.controller = mock.MagicMock() cv.conversation_layout = mock.MagicMock() cv.add_reply('hello') assert cv.conversation_layout.addWidget.call_count == 1 cal = cv.conversation_layout.addWidget.call_args_list assert isinstance(cal[0][0][0], ReplyWidget)
def test_ConversationView_add_downloaded_file(): """ Adding a file results in a new FileWidget added to the layout with the proper QLabel. """ cv = ConversationView(None) cv.controller = mock.MagicMock() cv.conversation_layout = mock.MagicMock() mock_source = mock.MagicMock() mock_file = mock.MagicMock() mock_file.is_downloaded = True with mock.patch('securedrop_client.gui.widgets.QLabel') as mock_label, \ mock.patch('securedrop_client.gui.widgets.QHBoxLayout.addWidget'),\ mock.patch('securedrop_client.gui.widgets.FileWidget.setLayout'): cv.add_file(mock_source, mock_file) mock_label.assert_called_with("Open") assert cv.conversation_layout.addWidget.call_count == 1 cal = cv.conversation_layout.addWidget.call_args_list assert isinstance(cal[0][0][0], FileWidget)
def test_ConversationView_init(): """ Ensure the conversation view has a layout to add widgets to. """ cv = ConversationView(None) assert isinstance(cv.conversation_layout, QVBoxLayout)
def show_conversation_for(self, source): """ TODO: Finish this... """ conversation = ConversationView(self) conversation.add_message('Source name: {}'.format( source.journalist_designation)) conversation.add_message('Hello, hello, is this thing switched on?') conversation.add_reply('Yes, I can hear you loud and clear!') conversation.add_reply('How can I help?') conversation.add_message('I have top secret documents relating to ' 'a massive technical scandal at the heart ' ' of the Freedom of the Press Foundation. ' 'In a shocking turn of events, it appears ' 'they give away all their software for FREE.') conversation.add_message("Hello: I’m a nurse at one of the trauma " "centers in town. We've had many patients in " "the last several months, all with " "similar/mysterious respiratory issues. My " "staff has noticed that most live down-wind " "from the Dole fields West of 696. Some of " "the patients say they have complained to " "local authorities about sewage smells. One " "said she's spotted a truck spraying a " "sludge of some kind, on the fields at " "night. I'm attaching a video from the " "patient who taped the trucks, and a PDF of " "redacted police reports that other patients " "shared. I don’t know if there's much you " "can do, but if there is I would be happy " "to help.") conversation.add_message("I work at the City Water Department, and a " "man named Reggie Esters is one of our board " "directors. I believe Reggie is related to " "Rep Monica Conyers. He's literally never " "here, and the resume on file for him makes " "no sense. I have a hunch he is not in his " "job legitimately, and think you should look " "into this. Also: someone I work with heard " "him on the phone once, talking about his " "'time' at Jackson—that contradicts his " "resume. It really seems fishy.", ['fishy_cv.PDF (234Kb)', ]) conversation.add_reply("THIS IS IT THIS IS THE TAPE EVERYONE'S " "LOOKING FOR!!!", ['filename.pdf (32Kb)', ]) conversation.add_reply("Hello: I read your story on Sally Dale, and " "her lawsuit against the St. Joseph's " "Orphanage. My great-aunt was one of the nuns " "there. She is willing to be interviewed, but " "does not want her name, location, or any " "identity details released. She feels " "horrible. She wants the children who survived " "to find peace. Thanks.") self.main_view.update_view(conversation)