Skip to content

Commit

Permalink
WIP Add tests: CLI interface of export.Service
Browse files Browse the repository at this point in the history
  • Loading branch information
gonzalo-bulnes committed Dec 5, 2022
1 parent db640a3 commit d3621a7
Showing 1 changed file with 38 additions and 2 deletions.
40 changes: 38 additions & 2 deletions tests/export/test_service.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import unittest
from unittest.mock import patch
from unittest.mock import MagicMock, patch

import pytest
from PyQt5.QtTest import QSignalSpy

from securedrop_client import export
Expand Down Expand Up @@ -60,4 +61,39 @@ def test_emits_printer_not_found_ready_when_printer_status_check_fails(
assert len(printer_not_found_ready_emissions) == 1
assert printer_not_found_ready_emissions[0] == [expected_error]

# FIXME Add disk API tests

class TestExportServiceInterfaceWithCLI(unittest.TestCase):
def test_internal_printer_status_check_returns_without_errors_when_empty_response(self):
SUCCESS_STATUS = "" # sd-devices API
export_service = export.Service()
valid_archive_path = "archive_path_13kn3"
export_service._create_archive = MagicMock()
export_service._export_archive = MagicMock(return_value=SUCCESS_STATUS)

export_service._check_printer_status(valid_archive_path) # testing internal details

assert True # no exception was raised

def test_internal_printer_status_check_exports_a_specifically_created_archive(self):
expected_archive_path = "archive_path_9f483f"
expected_archive_dir = "archive_dir_2i19c"
export_service = export.Service()
export_service._create_archive = MagicMock(return_value=expected_archive_path)
export_service._export_archive = MagicMock(return_value="") # "magic" value

export_service._check_printer_status(expected_archive_dir) # testing internal details

export_service._export_archive.assert_called_once_with(expected_archive_path)
export_service._create_archive.assert_called_once_with(
expected_archive_dir, "printer-preflight.sd-export", {"device": "printer-preflight"}
)

def test_internal_printer_status_check_raises_export_error_when_not_USB_CONNECTED(self):
not_USB_CONNECTED = "whatever"
valid_archive_path = "archive_path_034d3"
export_service = export.Service()
export_service._create_archive = MagicMock()
export_service._export_archive = MagicMock(return_value=not_USB_CONNECTED)

with pytest.raises(export.ExportError):
export_service._check_printer_status(valid_archive_path) # testing internal details

0 comments on commit d3621a7

Please sign in to comment.