forked from QubesOS/qubes-desktop-linux-menu
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_app_page.py
More file actions
166 lines (141 loc) · 5.11 KB
/
Copy pathtest_app_page.py
File metadata and controls
166 lines (141 loc) · 5.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# -*- encoding: utf8 -*-
#
# The Qubes OS Project, http://www.qubes-os.org
#
# Copyright (C) 2023 Marta Marczykowska-Górecka
# <marmarta@invisiblethingslab.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License along
# with this program; if not, see <http://www.gnu.org/licenses/>.
from unittest import mock
from ..desktop_file_manager import DesktopFileManager
from ..vm_manager import VMManager
from qubesadmin.tests.mock_app import MockDispatcher, MockQube
from ..application_page import AppPage
from ..settings_page import SettingsPage
def test_app_page_vm_state(test_desktop_file_path, test_qapp, test_builder):
dispatcher = MockDispatcher(test_qapp)
vm_manager = VMManager(test_qapp, dispatcher)
with mock.patch.object(
DesktopFileManager, "desktop_dirs", [test_desktop_file_path]
):
desktop_file_manager = DesktopFileManager(test_qapp)
app_page = AppPage(vm_manager, test_builder, desktop_file_manager)
# For some reason it defaults to the system tab.
app_page.toggle_buttons.apps_toggle.set_active(True)
# select dom0
app_page.vm_list.select_row(
[
row
for row in app_page.vm_list.get_children()
if row.vm_name == "dom0"
][0]
)
assert app_page.control_list.start_item.row_label.get_label() == " "
assert app_page.control_list.pause_item.row_label.get_label() == " "
# select a turned off vm
app_page.vm_list.select_row(
[
row
for row in app_page.vm_list.get_children()
if row.vm_name == "test-red"
][0]
)
assert (
app_page.control_list.start_item.row_label.get_label() == "Start qube"
)
assert app_page.control_list.pause_item.row_label.get_label() == " "
# select a turned on vm
app_page.vm_list.select_row(
[
row
for row in app_page.vm_list.get_children()
if row.vm_name == "sys-usb"
][0]
)
assert (
app_page.control_list.start_item.row_label.get_label()
== "Shutdown qube"
)
assert (
app_page.control_list.pause_item.row_label.get_label() == "Pause qube"
)
# select a turned off disposable template
app_page.vm_list.select_row(
[
row
for row in app_page.vm_list.get_children()
if row.vm_name == "test-alt-dvm"
][0]
)
assert app_page.control_list.start_item.row_label.get_label() == " "
assert app_page.control_list.pause_item.row_label.get_label() == " "
# select a turned on disposable template
app_page.vm_list.select_row(
[
row
for row in app_page.vm_list.get_children()
if row.vm_name == "test-alt-dvm-running"
][0]
)
assert (
app_page.control_list.start_item.row_label.get_label()
== "Shutdown qube"
)
assert (
app_page.control_list.pause_item.row_label.get_label() == "Pause qube"
)
def test_dispvm_parent_sorting(test_desktop_file_path, test_qapp, test_builder):
# check if dispvm child is sorted after the parent
test_qapp._qubes["disp1233"] = MockQube(
name="disp1233",
qapp=test_qapp,
klass="DispVM",
template_for_dispvms="True",
template="default-dvm",
auto_cleanup=True,
)
test_qapp.update_vm_calls()
dispatcher = MockDispatcher(test_qapp)
vm_manager = VMManager(test_qapp, dispatcher)
with mock.patch.object(
DesktopFileManager, "desktop_dirs", [test_desktop_file_path]
):
desktop_file_manager = DesktopFileManager(test_qapp)
app_page = AppPage(vm_manager, test_builder, desktop_file_manager)
found_dvm = False
for row in app_page.vm_list.get_children():
if found_dvm:
if row.vm_name == "disp1233" and row.vm_entry.parent_vm:
break
found_dvm = False
continue
if row.vm_entry.is_dispvm_template:
found_dvm = True
continue
found_dvm = False
else:
assert False
def test_settings_app_page(test_desktop_file_path, test_qapp, test_builder):
# a basic sanity test
dispatcher = MockDispatcher(test_qapp)
vm_manager = VMManager(test_qapp, dispatcher)
with mock.patch.object(
DesktopFileManager, "desktop_dirs", [test_desktop_file_path]
):
desktop_file_manager = DesktopFileManager(test_qapp)
settings_page = SettingsPage(
test_qapp, test_builder, desktop_file_manager, dispatcher
)
for row in settings_page.app_list.get_children():
assert not row.app_info.vm