diff --git a/securedrop_client/export/disk.py b/securedrop_client/export/disk.py index c42159dc3..96d5be80e 100644 --- a/securedrop_client/export/disk.py +++ b/securedrop_client/export/disk.py @@ -24,8 +24,8 @@ class Disk(QObject): export_done = pyqtSignal() export_failed = pyqtSignal() - client_connected = pyqtSignal() - last_client_disconnected = pyqtSignal() + client_started_watching = pyqtSignal() + last_client_stopped_watching = pyqtSignal() Status = NewType("Status", str) StatusUnknown = Status("unknown-isw32") @@ -57,8 +57,8 @@ def __init__( self._poller.wait_on(self._export_service.luks_encrypted_disk_found) self._poller.wait_on(self._export_service.luks_encrypted_disk_not_found) - self._poller.start_on(self.client_connected) - self._poller.pause_on(self.last_client_disconnected) + self._poller.start_on(self.client_started_watching) + self._poller.pause_on(self.last_client_stopped_watching) self._export_service.luks_encrypted_disk_not_found.connect( lambda error: self._on_luks_encrypted_disk_not_found(error) @@ -75,15 +75,15 @@ def last_error(self) -> Optional[CLIError]: return self._last_error # FIXME Returning the CLIError type is an abstraction leak. @pyqtSlot() - def connect(self) -> None: + def watch(self) -> None: self._connected_clients += 1 - self.client_connected.emit() + self.client_started_watching.emit() @pyqtSlot() - def disconnect(self) -> None: + def stop_watching(self) -> None: self._connected_clients -= 1 if self._connected_clients < 1: - self.last_client_disconnected.emit() + self.last_client_stopped_watching.emit() def export_on(self, signal: pyqtBoundSignal) -> None: """Allow to export files, in a thread-safe manner.""" diff --git a/securedrop_client/export/printer.py b/securedrop_client/export/printer.py index 549fb1965..734be5dd3 100644 --- a/securedrop_client/export/printer.py +++ b/securedrop_client/export/printer.py @@ -28,8 +28,8 @@ class Printer(QObject): job_done = pyqtSignal() job_failed = pyqtSignal() - client_connected = pyqtSignal() - last_client_disconnected = pyqtSignal() + client_started_watching = pyqtSignal() + last_client_stopped_watching = pyqtSignal() Status = NewType("Status", str) StatusUnknown = Status("unknown-sf5fd") @@ -61,8 +61,8 @@ def __init__( self._poller.wait_on(self._printing_service.printer_not_found_ready) self._poller.wait_on(self._printing_service.printer_found_ready) - self._poller.start_on(self.client_connected) - self._poller.pause_on(self.last_client_disconnected) + self._poller.start_on(self.client_started_watching) + self._poller.pause_on(self.last_client_stopped_watching) # The printing service is not up-to-date on the printing queue terminology. self._printing_service.printer_not_found_ready.connect( @@ -80,15 +80,15 @@ def last_error(self) -> Optional[CLIError]: return self._last_error # FIXME Returning the CLIError type is an abstraction leak. @pyqtSlot() - def connect(self) -> None: + def watch(self) -> None: self._connected_clients += 1 - self.client_connected.emit() + self.client_started_watching.emit() @pyqtSlot() - def disconnect(self) -> None: + def stop_watching(self) -> None: self._connected_clients -= 1 if self._connected_clients < 1: - self.last_client_disconnected.emit() + self.last_client_stopped_watching.emit() def enqueue_job_on(self, signal: pyqtBoundSignal) -> None: """Allow to enqueue printing jobs, in a thread-safe manner.""" diff --git a/tests/export/test_disk.py b/tests/export/test_disk.py index 7dc688058..bec05ce42 100644 --- a/tests/export/test_disk.py +++ b/tests/export/test_disk.py @@ -163,7 +163,7 @@ def test_disk_status_is_unknown_by_default(self): self.assertEqual(Disk.StatusUnknown, disk.status) - def test_disk_status_tracks_export_service_responses_when_connected(self): + def test_disk_status_tracks_export_service_responses_when_watched(self): responses = [ Disk.StatusLUKSEncrypted, Disk.StatusUnreachable, @@ -186,7 +186,7 @@ def test_disk_status_tracks_export_service_responses_when_connected(self): self.assertEqual( 0, len(export_service_response), - "Expected export service to receive no queries before the disk is connected, and emit no responses.", # noqa: E501 + "Expected export service to receive no queries before the disk is being watched, and emit no responses.", # noqa: E501 ) self.assertEqual( Disk.StatusUnknown, @@ -194,7 +194,7 @@ def test_disk_status_tracks_export_service_responses_when_connected(self): "Expected default disk status to be Disk.StatusUnknown, was not.", ) - disk.connect() # Action! + disk.watch() # Action! # The first query should be issued immediately. # After that, the dummy export service responds blazing fast. @@ -202,7 +202,7 @@ def test_disk_status_tracks_export_service_responses_when_connected(self): self.assertEqual( 1, len(export_service_response), - "Expected exactly 1 query to the export service, and 1 response immediately after the disk was connected.", # noqa: E501 + "Expected exactly 1 query to the export service, and 1 response immediately after the disk started being watched.", # noqa: E501 ) self.assertEqual( Disk.StatusLUKSEncrypted, @@ -256,7 +256,7 @@ def test_disk_status_tracks_export_service_responses_when_connected(self): "Expected disk status to track the last response, did not.", ) - def test_disk_status_stops_tracking_export_service_responses_when_disconnected(self): + def test_disk_status_stops_tracking_export_service_responses_when_not_watched(self): responses = [ Disk.StatusLUKSEncrypted, Disk.StatusUnreachable, @@ -276,7 +276,7 @@ def test_disk_status_stops_tracking_export_service_responses_when_disconnected(s self.assertEqual( 0, len(export_service_response), - "Expected export service to receive no queries before the disk is connected, and emit no responses.", # noqa: E501 + "Expected export service to receive no queries before the disk is being watched, and emit no responses.", # noqa: E501 ) self.assertEqual( Disk.StatusUnknown, @@ -284,7 +284,7 @@ def test_disk_status_stops_tracking_export_service_responses_when_disconnected(s "Expected default disk status to be Disk.StatusUnknown, was not.", ) - disk.connect() # Action! + disk.watch() # Action! # The first query should be issued immediately. # After that, the dummy export service responds blazing fast. @@ -292,7 +292,7 @@ def test_disk_status_stops_tracking_export_service_responses_when_disconnected(s self.assertEqual( 1, len(export_service_response), - "Expected exactly 1 query to the export service, and 1 response immediately after the disk was connected.", # noqa: E501 + "Expected exactly 1 query to the export service, and 1 response immediately after the disk started being watched.", # noqa: E501 ) self.assertEqual( Disk.StatusLUKSEncrypted, @@ -300,24 +300,24 @@ def test_disk_status_stops_tracking_export_service_responses_when_disconnected(s "Expected disk status to track the last response, did not.", ) - disk.disconnect() + disk.stop_watching() self.assertEqual( Disk.StatusUnknown, disk.status, - "Expected disk status to become unknown as soon as disconnected.", + "Expected disk status to become unknown as soon as stopped being watched.", ) export_service_response.wait(POLLING_INTERVAL + CHECK_EXECUTION_TIME) # will time out self.assertEqual( 1, len(export_service_response), - "Expected no new query to the export service after disconnection (total 1 query and 1 response)", # noqa: E501 + "Expected no new query to the export service after the disk stopped being watched (total 1 query and 1 response)", # noqa: E501 ) self.assertEqual( Disk.StatusUnknown, disk.status, - "Expected disk status to remain unknown until reconnected.", + "Expected disk status to remain unknown until being watched again.", ) def test_disk_signals_changes_in_disk_status(self): @@ -381,19 +381,20 @@ def test_disk_signals_changes_in_disk_status(self): ) # This last segment is admittedly awkward. We want to make sure that - # the signal is emitted when pausing the disk. Even though the disk connection - # is not the point of this test, we do have to connect to be able to disconnect it. + # the signal is emitted when pausing the disk. Even though the disk watching + # is not the point of this test, we do have to watch in order to be able + # to stop watching it. # - # The connection triggers a query to the disk_service. To ensure that - # connecting the disk doesn't have any visible side-effects, the dummy service + # Watching triggers a query to the disk_service. To ensure that + # watching the disk doesn't have any visible side-effects, the dummy service # is configured to respond that the disk wasn't found LUKS-encrypted. - disk.connect() - disk.disconnect() + disk.watch() + disk.stop_watching() disk_status_changed_emissions.wait(POLLING_INTERVAL) self.assertEqual( Disk.StatusUnknown, disk.status, - "Expected disk status to become Disk.StatusUnknown as soon as disconnected, was not.", # noqa: E501 + "Expected disk status to become Disk.StatusUnknown as soon as not being watched, was not.", # noqa: E501 ) self.assertEqual( 4, diff --git a/tests/export/test_printer.py b/tests/export/test_printer.py index ab775bc57..11fa69eb2 100644 --- a/tests/export/test_printer.py +++ b/tests/export/test_printer.py @@ -155,7 +155,7 @@ def test_printer_status_is_unknown_by_default(self): self.assertEqual(Printer.StatusUnknown, printer.status) - def test_printer_status_tracks_printing_service_responses_when_connected(self): + def test_printer_status_tracks_printing_service_responses_when_watched(self): responses = [ Printer.StatusReady, Printer.StatusUnreachable, @@ -184,10 +184,10 @@ def test_printer_status_tracks_printing_service_responses_when_connected(self): self.assertEqual( 0, len(printing_service_response), - "Expected printing service to receive no queries before the printer is connected, and emit no responses.", # noqa: E501 + "Expected printing service to receive no queries before the printer is being watched, and emit no responses.", # noqa: E501 ) - printer.connect() # Action! + printer.watch() # Action! # The first query should be issued immediately. # After that, the dummy printing service responds blazing fast. @@ -195,7 +195,7 @@ def test_printer_status_tracks_printing_service_responses_when_connected(self): self.assertEqual( 1, len(printing_service_response), - "Expected exactly 1 query to the printing service, and 1 response immediately after the printer was connected.", # noqa: E501 + "Expected exactly 1 query to the printing service, and 1 response immediately after the printer started being watched.", # noqa: E501 ) self.assertEqual( Printer.StatusReady, @@ -249,7 +249,7 @@ def test_printer_status_tracks_printing_service_responses_when_connected(self): "Expected printer status to track the last response, did not.", ) - def test_printer_status_stops_tracking_printing_service_responses_when_disconnected(self): + def test_printer_status_stops_tracking_printing_service_responses_when_not_watched(self): responses = [ Printer.StatusReady, Printer.StatusUnreachable, @@ -275,10 +275,10 @@ def test_printer_status_stops_tracking_printing_service_responses_when_disconnec self.assertEqual( 0, len(printing_service_response), - "Expected printing service to receive no queries before the printer is connected, and emit no responses.", # noqa: E501 + "Expected printing service to receive no queries before the printer is watched, and emit no responses.", # noqa: E501 ) - printer.connect() # Action! + printer.watch() # Action! # The first query should be issued immediately. # After that, the dummy printing service responds blazing fast. @@ -286,7 +286,7 @@ def test_printer_status_stops_tracking_printing_service_responses_when_disconnec self.assertEqual( 1, len(printing_service_response), - "Expected exactly 1 query to the printing service, and 1 response immediately after the printer was connected.", # noqa: E501 + "Expected exactly 1 query to the printing service, and 1 response immediately after the printer started being watched.", # noqa: E501 ) self.assertEqual( Printer.StatusReady, @@ -294,24 +294,24 @@ def test_printer_status_stops_tracking_printing_service_responses_when_disconnec "Expected printer status to track the last response, did not.", ) - printer.disconnect() + printer.stop_watching() self.assertEqual( Printer.StatusUnknown, printer.status, - "Expected printer status to become unknown as soon as disconnected.", + "Expected printer status to become unknown as soon as watching stopped.", ) printing_service_response.wait(POLLING_INTERVAL + CHECK_EXECUTION_TIME) # will time out self.assertEqual( 1, len(printing_service_response), - "Expected no new query to the printing service after disconnection (total 1 query and 1 response)", # noqa: E501 + "Expected no new query to the printing service after watching has stopped (total 1 query and 1 response)", # noqa: E501 ) self.assertEqual( Printer.StatusUnknown, printer.status, - "Expected printer status to remain unknown until reconnected.", + "Expected printer status to remain unknown until being watched again.", ) def test_printer_signals_changes_in_printer_status(self): @@ -375,19 +375,20 @@ def test_printer_signals_changes_in_printer_status(self): ) # This last segment is admittedly awkward. We want to make sure that - # the signal is emitted when pausing the printer. Even though the printer connection - # is not the point of this test, we do have to connect to be able to disconnect it. + # the signal is emitted when pausing the printer. Even though the printer watching + # is not the point of this test, we do have to watch in order to be able + # to stop watching it. # - # The connection triggers a query to the printer_service. To ensure that - # connecting the printer doesn't have any visible side-effects, the dummy service + # Watching triggers a query to the printer_service. To ensure that + # watching the printer doesn't have any visible side-effects, the dummy service # is configured to respond that the printer wasn't found ready. - printer.connect() - printer.disconnect() + printer.watch() + printer.stop_watching() printer_status_changed_emissions.wait(POLLING_INTERVAL) self.assertEqual( Printer.StatusUnknown, printer.status, - "Expected printer status to become Printer.StatusUnknown as soon as disconnected, was not.", # noqa: E501 + "Expected printer status to become Printer.StatusUnknown as soon as watching stopped, was not.", # noqa: E501 ) self.assertEqual( 4,