Skip to content

Commit

Permalink
fix mypy error default to empty string
Browse files Browse the repository at this point in the history
  • Loading branch information
Allie Crevier committed Feb 14, 2020
1 parent 54b1268 commit a271358
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 30 deletions.
2 changes: 1 addition & 1 deletion securedrop_client/gui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def __init__(self, filename: str, svg_size: str = None) -> None:
self.svg.setFixedSize(svg_size) if svg_size else self.svg.setFixedSize(QSize())
layout.addWidget(self.svg)

def update_image(self, filename, svg_size: str = None):
def update_image(self, filename: str, svg_size: str = None) -> None:
self.svg = load_svg(filename)
self.svg.setFixedSize(svg_size) if svg_size else self.svg.setFixedSize(QSize())
child = self.layout().takeAt(0)
Expand Down
31 changes: 16 additions & 15 deletions securedrop_client/gui/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
from uuid import uuid4
from PyQt5.QtCore import Qt, pyqtSlot, pyqtSignal, QEvent, QTimer, QSize, pyqtBoundSignal, \
QObject, QPoint
from PyQt5.QtGui import QIcon, QPalette, QBrush, QColor, QFont, QLinearGradient, QKeySequence
from PyQt5.QtGui import QIcon, QPalette, QBrush, QColor, QFont, QLinearGradient,QKeySequence, \
QCursor
from PyQt5.QtWidgets import QApplication, QListWidget, QLabel, QWidget, QListWidgetItem, \
QHBoxLayout, QVBoxLayout, QLineEdit, QScrollArea, QDialog, QAction, QMenu, QMessageBox, \
QToolButton, QSizePolicy, QPlainTextEdit, QStatusBar, QGraphicsDropShadowEffect, QPushButton, \
Expand Down Expand Up @@ -2048,7 +2049,7 @@ def _on_export_clicked(self):

if not self.dialog_in_progress:
self.dialog_in_progress = True
dialog = ExportDialog(self.controller, self.file.uuid, self.file.original_filename)
dialog = ExportDialog(self.controller, self.file.uuid, self.file.filename)
dialog.dialog_closing.connect(self._unset_dialog_in_progress)
dialog.exec()

Expand All @@ -2062,7 +2063,7 @@ def _on_print_clicked(self):

if not self.dialog_in_progress:
self.dialog_in_progress = True
dialog = PrintDialog(self.controller, self.file.uuid, self.file.original_filename)
dialog = PrintDialog(self.controller, self.file.uuid, self.file.filename)
dialog.dialog_closing.connect(self._unset_dialog_in_progress)
dialog.exec()

Expand Down Expand Up @@ -2305,7 +2306,7 @@ def __init__(self, controller: Controller, file_uuid: str, file_name: str):
self.controller = controller
self.file_uuid = file_uuid
self.file_name = file_name
self.error_status = None # Hold onto the error status we receive from the Export VM
self.error_status = '' # Hold onto the error status we receive from the Export VM

# Connect controller signals to slots
self.controller.export.printer_preflight_success.connect(self._on_preflight_success)
Expand Down Expand Up @@ -2432,7 +2433,7 @@ def __init__(self, controller: Controller, file_uuid: str, file_name: str):
self.controller = controller
self.file_uuid = file_uuid
self.file_name = file_name
self.error_status = None # Hold onto the error status we receive from the Export VM
self.error_status = '' # Hold onto the error status we receive from the Export VM

# Connect controller signals to slots
self.controller.export.preflight_check_call_success.connect(self._on_preflight_success)
Expand Down Expand Up @@ -2611,36 +2612,36 @@ def _on_preflight_success(self):

@pyqtSlot(object)
def _on_preflight_failure(self, error: ExportError):
self._update_dialog(error)
self._update_dialog(error.status)

@pyqtSlot()
def _on_export_success(self):
self._show_success_message()

@pyqtSlot(object)
def _on_export_failure(self, error: ExportError):
self._update_dialog(error)
self._update_dialog(error.status)

