From 1cbf49355ea73edb5e1ca96a003c26a0f7d326ea Mon Sep 17 00:00:00 2001 From: Gonzalo Bulnes Guilpain Date: Wed, 25 Jan 2023 10:58:39 +1100 Subject: [PATCH] Refactor rename Disk.StatusLUKSEncrypted to StatusReachable --- securedrop_client/export/disk.py | 4 +-- .../gui/conversation/export/dialog.py | 2 +- tests/export/test_disk.py | 32 +++++++++---------- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/securedrop_client/export/disk.py b/securedrop_client/export/disk.py index 96d5be80eb..1042487c02 100644 --- a/securedrop_client/export/disk.py +++ b/securedrop_client/export/disk.py @@ -29,7 +29,7 @@ class Disk(QObject): Status = NewType("Status", str) StatusUnknown = Status("unknown-isw32") - StatusLUKSEncrypted = Status("luks-encrypted-8563d") + StatusReachable = Status("luks-encrypted-8563d") StatusUnreachable = Status("unreachable-ofbu4") def __init__( @@ -192,7 +192,7 @@ def _on_unknown_state_entered(self) -> None: @pyqtSlot() def _on_luks_encrypted_state_entered(self) -> None: - self._status = Disk.StatusLUKSEncrypted + self._status = Disk.StatusReachable @pyqtSlot() def _on_unreachable_state_entered(self) -> None: diff --git a/securedrop_client/gui/conversation/export/dialog.py b/securedrop_client/gui/conversation/export/dialog.py index 850ca4a8d1..2ee5f06f15 100644 --- a/securedrop_client/gui/conversation/export/dialog.py +++ b/securedrop_client/gui/conversation/export/dialog.py @@ -209,7 +209,7 @@ def _show_generic_error_message(self) -> None: @pyqtSlot() def _on_disk_status_changed(self) -> None: disk_status = self._export_disk.status - if disk_status == Disk.StatusLUKSEncrypted: + if disk_status == Disk.StatusReachable: self._on_export_preflight_check_succeeded() elif disk_status == Disk.StatusUnreachable: self._on_export_preflight_check_failed() diff --git a/tests/export/test_disk.py b/tests/export/test_disk.py index bec05ce421..1cfd15d401 100644 --- a/tests/export/test_disk.py +++ b/tests/export/test_disk.py @@ -20,7 +20,7 @@ class ExportService(QObject): export_failed = pyqtSignal(object) export_succeeded = pyqtSignal(object) - def __init__(self, responses=[Disk.StatusLUKSEncrypted]): + def __init__(self, responses=[Disk.StatusReachable]): super().__init__() self.responses = responses[:] @@ -42,7 +42,7 @@ def check_disk(self): response = self.responses.pop(0) # The disk is unreachable unless it's LUKS-encrypted. # Note that using the Disk.Status type is merely for convenience and readability. - if response == Disk.StatusLUKSEncrypted: + if response == Disk.StatusReachable: self.luks_encrypted_disk_found.emit() else: reason = object() # to comply with the Service API @@ -100,10 +100,10 @@ def test_export_service_responds_as_configured(self): client = ExportServiceClient() responses = [ "not LUKS-encrypted", # whatever - Disk.StatusLUKSEncrypted, - Disk.StatusLUKSEncrypted, - Disk.StatusUnreachable, # not Disk.StatusLUKSEncrypted - Disk.StatusLUKSEncrypted, + Disk.StatusReachable, + Disk.StatusReachable, + Disk.StatusUnreachable, # not Disk.StatusReachable + Disk.StatusReachable, # nothing else ] export_service = ExportService(responses) # override default responses @@ -165,9 +165,9 @@ def test_disk_status_is_unknown_by_default(self): def test_disk_status_tracks_export_service_responses_when_watched(self): responses = [ - Disk.StatusLUKSEncrypted, + Disk.StatusReachable, Disk.StatusUnreachable, - Disk.StatusLUKSEncrypted, + Disk.StatusReachable, ] export_service = ExportService(responses) @@ -205,7 +205,7 @@ def test_disk_status_tracks_export_service_responses_when_watched(self): "Expected exactly 1 query to the export service, and 1 response immediately after the disk started being watched.", # noqa: E501 ) self.assertEqual( - Disk.StatusLUKSEncrypted, + Disk.StatusReachable, disk.status, "Expected disk status to track the last response, did not.", ) @@ -239,7 +239,7 @@ def test_disk_status_tracks_export_service_responses_when_watched(self): "Expected exactly a total of 3 queries, and 3 responses after the polling interval elapsed.", # noqa: E501 ) self.assertEqual( - Disk.StatusLUKSEncrypted, + Disk.StatusReachable, disk.status, "Expected disk status to track the last response, did not.", ) @@ -258,9 +258,9 @@ def test_disk_status_tracks_export_service_responses_when_watched(self): def test_disk_status_stops_tracking_export_service_responses_when_not_watched(self): responses = [ - Disk.StatusLUKSEncrypted, + Disk.StatusReachable, Disk.StatusUnreachable, - Disk.StatusLUKSEncrypted, + Disk.StatusReachable, ] export_service = ExportService(responses) POLLING_INTERVAL = 100 # milliseconds @@ -295,7 +295,7 @@ def test_disk_status_stops_tracking_export_service_responses_when_not_watched(se "Expected exactly 1 query to the export service, and 1 response immediately after the disk started being watched.", # noqa: E501 ) self.assertEqual( - Disk.StatusLUKSEncrypted, + Disk.StatusReachable, disk.status, "Expected disk status to track the last response, did not.", ) @@ -345,9 +345,9 @@ def test_disk_signals_changes_in_disk_status(self): export_service.luks_encrypted_disk_found.emit() self.assertEqual( - Disk.StatusLUKSEncrypted, + Disk.StatusReachable, disk.status, - "Expected disk status to become Disk.StatusLUKSEncrypted, did not.", + "Expected disk status to become Disk.StatusReachable, did not.", ) self.assertEqual( 2, @@ -357,7 +357,7 @@ def test_disk_signals_changes_in_disk_status(self): export_service.luks_encrypted_disk_found.emit() self.assertEqual( - Disk.StatusLUKSEncrypted, + Disk.StatusReachable, disk.status, "Didn't expect any change in disk status.", )