Skip to content

Commit

Permalink
Fix defect #174: application crash on source collection deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
redshiftzero committed Nov 15, 2018
1 parent 6befc41 commit b9c3565
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
5 changes: 3 additions & 2 deletions securedrop_client/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
24 changes: 24 additions & 0 deletions tests/test_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b9c3565

Please sign in to comment.