From 9718dc192b8064fa2b84231638e7ac307ceb30b9 Mon Sep 17 00:00:00 2001 From: heartsucker Date: Thu, 20 Dec 2018 15:39:56 +0100 Subject: [PATCH] WIP DO NOT MERGE --- securedrop_client/logic.py | 17 +++++++---------- tests/test_logic.py | 35 ++--------------------------------- 2 files changed, 9 insertions(+), 43 deletions(-) diff --git a/securedrop_client/logic.py b/securedrop_client/logic.py index 7f33723fb4..5420300be0 100644 --- a/securedrop_client/logic.py +++ b/securedrop_client/logic.py @@ -149,8 +149,8 @@ def setup(self): # that as downloads/decryption occur, the messages and replies # populate the view. self.conv_view_update = QTimer() - self.conv_view_update.timeout.connect(self.update_conversation_view) - self.conv_view_update.start(1000 * 60 * 0.10) # every 6 seconds + self.conv_view_update.timeout.connect(self.update_conversation_views) + self.conv_view_update.start(1000 * 6) # every 6 seconds event.listen(db.Submission, 'load', self.on_object_loaded) event.listen(db.Submission, 'init', self.on_object_instantiated) @@ -420,8 +420,7 @@ def on_synced(self, result): except CryptoError: logger.warning('Failed to import key for source {}'.format(source.uuid)) - # TODO: show something in the conversation view? - # self.gui.show_conversation_for() + self.update_conversation_views() else: # How to handle a failure? Exceptions are already logged. Perhaps # a message in the UI? @@ -445,16 +444,14 @@ def update_sources(self): self.gui.show_sources(sources) self.update_sync() - def update_conversation_view(self): + def update_conversation_views(self): """ Updates the conversation view to reflect progress of the download and decryption of messages and replies. """ - # Redraw the conversation view if we have clicked on a source - # and the source has not been deleted. - if self.gui.current_source and self.gui.current_source in self.session: - self.session.refresh(self.gui.current_source) - self.gui.show_conversation_for(self.gui.current_source) + for conversation in self.gui.conversations.values(): + self.session.refresh(conversation.source) + conversation.update_conversation(conversation.source.collection) def on_update_star_complete(self, result): """ diff --git a/tests/test_logic.py b/tests/test_logic.py index 00c504bf3d..d544ef9dbf 100644 --- a/tests/test_logic.py +++ b/tests/test_logic.py @@ -680,7 +680,7 @@ def test_Client_update_sources(homedir, config, mocker): mock_gui.show_sources.assert_called_once_with(source_list) -def test_Client_update_conversation_view_current_source(homedir, config, mocker): +def test_Client_update_conversation_views(homedir, config, mocker): """ Ensure the UI displays the latest version of the messages/replies that have been downloaded/decrypted in the current conversation view. @@ -698,43 +698,12 @@ def test_Client_update_conversation_view_current_source(homedir, config, mocker) mock_session.refresh = mocker.MagicMock() cl = Client('http://localhost', mock_gui, mock_session, homedir) - cl.update_conversation_view() + 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) -def test_Client_update_conversation_deleted_source(homedir, config, mocker): - """ - Ensure the UI does not attempt to refresh and display a deleted - source. - Using the `config` fixture to ensure the config is written to disk. - """ - mock_gui = mocker.MagicMock() - mock_gui.current_source = 'teehee' - mock_gui.show_conversation_for = mocker.MagicMock() - mock_session = mocker.MagicMock() - mock_session.refresh = mocker.MagicMock() - cl = Client('http://localhost', mock_gui, mock_session, homedir) - cl.update_conversation_view() - mock_session.refresh.assert_not_called() - mock_gui.show_conversation_for.assert_not_called() - - -def test_Client_update_conversation_view_no_current_source(homedir, config, mocker): - """ - Ensure that if there is no current source (i.e. the user has not clicked - a source in the sidebar), the UI will not redraw the conversation view. - Using the `config` fixture to ensure the config is written to disk. - """ - mock_gui = mocker.MagicMock() - mock_gui.current_source = None - mock_session = mocker.MagicMock() - cl = Client('http://localhost', mock_gui, mock_session, homedir) - cl.update_conversation_view() - mock_gui.show_conversation_for.assert_not_called() - - def test_Client_unstars_a_source_if_starred(homedir, config, mocker): """ Ensure that the client unstars a source if it is starred.