Skip to content

Commit b237806

Browse files
committed
Fix updater tests for new mocks
1 parent 23e70bb commit b237806

3 files changed

Lines changed: 34 additions & 178 deletions

File tree

qui/updater/tests/conftest.py

Lines changed: 20 additions & 167 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,9 @@
2222
import pytest
2323
import importlib.resources
2424

25-
from qubes_config.tests.conftest import (
26-
add_dom0_vm_property,
27-
add_dom0_text_property,
28-
add_dom0_feature,
29-
add_expected_vm,
30-
add_feature_with_template_to_all,
31-
add_feature_to_all,
32-
)
33-
from qubesadmin.tests import QubesTest
34-
3525
import gi
3626

27+
from qubesadmin.tests.mock_app import MockQube, MockQubesComplete
3728
from qui.updater.intro_page import UpdateRowWrapper
3829
from qui.updater.summary_page import RestartRowWrapper
3930
from qui.updater.utils import ListWrapper
@@ -45,170 +36,32 @@
4536

4637
@pytest.fixture
4738
def test_qapp():
48-
return test_qapp_impl()
49-
50-
51-
def test_qapp_impl():
52-
"""Test QubesApp"""
53-
qapp = QubesTest()
54-
qapp._local_name = "dom0" # pylint: disable=protected-access
55-
56-
add_dom0_vm_property(qapp, "clockvm", "sys-net")
57-
add_dom0_vm_property(qapp, "updatevm", "sys-net")
58-
add_dom0_vm_property(qapp, "default_netvm", "sys-net")
59-
add_dom0_vm_property(qapp, "default_template", "fedora-36")
60-
add_dom0_vm_property(qapp, "default_dispvm", "fedora-36")
61-
62-
add_dom0_text_property(qapp, "default_kernel", "1.1")
63-
add_dom0_text_property(qapp, "default_pool", "file")
64-
65-
add_dom0_feature(qapp, "gui-default-allow-fullscreen", "")
66-
add_dom0_feature(qapp, "gui-default-allow-utf8-titles", "")
67-
add_dom0_feature(qapp, "gui-default-trayicon-mode", "")
68-
add_dom0_feature(qapp, "qubes-vm-update-update-if-stale", None)
69-
add_dom0_feature(qapp, "skip-update", None)
70-
add_dom0_feature(qapp, "qubes-vm-update-hide-skipped", None)
71-
add_dom0_feature(qapp, "qubes-vm-update-hide-updated", None)
72-
73-
# setup labels
74-
qapp.expected_calls[("dom0", "admin.label.List", None, None)] = (
75-
b"0\x00red\nblue\ngreen\n"
76-
)
77-
78-
# setup pools:
79-
qapp.expected_calls[("dom0", "admin.pool.List", None, None)] = (
80-
b"0\x00linux-kernel\nlvm\nfile\n"
81-
)
82-
qapp.expected_calls[("dom0", "admin.pool.volume.List", "linux-kernel", None)] = (
83-
b"0\x001.1\nmisc\n4.2\n"
84-
)
85-
86-
add_expected_vm(
87-
qapp,
88-
"dom0",
89-
"AdminVM",
90-
{},
91-
{
92-
"service.qubes-update-check": 1,
93-
"config.default.qubes-update-check": None,
94-
"config-usbvm-name": None,
95-
"gui-default-secure-copy-sequence": None,
96-
"gui-default-secure-paste-sequence": None,
39+
qapp = MockQubesComplete()
40+
qapp._qubes["fedora-35"].updateable = True
41+
qapp._qubes["fedora-36"] = MockQube(
42+
name="fedora-36",
43+
qapp=qapp,
44+
klass="TemplateVM",
45+
netvm="",
46+
updateable=True,
47+
installed_by_rpm=True,
48+
features={
49+
"supported-service.qubes-u2f-proxy": "1",
50+
"service.qubes-update-check": "1",
51+
"service.updates-proxy-setup": "1",
9752
},
98-
[],
99-
)
100-
add_expected_vm(
101-
qapp,
102-
"sys-net",
103-
"AppVM",
104-
{"provides_network": ("bool", False, "True")},
105-
{"service.qubes-update-check": None, "service.qubes-updates-proxy": 1},
106-
[],
107-
)
108-
109-
add_expected_vm(
110-
qapp,
111-
"sys-firewall",
112-
"AppVM",
113-
{"provides_network": ("bool", False, "True")},
114-
{"service.qubes-update-check": None},
115-
[],
116-
)
117-
118-
add_expected_vm(
119-
qapp, "sys-usb", "AppVM", {}, {"service.qubes-update-check": None}, []
12053
)
12154

122-
add_expected_vm(
123-
qapp,
124-
"fedora-36",
125-
"TemplateVM",
126-
{"netvm": ("vm", False, ""), "updateable": ("bool", True, "True")},
127-
{"service.qubes-update-check": None},
128-
[],
129-
)
55+
qapp._qubes["fedora-35"].features["updates-available"] = ""
13056

131-
add_expected_vm(
132-
qapp,
133-
"fedora-35",
134-
"TemplateVM",
135-
{"netvm": ("vm", False, ""), "updateable": ("bool", True, "True")},
136-
{"service.qubes-update-check": None},
137-
[],
138-
)
57+
qapp._qubes["test-standalone"].updateable = True
13958

140-
add_expected_vm(
141-
qapp,
142-
"default-dvm",
143-
"DispVM",
144-
{
145-
"template_for_dispvms": ("bool", False, "True"),
146-
"auto_cleanup": ("bool", False, "False"),
147-
},
148-
{"service.qubes-update-check": None},
149-
[],
150-
)
151-
152-
add_expected_vm(
153-
qapp, "test-vm", "AppVM", {}, {"service.qubes-update-check": None}, []
154-
)
155-
156-
add_expected_vm(
157-
qapp,
158-
"test-blue",
159-
"AppVM",
160-
{"label": ("str", False, "blue")},
161-
{"service.qubes-update-check": None},
162-
[],
163-
)
164-
165-
add_expected_vm(
166-
qapp,
167-
"test-red",
168-
"AppVM",
169-
{"label": ("str", False, "red")},
170-
{"service.qubes-update-check": None},
171-
[],
172-
)
173-
174-
add_expected_vm(
175-
qapp,
176-
"test-standalone",
177-
"StandaloneVM",
178-
{
179-
"label": ("str", False, "green"),
180-
"updateable": ("bool", True, "True"),
181-
},
182-
{"service.qubes-update-check": None},
183-
[],
184-
)
185-
186-
add_expected_vm(
187-
qapp,
188-
"vault",
189-
"AppVM",
190-
{"netvm": ("vm", False, "")},
191-
{"service.qubes-update-check": None},
192-
[],
193-
)
59+
qapp.update_vm_calls()
60+
return qapp
19461

195-
add_feature_with_template_to_all(
196-
qapp,
197-
"supported-service.qubes-u2f-proxy",
198-
["test-vm", "fedora-35", "sys-usb"],
199-
)
200-
add_feature_to_all(qapp, "service.qubes-u2f-proxy", ["test-vm"])
201-
add_feature_to_all(qapp, "restart-after-update", [])
202-
add_feature_to_all(qapp, "updates-available", [])
203-
add_feature_to_all(qapp, "last-update", [])
204-
add_feature_to_all(qapp, "last-updates-check", [])
205-
add_feature_to_all(qapp, "template-name", [])
206-
add_feature_to_all(qapp, "servicevm", ["sys-usb", "sys-firewall", "sys-net"])
207-
add_feature_to_all(qapp, "os-eol", [])
208-
add_feature_to_all(qapp, "skip-update", [])
209-
add_feature_to_all(qapp, "prohibit-start", [])
21062

211-
return qapp
63+
def test_qapp_impl():
64+
return MockQubesComplete()
21265

21366

21467
@pytest.fixture

qui/updater/tests/test_intro_page.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,13 @@ def test_populate_vm_list(
6464
assert len(sut.get_vms_to_update()) == 2
6565

6666

67+
# i-th expectations value is an expected number of selected VMs after clicking on the
68+
# colum header i times
6769
@pytest.mark.parametrize(
6870
"updates_available, expectations",
6971
(
70-
pytest.param((2, 6), (0, 2, 6, 12, 0)),
71-
pytest.param((6, 0), (0, 6, 12, 0)),
72+
pytest.param((2, 6), (0, 2, 6, 13, 0)),
73+
pytest.param((6, 0), (0, 6, 13, 0)),
7274
),
7375
)
7476
def test_on_header_toggled(
@@ -88,7 +90,7 @@ def test_on_header_toggled(
8890
for vm in test_qapp.domains:
8991
sut.list_store.append_vm(vm)
9092

91-
assert len(sut.list_store) == 12
93+
assert len(sut.list_store) == 13
9294

9395
for i, row in enumerate(sut.list_store):
9496
if i < updates_available[0]:
@@ -107,9 +109,9 @@ def test_on_header_toggled(
107109
assert selected_num == expected
108110
assert (
109111
sut.checkbox_column_button.get_inconsistent()
110-
and expected not in (0, 12)
112+
and expected not in (0, 13)
111113
or sut.checkbox_column_button.get_active()
112-
and expected == 12
114+
and expected == 13
113115
or not sut.checkbox_column_button.get_active()
114116
and expected == 0
115117
)
@@ -128,7 +130,7 @@ def test_on_checkbox_toggled(
128130
for vm in test_qapp.domains:
129131
sut.list_store.append_vm(vm)
130132

131-
assert len(sut.list_store) == 12
133+
assert len(sut.list_store) == 13
132134

133135
sut.head_checkbox.state = HeaderCheckbox.NONE
134136
sut.head_checkbox.set_buttons()
@@ -186,7 +188,7 @@ def test_prohibit_start(
186188
for vm in test_qapp.domains:
187189
sut.list_store.append_vm(vm)
188190

189-
assert len(sut.list_store) == 12
191+
assert len(sut.list_store) == 13
190192

191193
sut.head_checkbox.state = HeaderCheckbox.NONE
192194
sut.head_checkbox.set_buttons()
@@ -420,7 +422,7 @@ def test_select_rows_ignoring_conditions(
420422
for vm in test_qapp.domains:
421423
sut.list_store.append_vm(vm)
422424

423-
assert len(sut.list_store) == 12
425+
assert len(sut.list_store) == 13
424426

425427
result = b""
426428
if tmpls_and_stndas:

qui/updater/tests/test_summary_page.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def test_on_header_toggled(
9696
sut.head_checkbox._allowed[0] = AppVMType.SERVICEVM
9797
service_num = 3
9898
sut.head_checkbox._allowed[1] = AppVMType.NON_SERVICEVM
99-
non_excluded_num = 6
99+
non_excluded_num = 7
100100

101101
sut.head_checkbox.state = HeaderCheckbox.NONE
102102

@@ -176,9 +176,9 @@ def test_on_checkbox_toggled(
176176

177177

178178
# expected data based on test_qapp setup
179-
UP_VMS = 7
179+
UP_VMS = 9
180180
UP_SERVICE_VMS = 3
181-
UP_APP_VMS = 4
181+
UP_APP_VMS = 6
182182

183183

184184
@pytest.mark.parametrize(
@@ -381,6 +381,7 @@ def test_perform_restart(
381381
"test-blue",
382382
"test-red",
383383
"test-vm",
384+
"test-old",
384385
"vault",
385386
)
386387
expected_shutdown_calls = [

0 commit comments

Comments
 (0)