From 2f1639b3f74cbd7e86e2ec8b5e52a3731b26b5c0 Mon Sep 17 00:00:00 2001 From: heartsucker Date: Tue, 21 May 2019 21:01:47 +0200 Subject: [PATCH] yeeeeeeeeeeeeeeeeeeeee --- securedrop_client/gui/widgets.py | 29 +++++++++++------------------ securedrop_client/logic.py | 1 - tests/gui/test_widgets.py | 18 +----------------- 3 files changed, 12 insertions(+), 36 deletions(-) diff --git a/securedrop_client/gui/widgets.py b/securedrop_client/gui/widgets.py index 76b9d86739..1eb23c1690 100644 --- a/securedrop_client/gui/widgets.py +++ b/securedrop_client/gui/widgets.py @@ -1286,20 +1286,14 @@ def __init__( file_uuid: str, controller: Controller, file_ready_signal: pyqtBoundSignal, - align="left", - ): + ) -> None: """ - Given some text, an indication of alignment ('left' or 'right') and - a reference to the controller, make something to display a file. - - Align is set to left by default because currently SecureDrop can only - accept files from sources to journalists. + Given some text and a reference to the controller, make something to display a file. """ super().__init__() self.session_maker = session_maker self.controller = controller self.file_uuid = file_uuid - self.align = align self.file_is_downloaded = False # default to `False`, value updated in `update()` self.layout = QHBoxLayout() @@ -1308,12 +1302,18 @@ def __init__( file_ready_signal.connect(self._on_file_download, type=Qt.QueuedConnection) - def update(self): + def update(self) -> None: icon = QLabel() icon.setPixmap(load_image('file.png')) session = self.session_maker() + + # we have to query to get the object we want file_ = session.query(File).filter_by(uuid=self.file_uuid).one() + # and then force a refresh because SQLAlchemy might have a copy of this object + # in this thread already that isn't up to date + session.refresh(file_) + self.file_is_downloaded = file_.is_downloaded if self.file_is_downloaded: @@ -1322,18 +1322,11 @@ def update(self): human_filesize = humanize_filesize(file_.size) description = QLabel("Download ({})".format(human_filesize)) - if self.align != "left": - # Float right... - self.layout.addStretch(5) - self.layout.addWidget(icon) self.layout.addWidget(description, 5) + self.layout.addStretch(5) - if self.align == "left": - # Add space on right hand side... - self.layout.addStretch(5) - - def clear(self): + def clear(self) -> None: while self.layout.count(): child = self.layout.takeAt(0) if child.widget(): diff --git a/securedrop_client/logic.py b/securedrop_client/logic.py index 40fe659f97..a9984061c1 100644 --- a/securedrop_client/logic.py +++ b/securedrop_client/logic.py @@ -562,7 +562,6 @@ def on_file_download_success(self, result: Any) -> None: """ Called when a file has downloaded. """ - print(type(result), result) self.file_ready.emit(result) def on_file_download_failure(self, exception: Exception) -> None: diff --git a/tests/gui/test_widgets.py b/tests/gui/test_widgets.py index 0cb5238734..65db593ab6 100644 --- a/tests/gui/test_widgets.py +++ b/tests/gui/test_widgets.py @@ -1139,7 +1139,7 @@ def test_FileWidget_init_left(mocker): source = factory.Source() file_ = factory.File(is_downloaded=True) - fw = FileWidget(source, file_, mock_controller, mock_signal, align='left') + fw = FileWidget(source, file_, mock_controller, mock_signal) assert isinstance(fw.layout.takeAt(0), QWidgetItem) assert isinstance(fw.layout.takeAt(0), QWidgetItem) @@ -1147,22 +1147,6 @@ def test_FileWidget_init_left(mocker): assert fw.controller == mock_controller -def test_FileWidget_init_right(mocker): - """ - Check the FileWidget is configured correctly for align-right. - """ - mock_controller = mocker.MagicMock() - mock_signal = mocker.MagicMock() # not important for this test - source = factory.Source() - file_ = factory.File(is_downloaded=True) - - fw = FileWidget(source, file_, mock_controller, mock_signal, align='right') - assert isinstance(fw.layout.takeAt(0), QSpacerItem) - assert isinstance(fw.layout.takeAt(0), QWidgetItem) - assert isinstance(fw.layout.takeAt(0), QWidgetItem) - assert fw.controller == mock_controller - - def test_FileWidget_mousePressEvent_download(mocker): """ Should fire the expected download event handler in the logic layer.