Skip to content

Commit

Permalink
yeeeeeeeeeeeeeeeeeeeee
Browse files Browse the repository at this point in the history
  • Loading branch information
heartsucker committed May 21, 2019
1 parent 4d87371 commit 2f1639b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 36 deletions.
29 changes: 11 additions & 18 deletions securedrop_client/gui/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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:
Expand All @@ -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():
Expand Down
1 change: 0 additions & 1 deletion securedrop_client/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
18 changes: 1 addition & 17 deletions tests/gui/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1139,30 +1139,14 @@ 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)
assert isinstance(fw.layout.takeAt(0), QSpacerItem)
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.
Expand Down

0 comments on commit 2f1639b

Please sign in to comment.