Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix defect #174: application crash on source collection deletion #176

Merged
merged 1 commit into from
Nov 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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