From cc8f6a4169d0b3d1a81caa537f30231564e47091 Mon Sep 17 00:00:00 2001 From: heartsucker Date: Sun, 6 Jan 2019 15:06:36 +0100 Subject: [PATCH] inject homedir for pulling data on update --- securedrop_client/gui/main.py | 3 +-- securedrop_client/gui/widgets.py | 6 ++++-- securedrop_client/logic.py | 6 +----- tests/gui/test_widgets.py | 28 ++++++++++++++-------------- tests/test_logic.py | 3 +-- 5 files changed, 21 insertions(+), 25 deletions(-) diff --git a/securedrop_client/gui/main.py b/securedrop_client/gui/main.py index 56366d8142..af2506269c 100644 --- a/securedrop_client/gui/main.py +++ b/securedrop_client/gui/main.py @@ -26,7 +26,6 @@ ConversationView, SourceProfileShortWidget) from securedrop_client.resources import load_icon -from securedrop_client.storage import get_data logger = logging.getLogger(__name__) @@ -177,7 +176,7 @@ def show_conversation_for(self, source): conversation_container = self.conversations.get(source.uuid, None) if conversation_container is None: - conversation = ConversationView(source, parent=self) + conversation = ConversationView(source, self.sdc_home, parent=self) conversation.setup(self.controller) conversation_container = QWidget() diff --git a/securedrop_client/gui/widgets.py b/securedrop_client/gui/widgets.py index 5d4fb62692..c79631125c 100644 --- a/securedrop_client/gui/widgets.py +++ b/securedrop_client/gui/widgets.py @@ -26,6 +26,7 @@ QMessageBox, QToolButton from securedrop_client.resources import load_svg, load_image +from securedrop_client.storage import get_data from securedrop_client.utils import humanize_filesize logger = logging.getLogger(__name__) @@ -612,9 +613,10 @@ class ConversationView(QWidget): Renders a conversation. """ - def __init__(self, source_db_object, parent=None): + def __init__(self, source_db_object, sdc_home: str, parent=None): super().__init__(parent) self.source = source_db_object + self.sdc_home = sdc_home self.container = QWidget() self.conversation_layout = QVBoxLayout() @@ -667,7 +669,7 @@ def add_item_content_or(self, adder, item, default): if item.is_downloaded is False: adder(default) else: - adder(item.content) + adder(get_data(self.sdc_home, item.filename)) def setup(self, controller): """ diff --git a/securedrop_client/logic.py b/securedrop_client/logic.py index 507159416a..2467c7c693 100644 --- a/securedrop_client/logic.py +++ b/securedrop_client/logic.py @@ -576,11 +576,7 @@ def on_file_downloaded(self, result, current_object): # Now that download and decrypt are done, mark the file as such. storage.mark_file_as_downloaded(file_uuid, self.session) - # Refresh the current source conversation, bearing in mind - # that the user may have navigated to another source. - self.gui.show_conversation_for(self.gui.current_source) - self.set_status( - 'Finished downloading {}'.format(current_object.filename)) + self.set_status('Finished downloading {}'.format(current_object.filename)) else: # The file did not download properly. # Update the UI in some way to indicate a failure state. self.set_status("The file download failed. Please try again.") diff --git a/tests/gui/test_widgets.py b/tests/gui/test_widgets.py index 6a39549dd0..f529e56d99 100644 --- a/tests/gui/test_widgets.py +++ b/tests/gui/test_widgets.py @@ -680,44 +680,44 @@ def test_FileWidget_mousePressEvent_open(mocker): fw.controller.on_file_open.assert_called_once_with(submission) -def test_ConversationView_init(mocker): +def test_ConversationView_init(mocker, homedir): """ Ensure the conversation view has a layout to add widgets to. """ mocked_source = mocker.MagicMock() - cv = ConversationView(mocked_source) + cv = ConversationView(mocked_source, homedir) assert isinstance(cv.conversation_layout, QVBoxLayout) -def test_ConversationView_setup(mocker): +def test_ConversationView_setup(mocker, homedir): """ Ensure the controller is set """ mocked_source = mocker.MagicMock() - cv = ConversationView(mocked_source) + cv = ConversationView(mocked_source, homedir) mock_controller = mocker.MagicMock() cv.setup(mock_controller) assert cv.controller == mock_controller -def test_ConversationView_move_to_bottom(mocker): +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() - cv = ConversationView(mocked_source) + cv = ConversationView(mocked_source, homedir) cv.scroll = mocker.MagicMock() cv.move_to_bottom(0, 6789) cv.scroll.verticalScrollBar().setValue.assert_called_once_with(6789) -def test_ConversationView_add_message(mocker): +def test_ConversationView_add_message(mocker, homedir): """ Adding a message results in a new MessageWidget added to the layout. """ mocked_source = mocker.MagicMock() - cv = ConversationView(mocked_source) + cv = ConversationView(mocked_source, homedir) cv.controller = mocker.MagicMock() cv.conversation_layout = mocker.MagicMock() @@ -728,12 +728,12 @@ def test_ConversationView_add_message(mocker): assert isinstance(cal[0][0][0], MessageWidget) -def test_ConversationView_add_reply(mocker): +def test_ConversationView_add_reply(mocker, homedir): """ Adding a reply results in a new ReplyWidget added to the layout. """ mocked_source = mocker.MagicMock() - cv = ConversationView(mocked_source) + cv = ConversationView(mocked_source, homedir) cv.controller = mocker.MagicMock() cv.conversation_layout = mocker.MagicMock() @@ -744,13 +744,13 @@ def test_ConversationView_add_reply(mocker): assert isinstance(cal[0][0][0], ReplyWidget) -def test_ConversationView_add_downloaded_file(mocker): +def test_ConversationView_add_downloaded_file(mocker, homedir): """ Adding a file results in a new FileWidget added to the layout with the proper QLabel. """ mocked_source = mocker.MagicMock() - cv = ConversationView(mocked_source) + cv = ConversationView(mocked_source, homedir) cv.controller = mocker.MagicMock() cv.conversation_layout = mocker.MagicMock() @@ -769,13 +769,13 @@ def test_ConversationView_add_downloaded_file(mocker): assert isinstance(cal[0][0][0], FileWidget) -def test_ConversationView_add_not_downloaded_file(mocker): +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() - cv = ConversationView(mocked_source) + cv = ConversationView(mocked_source, homedir) cv.controller = mocker.MagicMock() cv.conversation_layout = mocker.MagicMock() diff --git a/tests/test_logic.py b/tests/test_logic.py index 6db51457ac..66384c3020 100644 --- a/tests/test_logic.py +++ b/tests/test_logic.py @@ -700,8 +700,7 @@ def test_Client_update_conversation_views(homedir, config, mocker): cl = Client('http://localhost', mock_gui, mock_session, homedir) cl.update_conversation_views() mock_session.refresh.assert_called_with(mock_gui.current_source) - mock_gui.show_conversation_for.assert_called_once_with( - mock_gui.current_source) + mock_gui.show_conversation_for.assert_called_once_with(mock_gui.current_source) def test_Client_unstars_a_source_if_starred(homedir, config, mocker):