def _update_dialog(self, error: ExportStatus):
self.error_status = error.status
def _update_dialog(self, error_status: str):
self.error_status = error_status
# If the continue button is disabled then this is the result of a background preflight check
if not self.continue_button.isEnabled():
if error.status == ExportStatus.BAD_PASSPHRASE.value:
if self.error_status == ExportStatus.BAD_PASSPHRASE.value:
self.continue_button.clicked.connect(self._show_passphrase_request_message_again)
elif error.status == ExportStatus.USB_NOT_CONNECTED.value:
elif self.error_status == ExportStatus.USB_NOT_CONNECTED.value:
self.continue_button.clicked.connect(self._show_insert_usb_message)
elif error.status == ExportStatus.DISK_ENCRYPTION_NOT_SUPPORTED_ERROR.value:
elif self.error_status == ExportStatus.DISK_ENCRYPTION_NOT_SUPPORTED_ERROR.value:
self.continue_button.clicked.connect(self._show_insert_encrypted_usb_message)
else:
self.continue_button.clicked.connect(self._show_generic_error_message)

self.continue_button.setEnabled(True)
else:
if error.status == ExportStatus.BAD_PASSPHRASE.value:
if self.error_status == ExportStatus.BAD_PASSPHRASE.value:
self._show_passphrase_request_message_again()
elif error.status == ExportStatus.USB_NOT_CONNECTED.value:
elif self.error_status == ExportStatus.USB_NOT_CONNECTED.value:
self._show_insert_usb_message()
elif error.status == ExportStatus.DISK_ENCRYPTION_NOT_SUPPORTED_ERROR.value:
elif self.error_status == ExportStatus.DISK_ENCRYPTION_NOT_SUPPORTED_ERROR.value:
self._show_insert_encrypted_usb_message()
else:
self._show_generic_error_message()
Expand Down
26 changes: 12 additions & 14 deletions tests/gui/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -2082,7 +2082,7 @@ def test_ExportDialog__on_preflight_failure(mocker):
error = ExportError('mock_error_status')
dialog._on_preflight_failure(error)

dialog._update_dialog.assert_called_with(error)
dialog._update_dialog.assert_called_with('mock_error_status')


def test_ExportDialog__on_export_success(mocker):
Expand All @@ -2105,7 +2105,7 @@ def test_ExportDialog__on_export_failure(mocker):
error = ExportError('mock_error_status')
dialog._on_export_failure(error)

dialog._update_dialog.assert_called_with(error)
dialog._update_dialog.assert_called_with('mock_error_status')


def test_ExportDialog__update_dialog_when_status_is_USB_NOT_CONNECTED(mocker):
Expand All @@ -2118,12 +2118,12 @@ def test_ExportDialog__update_dialog_when_status_is_USB_NOT_CONNECTED(mocker):
mocker.patch.object(dialog.continue_button, 'isEnabled', return_value=False)

# When the continue button is enabled, ensure clicking continue will show next instructions
dialog._update_dialog(ExportError(ExportStatus.USB_NOT_CONNECTED.value))
dialog._update_dialog(ExportStatus.USB_NOT_CONNECTED.value)
dialog.continue_button.clicked.connect.assert_called_once_with(dialog._show_insert_usb_message)

# When the continue button is enabled, ensure next instructions are shown
mocker.patch.object(dialog.continue_button, 'isEnabled', return_value=True)
dialog._update_dialog(ExportError(ExportStatus.USB_NOT_CONNECTED.value))
dialog._update_dialog(ExportStatus.USB_NOT_CONNECTED.value)
dialog._show_insert_usb_message.assert_called_once_with()


Expand All @@ -2137,13 +2137,13 @@ def test_ExportDialog__update_dialog_when_status_is_BAD_PASSPHRASE(mocker):
mocker.patch.object(dialog.continue_button, 'isEnabled', return_value=False)

