Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing and incorrect assertions in Controller tests #1501

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions securedrop_client/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,7 @@ def call_api( # type: ignore [no-untyped-def]
):
"""
Calls the function in a non-blocking manner. Upon completion calls the
callback with the result. Calls timeout if the timer associated with
the call emits a timeout signal. Any further arguments are passed to
callback with the result. Any further arguments are passed to
the function to be called.
"""
new_thread_id = str(uuid.uuid4()) # Uniquely id the new thread.
Expand Down
38 changes: 19 additions & 19 deletions tests/test_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ def test_Controller_call_api(homedir, config, mocker, session_maker):
thread.started.connect.assert_called_once_with(runner.call_api)
thread.start.assert_called_once_with()
runner.moveToThread.assert_called_once_with(thread)
runner.call_succeeded.connect.call_count == 1
runner.call_failed.connect.call_count == 1
runner.call_timed_out.connect.call_count == 1
assert runner.call_succeeded.connect.call_count == 1
assert runner.call_failed.connect.call_count == 1
assert runner.call_timed_out.connect.call_count == 0


def test_Controller_login(homedir, config, mocker, session_maker):
Expand Down Expand Up @@ -1474,7 +1474,7 @@ def test_Controller_on_file_decryption_failure(homedir, config, mocker, session,
mock_file_ready.emit.assert_not_called()
mock_update_error_status.assert_called_once_with("The file download failed. Please try again.")

co._submit_download_job.call_count == 1
assert co._submit_download_job.call_count == 0
error_logger.call_args_list[0][0][0] == "Failed to decrypt {}".format(file_.uuid)

mock_set_status.assert_not_called()
Expand Down Expand Up @@ -1713,7 +1713,7 @@ def test_Controller_on_reply_downloaded_checksum_failure(mocker, homedir, sessio
reply_ready.emit.assert_not_called()

# Job should get resubmitted and we should log this is happening
co._submit_download_job.call_count == 1
assert co._submit_download_job.call_count == 1
warning_logger.call_args_list[0][0][
0
] == "Failure due to checksum mismatch, retrying {}".format(reply.uuid)
Expand Down Expand Up @@ -1906,7 +1906,7 @@ def test_Controller_on_message_downloaded_checksum_failure(mocker, homedir, sess
message_ready.emit.assert_not_called()

# Job should get resubmitted and we should log this is happening
co._submit_download_job.call_count == 1
assert co._submit_download_job.call_count == 1


def test_Controller_on_message_downloaded_decryption_failure(mocker, homedir, session_maker):
Expand Down Expand Up @@ -2378,7 +2378,7 @@ def test_Controller_run_printer_preflight_checks(homedir, mocker, session, sourc

co.run_printer_preflight_checks()

co.export.begin_printer_preflight.emit.call_count == 1
assert co.export.begin_printer_preflight.emit.call_count == 1


def test_Controller_run_printer_preflight_checks_not_qubes(homedir, mocker, session, source):
Expand All @@ -2392,8 +2392,8 @@ def test_Controller_run_printer_preflight_checks_not_qubes(homedir, mocker, sess

co.run_printer_preflight_checks()

co.export.begin_printer_preflight.emit.call_count == 0
co.export.printer_preflight_success.emit.call_count == 1
assert co.export.begin_printer_preflight.emit.call_count == 0
assert co.export.printer_preflight_success.emit.call_count == 1


def test_Controller_run_print_file(mocker, session, homedir):
Expand All @@ -2412,7 +2412,7 @@ def test_Controller_run_print_file(mocker, session, homedir):

co.print_file(file.uuid)

co.export.begin_print.emit.call_count == 1
assert co.export.begin_print.emit.call_count == 1


def test_Controller_run_print_file_not_qubes(mocker, session, homedir):
Expand All @@ -2433,7 +2433,7 @@ def test_Controller_run_print_file_not_qubes(mocker, session, homedir):

co.print_file(file.uuid)

co.export.begin_print.emit.call_count == 0
assert co.export.begin_print.emit.call_count == 0


def test_Controller_print_file_file_missing(homedir, mocker, session, session_maker):
Expand Down Expand Up @@ -2491,7 +2491,7 @@ def test_Controller_print_file_when_orig_file_already_exists(

co.print_file(file.uuid)

co.export.begin_print.emit.call_count == 1
assert co.export.begin_print.emit.call_count == 1
co.get_file.assert_called_with(file.uuid)


Expand All @@ -2518,7 +2518,7 @@ def test_Controller_print_file_when_orig_file_already_exists_not_qubes(

co.export_file_to_usb_drive(file.uuid, "mock passphrase")

co.export.begin_print.emit.call_count == 1
assert co.export.begin_print.emit.call_count == 0
co.get_file.assert_called_with(file.uuid)


Expand All @@ -2534,7 +2534,7 @@ def test_Controller_run_export_preflight_checks(homedir, mocker, session, source

co.run_export_preflight_checks()

co.export.begin_usb_export.emit.call_count == 1
assert co.export.begin_preflight_check.emit.call_count == 1


def test_Controller_run_export_preflight_checks_not_qubes(homedir, mocker, session, source):
Expand All @@ -2550,7 +2550,7 @@ def test_Controller_run_export_preflight_checks_not_qubes(homedir, mocker, sessi

co.run_export_preflight_checks()

co.export.begin_usb_export.emit.call_count == 0
assert co.export.begin_preflight_check.emit.call_count == 0


def test_Controller_export_file_to_usb_drive(homedir, mocker, session):
Expand All @@ -2573,7 +2573,7 @@ def test_Controller_export_file_to_usb_drive(homedir, mocker, session):

co.export_file_to_usb_drive(file.uuid, "mock passphrase")

co.export.begin_usb_export.emit.call_count == 1
assert co.export.begin_usb_export.emit.call_count == 1


def test_Controller_export_file_to_usb_drive_not_qubes(homedir, mocker, session):
Expand All @@ -2598,7 +2598,7 @@ def test_Controller_export_file_to_usb_drive_not_qubes(homedir, mocker, session)
co.export_file_to_usb_drive(file.uuid, "mock passphrase")

co.export.send_file_to_usb_device.assert_not_called()
co.export.begin_usb_export.emit.call_count == 0
assert co.export.begin_usb_export.emit.call_count == 0


def test_Controller_export_file_to_usb_drive_file_missing(homedir, mocker, session, session_maker):
Expand Down Expand Up @@ -2658,7 +2658,7 @@ def test_Controller_export_file_to_usb_drive_when_orig_file_already_exists(

co.export_file_to_usb_drive(file.uuid, "mock passphrase")

co.export.begin_usb_export.emit.call_count == 1
assert co.export.begin_usb_export.emit.call_count == 1
co.get_file.assert_called_with(file.uuid)


Expand All @@ -2685,7 +2685,7 @@ def test_Controller_export_file_to_usb_drive_when_orig_file_already_exists_not_q

co.export_file_to_usb_drive(file.uuid, "mock passphrase")

co.export.begin_usb_export.emit.call_count == 1
assert co.export.begin_usb_export.emit.call_count == 0
co.get_file.assert_called_with(file.uuid)


Expand Down