Skip to content

Commit

Permalink
(WIP) Add functional tests for Export Wizard
Browse files Browse the repository at this point in the history
  • Loading branch information
rocodes committed Feb 5, 2024
1 parent 13c5e24 commit 27525f5
Show file tree
Hide file tree
Showing 8 changed files with 1,924 additions and 152 deletions.
104 changes: 99 additions & 5 deletions client/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from configparser import ConfigParser
from datetime import datetime
from uuid import uuid4
from unittest import mock

import pytest
from PyQt5.QtCore import Qt
Expand All @@ -22,6 +23,7 @@
Source,
make_session_maker,
)
from securedrop_client.export_status import ExportStatus
from securedrop_client.gui import conversation
from securedrop_client.gui.main import Window
from securedrop_client.logic import Controller
Expand All @@ -47,7 +49,7 @@
TIME_CLICK_ACTION = 1000
TIME_RENDER_SOURCE_LIST = 20000
TIME_RENDER_CONV_VIEW = 1000
TIME_RENDER_EXPORT_DIALOG = 1000
TIME_RENDER_EXPORT_WIZARD = 1000
TIME_FILE_DOWNLOAD = 5000


Expand Down Expand Up @@ -168,13 +170,105 @@ def homedir(i18n):


@pytest.fixture(scope="function")
def mock_export():
def mock_export_locked():
"""
Represents the following scenario:
* Locked USB already inserted
* "Export" clicked, export wizard launched
* Passphrase successfully entered on first attempt (and export suceeeds)
"""
device = conversation.ExportDevice()

device.run_export_preflight_checks = lambda: device.export_state_changed.emit(
ExportStatus.DEVICE_LOCKED
)
device.run_printer_preflight_checks = lambda: None
device.print = lambda filepaths: None
device.export = mock.MagicMock()
device.export.side_effect = [
lambda filepaths, passphrase: device.export_state_changed.emit(
ExportStatus.DEVICE_WRITABLE
),
lambda filepaths, passphrase: device.export_state_changed.emit(ExportStatus.SUCCESS_EXPORT),
]

return device


@pytest.fixture(scope="function")
def mock_export_unlocked():
"""
Represents the following scenario:
* USB already inserted and unlocked by the user
* Export wizard launched
* Export succeeds
"""
device = conversation.ExportDevice()

device.run_export_preflight_checks = lambda: device.export_state_changed.emit(
ExportStatus.DEVICE_WRITABLE
)
device.run_printer_preflight_checks = lambda: None
device.print = lambda filepaths: None
device.export = lambda filepaths, passphrase: device.export_state_changed.emit(
ExportStatus.SUCCESS_EXPORT
)

return device


@pytest.fixture(scope="function")
def mock_export_no_usb_then_bad_passphrase_then_fail():
"""
Represents the following scenario:
* Export wizard launched
* Locked USB inserted
* Mistyped Passphrase
* Correct passphrase
* Export fails
"""
device = conversation.ExportDevice()

device.run_export_preflight_checks = lambda: device.export_state_changed.emit(
ExportStatus.NO_DEVICE_DETECTED
)
device.run_printer_preflight_checks = lambda: None
device.print = lambda filepaths: None
device.export = mock.MagicMock()
device.export.side_effect = [
lambda filepaths, passphrase: device.export_state_changed.emit(ExportStatus.DEVICE_LOCKED),
lambda filepaths, passphrase: device.export_state_changed.emit(
ExportStatus.ERROR_UNLOCK_LUKS
),
lambda filepaths, passphrase: device.export_state_changed.emit(
ExportStatus.DEVICE_WRITABLE
),
lambda filepaths, passphrase: device.export_state_changed.emit(ExportStatus.ERROR_EXPORT),
]

return device


@pytest.fixture(scope="function")
def mock_export_fail_early():
"""
Represents the following scenario:
* Locked USB inserted
* Export wizard launched
* Unrecoverable error before export happens
(eg, mount error)
"""
device = conversation.ExportDevice()

device.run_export_preflight_checks = lambda dir: None
device.run_printer_preflight_checks = lambda dir: None
device.run_export_preflight_checks = lambda: device.export_state_changed.emit(
ExportStatus.DEVICE_LOCKED
)
device.run_printer_preflight_checks = lambda: None
device.print = lambda filepaths: None
device.export = lambda filepaths, passphrase: None
device.export = mock.MagicMock()
device.export = lambda filepaths, passphrase: device.export_state_changed.emit(
ExportStatus.ERROR_MOUNT
)

return device

Expand Down
1,518 changes: 1,518 additions & 0 deletions client/tests/functional/cassettes/test_export_wizard_no_device_then_fail.yaml

Large diffs are not rendered by default.

123 changes: 0 additions & 123 deletions client/tests/functional/test_export_file_dialog.py

This file was deleted.

Loading

0 comments on commit 27525f5

Please sign in to comment.