# When the continue button is enabled, ensure clicking continue will show next instructions
dialog._update_dialog(ExportError(ExportStatus.BAD_PASSPHRASE.value))
dialog._update_dialog(ExportStatus.BAD_PASSPHRASE.value)
dialog.continue_button.clicked.connect.assert_called_once_with(
dialog._show_passphrase_request_message_again)

# When the continue button is enabled, ensure next instructions are shown
mocker.patch.object(dialog.continue_button, 'isEnabled', return_value=True)
dialog._update_dialog(ExportError(ExportStatus.BAD_PASSPHRASE.value))
dialog._update_dialog(ExportStatus.BAD_PASSPHRASE.value)
dialog._show_passphrase_request_message_again.assert_called_once_with()


Expand All @@ -2157,15 +2157,13 @@ def test_ExportDialog__update_dialog_when_status_DISK_ENCRYPTION_NOT_SUPPORTED_E
mocker.patch.object(dialog.continue_button, 'isEnabled', return_value=False)

# When the continue button is enabled, ensure clicking continue will show next instructions
dialog._update_dialog(
ExportError(ExportStatus.DISK_ENCRYPTION_NOT_SUPPORTED_ERROR.value))
dialog._update_dialog(ExportStatus.DISK_ENCRYPTION_NOT_SUPPORTED_ERROR.value)
dialog.continue_button.clicked.connect.assert_called_once_with(
dialog._show_insert_encrypted_usb_message)

# When the continue button is enabled, ensure next instructions are shown
mocker.patch.object(dialog.continue_button, 'isEnabled', return_value=True)
dialog._update_dialog(ExportError(
ExportStatus.DISK_ENCRYPTION_NOT_SUPPORTED_ERROR.value))
dialog._update_dialog(ExportStatus.DISK_ENCRYPTION_NOT_SUPPORTED_ERROR.value)
dialog._show_insert_encrypted_usb_message.assert_called_once_with()


Expand All @@ -2179,14 +2177,14 @@ def test_ExportDialog__update_dialog_when_status_is_CALLED_PROCESS_ERROR(mocker)
mocker.patch.object(dialog.continue_button, 'isEnabled', return_value=False)

# When the continue button is enabled, ensure clicking continue will show next instructions
dialog._update_dialog(ExportError(ExportStatus.CALLED_PROCESS_ERROR.value))
dialog._update_dialog(ExportStatus.CALLED_PROCESS_ERROR.value)
dialog.continue_button.clicked.connect.assert_called_once_with(
dialog._show_generic_error_message)
assert dialog.error_status == ExportStatus.CALLED_PROCESS_ERROR.value

# When the continue button is enabled, ensure next instructions are shown
mocker.patch.object(dialog.continue_button, 'isEnabled', return_value=True)
dialog._update_dialog(ExportError(ExportStatus.CALLED_PROCESS_ERROR.value))
dialog._update_dialog(ExportStatus.CALLED_PROCESS_ERROR.value)
dialog._show_generic_error_message.assert_called_once_with()
assert dialog.error_status == ExportStatus.CALLED_PROCESS_ERROR.value

Expand All @@ -2201,14 +2199,14 @@ def test_ExportDialog__update_dialog_when_status_is_unknown(mocker):
mocker.patch.object(dialog.continue_button, 'isEnabled', return_value=False)

# When the continue button is enabled, ensure clicking continue will show next instructions
dialog._update_dialog(ExportError('Some Unknown Error Status'))
dialog._update_dialog('Some Unknown Error Status')
dialog.continue_button.clicked.connect.assert_called_once_with(
dialog._show_generic_error_message)
assert dialog.error_status == 'Some Unknown Error Status'

# When the continue button is enabled, ensure next instructions are shown
mocker.patch.object(dialog.continue_button, 'isEnabled', return_value=True)
dialog._update_dialog(ExportError('Some Unknown Error Status'))
dialog._update_dialog('Some Unknown Error Status')
dialog._show_generic_error_message.assert_called_once_with()
assert dialog.error_status == 'Some Unknown Error Status'

Expand Down

0 comments on commit a271358

Please sign in to comment.