From a9b61b5e7441ee20a1cb80aca260047fe5f5c2ff Mon Sep 17 00:00:00 2001 From: Allie Crevier Date: Fri, 20 Mar 2020 00:00:03 -0700 Subject: [PATCH] update star functional test --- securedrop_client/api_jobs/updatestar.py | 10 ++++------ securedrop_client/gui/widgets.py | 4 ++-- securedrop_client/logic.py | 6 ++++-- tests/functional/test_star_source.py | 2 +- tests/functional/test_unstar_source.py | 2 +- tests/test_logic.py | 8 +++++--- 6 files changed, 17 insertions(+), 15 deletions(-) diff --git a/securedrop_client/api_jobs/updatestar.py b/securedrop_client/api_jobs/updatestar.py index e2473a6861..ce9f2fac3b 100644 --- a/securedrop_client/api_jobs/updatestar.py +++ b/securedrop_client/api_jobs/updatestar.py @@ -36,25 +36,23 @@ def call_api(self, api_client: API, session: Session) -> str: return self.source_uuid except (RequestTimeoutError, ServerConnectionError) as e: error_message = f'Failed to update star on source {self.source_uuid} due to error: {e}' - raise UpdateStarJobTimeoutError(error_message, self.source_uuid, self.is_starred) + raise UpdateStarJobTimeoutError(error_message, self.source_uuid) except Exception as e: error_message = f'Failed to update star on source {self.source_uuid} due to {e}' - raise UpdateStarJobError(error_message, self.source_uuid, self.is_starred) + raise UpdateStarJobError(error_message, self.source_uuid) class UpdateStarJobError(Exception): - def __init__(self, message: str, source_uuid: str, is_starred: bool) -> None: + def __init__(self, message: str, source_uuid: str) -> None: super().__init__(message) self.source_uuid = source_uuid - self.is_starred = is_starred class UpdateStarJobTimeoutError(RequestTimeoutError): - def __init__(self, message: str, source_uuid: str, is_starred: bool) -> None: + def __init__(self, message: str, source_uuid: str) -> None: super().__init__() self.message = message self.source_uuid = source_uuid - self.is_starred = is_starred def __str__(self) -> str: return self.message diff --git a/securedrop_client/gui/widgets.py b/securedrop_client/gui/widgets.py index 1214fb43f2..cd78577c00 100644 --- a/securedrop_client/gui/widgets.py +++ b/securedrop_client/gui/widgets.py @@ -1338,14 +1338,14 @@ def update(self, is_starred: bool) -> None: self.is_starred = is_starred self.setChecked(self.is_starred) - @pyqtSlot(str) + @pyqtSlot(str, bool) def on_star_update_failed(self, source_uuid: str, is_starred: bool) -> None: """ If the star update failed to update on the server, toggle back to previous state. """ if self.source_uuid == source_uuid: self.is_starred = is_starred - self.setChecked(is_starred) + self.setChecked(self.is_starred) self.pending_count = self.pending_count - 1 @pyqtSlot(str) diff --git a/securedrop_client/logic.py b/securedrop_client/logic.py index 784c5fdce3..8ab4405ca2 100644 --- a/securedrop_client/logic.py +++ b/securedrop_client/logic.py @@ -202,8 +202,9 @@ class Controller(QObject): Emits: str: the source UUID + bool: is_starred """ - star_update_failed = pyqtSignal(str) + star_update_failed = pyqtSignal(str, bool) def __init__(self, hostname: str, gui, session_maker: sessionmaker, home: str, proxy: bool = True, qubes: bool = True) -> None: @@ -522,7 +523,8 @@ def on_update_star_failure( ) -> None: if isinstance(error, UpdateStarJobError): self.gui.update_error_status(_('Failed to update star.')) - self.star_update_failed.emit(error.source_uuid, error.is_starred) + source = self.session.query(db.Source).filter_by(uuid=error.source_uuid).one() + self.star_update_failed.emit(error.source_uuid, source.is_starred) @login_required def update_star(self, source_uuid: str, is_starred: bool): diff --git a/tests/functional/test_star_source.py b/tests/functional/test_star_source.py index f48b9ae9fe..001b069946 100644 --- a/tests/functional/test_star_source.py +++ b/tests/functional/test_star_source.py @@ -34,4 +34,4 @@ def check_for_sources(): qtbot.mouseClick(first_source_widget.star, Qt.LeftButton) qtbot.wait(1000) # Check the source is now checked. - assert first_source_widget.star.source.is_starred is True + assert first_source_widget.star.is_starred is True diff --git a/tests/functional/test_unstar_source.py b/tests/functional/test_unstar_source.py index a44e78af80..a9e4f9a546 100644 --- a/tests/functional/test_unstar_source.py +++ b/tests/functional/test_unstar_source.py @@ -34,4 +34,4 @@ def check_for_sources(): qtbot.mouseClick(first_source_widget.star, Qt.LeftButton) qtbot.wait(1000) # Check the source isn't checked once more. - assert first_source_widget.star.source.is_starred is False + assert first_source_widget.star.is_starred is False diff --git a/tests/test_logic.py b/tests/test_logic.py index b07891d57c..28ad9feaaf 100644 --- a/tests/test_logic.py +++ b/tests/test_logic.py @@ -584,11 +584,13 @@ def test_Controller_on_update_star_failed(homedir, config, mocker): gui = mocker.MagicMock() co = Controller('http://localhost', gui, mocker.MagicMock(), homedir) co.star_update_failed = mocker.MagicMock() + source = factory.Source() + co.session.query().filter_by().one.return_value = source - error = UpdateStarJobError('mock_message', 'mock_uuid', True) + error = UpdateStarJobError('mock_message', source.uuid) co.on_update_star_failure(error) - co.star_update_failed.emit.assert_called_once_with(error.source_uuid, error.is_starred) + co.star_update_failed.emit.assert_called_once_with(source.uuid, source.is_starred) gui.update_error_status.assert_called_once_with('Failed to update star.') @@ -601,7 +603,7 @@ def test_Controller_on_update_star_failed_due_to_timeout(homedir, config, mocker co = Controller('http://localhost', gui, mocker.MagicMock(), homedir) co.star_update_failed = mocker.MagicMock() - error = UpdateStarJobTimeoutError('mock_message', 'mock_uuid', True) + error = UpdateStarJobTimeoutError('mock_message', 'mock_uuid') co.on_update_star_failure(error) co.star_update_failed.emit.assert_not_called()