From b9c3565373aba85e5eaba014bf71a8d23a60a511 Mon Sep 17 00:00:00 2001 From: redshiftzero Date: Thu, 15 Nov 2018 11:02:24 -0800 Subject: [PATCH] Fix defect #174: application crash on source collection deletion --- securedrop_client/logic.py | 5 +++-- tests/test_logic.py | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/securedrop_client/logic.py b/securedrop_client/logic.py index bec183923..25891f1ba 100644 --- a/securedrop_client/logic.py +++ b/securedrop_client/logic.py @@ -419,8 +419,9 @@ def update_conversation_view(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. - if self.gui.current_source: + # 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) diff --git a/tests/test_logic.py b/tests/test_logic.py index e60cee48c..6a187347a 100644 --- a/tests/test_logic.py +++ b/tests/test_logic.py @@ -544,12 +544,36 @@ def test_Client_update_conversation_view_current_source(safe_tmpdir): mock_gui.current_source = 'teehee' mock_gui.show_conversation_for = mock.MagicMock() mock_session = mock.MagicMock() + + # Since we use the set-like behavior of self.session + # to check if the source is still persistent, let's mock that here + mock_session.__contains__ = mock.MagicMock() + mock_session.__contains__.return_value = [mock_gui.current_source] + + mock_session.refresh = mock.MagicMock() cl = Client('http://localhost', mock_gui, mock_session, str(safe_tmpdir)) cl.update_conversation_view() + 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(safe_tmpdir): + """ + Ensure the UI does not attempt to refresh and display a deleted + source. + """ + mock_gui = mock.MagicMock() + mock_gui.current_source = 'teehee' + mock_gui.show_conversation_for = mock.MagicMock() + mock_session = mock.MagicMock() + mock_session.refresh = mock.MagicMock() + cl = Client('http://localhost', mock_gui, mock_session, str(safe_tmpdir)) + 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(safe_tmpdir): """ Ensure that if there is no current source (i.e. the user has not clicked