From 51232ac0ebf5d41abff96c01b5c32e749b759c45 Mon Sep 17 00:00:00 2001 From: Allie Crevier Date: Tue, 25 Feb 2020 12:00:44 -0800 Subject: [PATCH] no longer mark replies as failed if they time out --- securedrop_client/api_jobs/uploads.py | 1 - securedrop_client/logic.py | 5 ++++- tests/test_logic.py | 19 ++++++++++++++++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/securedrop_client/api_jobs/uploads.py b/securedrop_client/api_jobs/uploads.py index c45ca9f25..7f56c81d6 100644 --- a/securedrop_client/api_jobs/uploads.py +++ b/securedrop_client/api_jobs/uploads.py @@ -71,7 +71,6 @@ def call_api(self, api_client: API, session: Session) -> str: except (RequestTimeoutError, ServerConnectionError) as e: message = "Failed to send reply for source {id} due to Exception: {error}".format( id=self.source_uuid, error=e) - self._set_status_to_failed(session) raise SendReplyJobTimeoutError(message, self.reply_uuid) except Exception as e: message = "Failed to send reply for source {id} due to Exception: {error}".format( diff --git a/securedrop_client/logic.py b/securedrop_client/logic.py index 8fd87d218..ae70573b3 100644 --- a/securedrop_client/logic.py +++ b/securedrop_client/logic.py @@ -813,7 +813,10 @@ def on_reply_failure( exception: Union[SendReplyJobError, SendReplyJobTimeoutError] ) -> None: logger.debug('{} failed to send'.format(exception.reply_uuid)) - self.reply_failed.emit(exception.reply_uuid) + + # only emit failure signal for non-timeout errors + if isinstance(exception, SendReplyJobError): + self.reply_failed.emit(exception.reply_uuid) def get_file(self, file_uuid: str) -> db.File: file = storage.get_file(self.session, file_uuid) diff --git a/tests/test_logic.py b/tests/test_logic.py index 4dfa37683..97ef98378 100644 --- a/tests/test_logic.py +++ b/tests/test_logic.py @@ -16,7 +16,7 @@ from securedrop_client.api_jobs.downloads import ( DownloadChecksumMismatchException, DownloadDecryptionException, DownloadException ) -from securedrop_client.api_jobs.uploads import SendReplyJobError +from securedrop_client.api_jobs.uploads import SendReplyJobError, SendReplyJobTimeoutError with open(os.path.join(os.path.dirname(__file__), 'files', 'test-key.gpg.pub.asc')) as f: PUB_KEY = f.read() @@ -1395,6 +1395,23 @@ def test_Controller_on_reply_failure(homedir, mocker, session_maker): reply_succeeded.emit.assert_not_called() +def test_Controller_on_reply_failure_for_timeout(homedir, mocker, session_maker): + ''' + Check that when the method is called, the client emits the correct signal. + ''' + co = Controller('http://localhost', mocker.MagicMock(), session_maker, homedir) + reply_succeeded = mocker.patch.object(co, 'reply_succeeded') + reply_failed = mocker.patch.object(co, 'reply_failed') + debug_logger = mocker.patch('securedrop_client.logic.logger.debug') + + exception = SendReplyJobTimeoutError('mock_error_message', 'mock_reply_uuid') + co.on_reply_failure(exception) + + debug_logger.assert_called_once_with('{} failed to send'.format('mock_reply_uuid')) + reply_failed.emit.assert_not_called() + reply_succeeded.emit.assert_not_called() + + def test_Controller_is_authenticated_property(homedir, mocker, session_maker): ''' Check that the @property `is_authenticated`: