Skip to content

Commit

Permalink
WIP DO NOT MERGE
Browse files Browse the repository at this point in the history
  • Loading branch information
heartsucker committed Dec 20, 2018
1 parent d383f51 commit 9718dc1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 43 deletions.
17 changes: 7 additions & 10 deletions securedrop_client/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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?
Expand All @@ -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):
"""
Expand Down
35 changes: 2 additions & 33 deletions tests/test_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down

0 comments on commit 9718dc1

Please sign in to comment.