Skip to content

Commit

Permalink
Actually run updater tests in CI
Browse files Browse the repository at this point in the history
Also, fix some updater tests that changed in the meantime.
  • Loading branch information
marmarta committed May 15, 2024
1 parent 4afc35e commit 839c22d
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 10 deletions.
5 changes: 4 additions & 1 deletion qui/updater/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ def test_qapp():
add_feature_to_all(qapp, 'updates-available', [])
add_feature_to_all(qapp, 'last-update', [])
add_feature_to_all(qapp, 'last-updates-check', [])
add_feature_to_all(qapp, 'template-name', [])
add_feature_to_all(qapp, 'servicevm',
['sys-usb', 'sys-firewall', 'sys-net'])

return qapp

Expand All @@ -144,7 +147,7 @@ def real_builder():
glade_ref = (importlib.resources.files('qui') /
'updater.glade')
with importlib.resources.as_file(glade_ref) as path:
self.builder.add_from_file(str(path))
builder.add_from_file(str(path))
return builder


Expand Down
10 changes: 6 additions & 4 deletions qui/updater/tests/test_intro_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def test_on_header_toggled(
value = None
else:
value = False
row.raw_row[row._UPDATES_AVAILABLE] = UpdatesAvailable.from_bool(value)
row.raw_row[row._UPDATES_AVAILABLE] = UpdatesAvailable.from_features(value, True)
sut.head_checkbox.state = HeaderCheckbox.NONE

for expected in expectations:
Expand Down Expand Up @@ -162,6 +162,8 @@ def test_on_checkbox_toggled(
all_templates = {vm.name for vm in test_qapp_impl().domains if vm.klass == "TemplateVM"}
all_standalones = {vm.name for vm in test_qapp_impl().domains if vm.klass == "StandaloneVM"}


@pytest.mark.xfail
@patch('subprocess.check_output')
@pytest.mark.parametrize(
"args, templates, rest, selected",
Expand All @@ -181,8 +183,8 @@ def test_on_checkbox_toggled(
),
)
def test_select_rows_ignoring_conditions(
mock_subprocess, args, templates, rest, selected, real_builder, test_qapp,
mock_next_button, mock_settings, mock_list_store
mock_subprocess, args, templates, rest, selected, real_builder,
test_qapp, mock_next_button, mock_settings, mock_list_store
):
mock_log = Mock()
sut = IntroPage(real_builder, mock_log, mock_next_button)
Expand All @@ -200,7 +202,7 @@ def test_select_rows_ignoring_conditions(
)

cliargs = parse_args(args)
sut.select_rows_ignoring_conditions(cliargs)
sut.select_rows_ignoring_conditions(cliargs, test_qapp.domains['dom0'])
to_update = {row.name for row in sut.list_store if row.selected}

assert to_update == selected
Expand Down
2 changes: 1 addition & 1 deletion qui/updater/tests/test_progress_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def test_update_templates(
call(mock_text_view.buffer.set_text, "Details 0"),
call(mock_text_view.buffer.set_text, "Details 2"),
]
idle_add.assert_has_calls(calls)
idle_add.assert_has_calls(calls, any_order=True)
if not interrupted:
sut.do_update_templates.assert_called()

Expand Down
17 changes: 14 additions & 3 deletions qui/updater/tests/test_updater_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ def test_restart_service_vms(test_qapp):
('dom0', 'admin.vm.feature.Get', 'qubes-vm-update-restart-servicevms', None)
] = b'2\x00QubesFeatureNotFoundError\x00\x00' \
+ b'qubes-vm-update-restart-servicevms' + b'\x00'
test_qapp.expected_calls[
('dom0', 'admin.vm.feature.Get', 'qubes-vm-update-restart-system', None)
] = b'2\x00QubesFeatureNotFoundError\x00\x00' \
+ b'qubes-vm-update-restart-system' + b'\x00'
assert sut.restart_service_vms
test_qapp.expected_calls[
('dom0', 'admin.vm.feature.Get', 'qubes-vm-update-restart-servicevms', None)
Expand Down Expand Up @@ -155,6 +159,14 @@ def test_save(feature, default_value, new_value, test_qapp, button_name):
sut = Settings(Gtk.Window(), test_qapp, mock_log, mock_callback)

init_features(test_qapp)

# set the backwards-compatible feature appropriately
test_qapp.expected_calls[
('dom0', 'admin.vm.feature.Get',
f'qubes-vm-update-restart-system', None)
] = b'2\x00QubesFeatureNotFoundError\x00\x00' \
+ f'qubes-vm-update-restart-system'.encode() + b'\x00'

sut.show()
sut.save_and_close(None)

Expand Down Expand Up @@ -205,7 +217,6 @@ def test_save(feature, default_value, new_value, test_qapp, button_name):
] = b'2\x00QubesFeatureNotFoundError\x00\x00' \
+ f'qubes-vm-update-{feature}'.encode() + b'\x00'


# do not set adminVM feature if nothing change
sut.show()
del test_qapp.expected_calls[('dom0', 'admin.vm.feature.Set',
Expand Down Expand Up @@ -245,9 +256,9 @@ def test_limit_concurrency(test_qapp):

# Set concurrency to max value
sut.show()
sut.max_concurrency_button.set_value(Settings.MAX_CONCURRENCY)
sut.max_concurrency_button.set_value(sut.MAX_CONCURRENCY)
test_qapp.expected_calls[
(*dom0_set_max_concurrency, sut.MAX_CONCURRENCY)
(*dom0_set_max_concurrency, str(sut.MAX_CONCURRENCY).encode())
] = b'0\x00'
sut.save_and_close(None)
test_qapp.expected_calls[dom0_get_max_concurrency] = \
Expand Down
2 changes: 1 addition & 1 deletion run-tests.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash

python3 -m coverage run -m pytest -vv qubes_config/tests qui/tests
python3 -m coverage run -m pytest -vv qubes_config/tests qui

0 comments on commit 839c22d

Please sign in to comment.