test_vm_settings.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  1. #!/usr/bin/python3
  2. #
  3. # The Qubes OS Project, https://www.qubes-os.org/
  4. #
  5. # Copyright (C) 2016 Marta Marczykowska-Górecka
  6. # <marmarta@invisiblethingslab.com>
  7. #
  8. # This program is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation; either version 2 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License along
  19. # with this program; if not, write to the Free Software Foundation, Inc.,
  20. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  21. #
  22. import logging.handlers
  23. import unittest
  24. import unittest.mock
  25. from PyQt5 import QtTest, QtCore
  26. from qubesadmin import Qubes
  27. import qubesmanager.settings as vm_settings
  28. from qubesmanager.tests import init_qtapp
  29. class VMSettingsTest(unittest.TestCase):
  30. def setUp(self):
  31. super(VMSettingsTest, self).setUp()
  32. self.qtapp, self.loop = init_qtapp()
  33. self.mock_qprogress = unittest.mock.patch(
  34. 'PyQt5.QtWidgets.QProgressDialog')
  35. self.mock_qprogress.start()
  36. self.addCleanup(self.mock_qprogress.stop)
  37. self.qapp = Qubes()
  38. if "test-vm" in self.qapp.domains:
  39. del self.qapp.domains["test-vm"]
  40. def tearDown(self):
  41. if "test-vm" in self.qapp.domains:
  42. del self.qapp.domains["test-vm"]
  43. super(VMSettingsTest, self).tearDown()
  44. def test_00_load_correct_tab(self):
  45. self.vm = self.qapp.add_new_vm("AppVM", "test-vm", "red")
  46. self.dialog = vm_settings.VMSettingsWindow(
  47. self.vm, qapp=self.qtapp, qubesapp=self.qapp, init_page="basic")
  48. self.assertTrue(
  49. self.dialog.tabWidget.currentWidget() is self.dialog.basic_tab)
  50. self.dialog.deleteLater()
  51. self.qtapp.processEvents()
  52. self.dialog = vm_settings.VMSettingsWindow(
  53. self.vm, qapp=self.qtapp, qubesapp=self.qapp, init_page="advanced")
  54. self.assertTrue(
  55. self.dialog.tabWidget.currentWidget() is self.dialog.advanced_tab)
  56. self.dialog.deleteLater()
  57. self.qtapp.processEvents()
  58. self.dialog = vm_settings.VMSettingsWindow(
  59. self.vm, qapp=self.qtapp, qubesapp=self.qapp, init_page="firewall")
  60. self.assertTrue(
  61. self.dialog.tabWidget.currentWidget() is self.dialog.firewall_tab)
  62. self.dialog.deleteLater()
  63. self.qtapp.processEvents()
  64. self.dialog = vm_settings.VMSettingsWindow(
  65. self.vm, qapp=self.qtapp, qubesapp=self.qapp, init_page="devices")
  66. self.assertTrue(
  67. self.dialog.tabWidget.currentWidget() is self.dialog.devices_tab)
  68. self.dialog.deleteLater()
  69. self.qtapp.processEvents()
  70. self.dialog = vm_settings.VMSettingsWindow(
  71. self.vm, qapp=self.qtapp, qubesapp=self.qapp,
  72. init_page="applications")
  73. self.assertTrue(
  74. self.dialog.tabWidget.currentWidget() is self.dialog.apps_tab)
  75. self.dialog.deleteLater()
  76. self.qtapp.processEvents()
  77. self.dialog = vm_settings.VMSettingsWindow(
  78. self.vm, qapp=self.qtapp, qubesapp=self.qapp, init_page="services")
  79. self.assertTrue(
  80. self.dialog.tabWidget.currentWidget() is self.dialog.services_tab)
  81. self.dialog.deleteLater()
  82. self.qtapp.processEvents()
  83. def test_01_basic_tab_default(self):
  84. self.vm = self.qapp.add_new_vm("AppVM", "test-vm", "blue")
  85. # set the vm to have a default template and netvm
  86. self.dialog = vm_settings.VMSettingsWindow(
  87. self.vm, qapp=self.qtapp, qubesapp=self.qapp, init_page="basic")
  88. self.assertEqual(self.dialog.vmname.text(), "test-vm",
  89. "Name displayed incorrectly")
  90. self.assertTrue("blue" in self.dialog.vmlabel.currentText(),
  91. "Incorrect label displayed")
  92. displayed_template = self.dialog.template_name.currentText()
  93. correct_template = self.vm.template.name
  94. self.assertTrue("current" in displayed_template,
  95. "Template incorrectly not shown as current")
  96. self.assertTrue(correct_template in displayed_template,
  97. "Template not displayed correctly")
  98. displayed_netvm = self.dialog.netVM.currentText()
  99. correct_netvm = self.vm.netvm.name
  100. self.assertTrue("current" in displayed_netvm,
  101. "NetVM incorrectly not shown as current")
  102. self.assertTrue(correct_netvm in displayed_netvm,
  103. "NetVM not displayed correctly")
  104. self.assertEqual(self.dialog.include_in_backups.isChecked(),
  105. self.vm.include_in_backups,
  106. "Incorrect 'include in backups' state")
  107. self.assertEqual(self.dialog.autostart_vm.isChecked(),
  108. self.vm.autostart,
  109. "Incorrect 'autostart' state")
  110. self.assertEqual(self.dialog.type_label.text(),
  111. self.vm.klass,
  112. "Incorrect class displayed")
  113. self.assertEqual(self.dialog.ip_label.text(),
  114. self.vm.ip,
  115. "Incorrect IP displayed")
  116. self.assertEqual(self.dialog.netmask_label.text(),
  117. self.vm.visible_netmask,
  118. "Incorrect netmask displayed")
  119. self.assertEqual(self.dialog.gateway_label.text(),
  120. self.vm.visible_gateway,
  121. "Incorrect gateway displayed")
  122. self.assertEqual(self.dialog.max_priv_storage.value(),
  123. self.vm.volumes['private'].size // 1024 ** 2,
  124. "Incorrect max private storage size")
  125. self.assertEqual(self.dialog.root_resize.value(),
  126. self.vm.volumes['root'].size // 1024 ** 2,
  127. "Incorrect max private root size")
  128. def test_02_basic_tab_nones(self):
  129. self.vm = self.qapp.add_new_vm("StandaloneVM", "test-vm", "blue")
  130. # set the vm to have a default template and netvm
  131. self.vm.netvm = None
  132. self.dialog = vm_settings.VMSettingsWindow(
  133. self.vm, qapp=self.qtapp, qubesapp=self.qapp, init_page="basic")
  134. self.assertEqual("", self.dialog.template_name.currentText(),
  135. "No template incorrectly displayed")
  136. displayed_netvm = self.dialog.netVM.currentText()
  137. self.assertTrue("current" in displayed_netvm,
  138. "None NetVM incorrectly not shown as current")
  139. self.assertTrue("none" in displayed_netvm,
  140. "None NetVM not displayed correctly")
  141. self.assertEqual(self.dialog.type_label.text(), "StandaloneVM",
  142. "Type displayed incorrectly for standaloneVM")
  143. self.assertEqual(self.dialog.ip_label.text(),
  144. "---",
  145. "Incorrect IP displayed")
  146. self.assertEqual(self.dialog.netmask_label.text(),
  147. "---",
  148. "Incorrect netmask displayed")
  149. self.assertEqual(self.dialog.gateway_label.text(),
  150. "---",
  151. "Incorrect gateway displayed")
  152. def test_03_change_label(self):
  153. self.vm = self.qapp.add_new_vm("AppVM", "test-vm", "blue")
  154. self.dialog = vm_settings.VMSettingsWindow(
  155. self.vm, qapp=self.qtapp, qubesapp=self.qapp, init_page="basic")
  156. self.dialog.show()
  157. new_label = self._set_noncurrent(self.dialog.vmlabel)
  158. self._click_ok()
  159. self.assertEqual(str(self.vm.label), new_label,
  160. "Label is not set correctly")
  161. def test_04_change_template(self):
  162. self.vm = self.qapp.add_new_vm("AppVM", "test-vm", "blue")
  163. self.dialog = vm_settings.VMSettingsWindow(
  164. self.vm, qapp=self.qtapp, qubesapp=self.qapp, init_page="basic")
  165. new_template = self._set_noncurrent(self.dialog.template_name)
  166. self._click_ok()
  167. self.assertEqual(self.vm.template.name, new_template,
  168. "Template is not set correctly")
  169. def test_05_change_networking(self):
  170. self.vm = self.qapp.add_new_vm("AppVM", "test-vm", "blue")
  171. self.dialog = vm_settings.VMSettingsWindow(
  172. self.vm, qapp=self.qtapp, qubesapp=self.qapp, init_page="basic")
  173. new_netvm = self._set_noncurrent(self.dialog.netVM)
  174. self._click_ok()
  175. self.assertEqual(self.vm.netvm.name, new_netvm,
  176. "NetVM is not set correctly")
  177. def test_06_change_networking_none(self):
  178. self.vm = self.qapp.add_new_vm("AppVM", "test-vm", "blue")
  179. self.dialog = vm_settings.VMSettingsWindow(
  180. self.vm, qapp=self.qtapp, qubesapp=self.qapp, init_page="basic")
  181. self._set_none(self.dialog.netVM)
  182. self._click_ok()
  183. self.assertIsNone(self.vm.netvm,
  184. "None netVM is not set correctly")
  185. def test_07_change_networking_to_default(self):
  186. self.vm = self.qapp.add_new_vm("AppVM", "test-vm", "blue")
  187. for vm in self.qapp.domains:
  188. if getattr(vm, 'provides_network', False)\
  189. and vm != self.qapp.default_netvm:
  190. self.vm.netvm = vm
  191. break
  192. self.dialog = vm_settings.VMSettingsWindow(
  193. self.vm, qapp=self.qtapp, qubesapp=self.qapp, init_page="basic")
  194. new_netvm = self._set_default(self.dialog.netVM)
  195. self._click_ok()
  196. self.assertTrue(self.vm.netvm.name in new_netvm,
  197. "NetVM is not set correctly")
  198. self.assertTrue(self.vm.property_is_default('netvm'))
  199. def test_08_basic_checkboxes_true(self):
  200. self.vm = self.qapp.add_new_vm("AppVM", "test-vm", "blue")
  201. self.dialog = vm_settings.VMSettingsWindow(
  202. self.vm, qapp=self.qtapp, qubesapp=self.qapp, init_page="basic")
  203. self.dialog.show()
  204. self.dialog.include_in_backups.setChecked(True)
  205. self.dialog.autostart_vm.setChecked(True)
  206. self._click_ok()
  207. self.assertTrue(self.vm.include_in_backups,
  208. "Include in backups not set to true")
  209. self.assertTrue(self.vm.autostart,
  210. "Autostart not set to true")
  211. def test_09_basic_checkboxes_false(self):
  212. self.vm = self.qapp.add_new_vm("AppVM", "test-vm", "blue")
  213. self.dialog = vm_settings.VMSettingsWindow(
  214. self.vm, qapp=self.qtapp, qubesapp=self.qapp, init_page="basic")
  215. self.dialog.show()
  216. self.dialog.include_in_backups.setChecked(False)
  217. self.dialog.autostart_vm.setChecked(False)
  218. self._click_ok()
  219. self.assertFalse(self.vm.include_in_backups,
  220. "Include in backups not set to false")
  221. self.assertFalse(self.vm.autostart,
  222. "Autostart not set to false")
  223. def test_10_increase_private_storage(self):
  224. self.vm = self.qapp.add_new_vm("AppVM", "test-vm", "blue")
  225. self.dialog = vm_settings.VMSettingsWindow(
  226. self.vm, qapp=self.qtapp, qubesapp=self.qapp, init_page="basic")
  227. current_storage = self.vm.volumes['private'].size // 1024**2
  228. new_storage = current_storage + 512
  229. self.dialog.max_priv_storage.setValue(new_storage)
  230. self._click_ok()
  231. self.assertEqual(self.vm.volumes['private'].size // 1024**2,
  232. new_storage)
  233. # TODO are dependencies correctly processed
  234. @unittest.mock.patch('PyQt5.QtWidgets.QProgressDialog')
  235. @unittest.mock.patch('PyQt5.QtWidgets.QInputDialog.getText')
  236. @unittest.mock.patch('qubesmanager.settings.RenameVMThread')
  237. def test_11_rename_vm(self, mock_thread, mock_input, _):
  238. self.vm = self.qapp.add_new_vm("AppVM", "test-vm", "blue")
  239. self.dialog = vm_settings.VMSettingsWindow(
  240. self.vm, qapp=self.qtapp, qubesapp=self.qapp, init_page="basic")
  241. self.assertTrue(self.dialog.rename_vm_button.isEnabled())
  242. mock_input.return_value = ("test-vm2", True)
  243. self.dialog.rename_vm_button.click()
  244. mock_thread.assert_called_with(self.vm, "test-vm2", unittest.mock.ANY)
  245. mock_thread().start.assert_called_with()
  246. @unittest.mock.patch('qubesmanager.clone_vm.CloneVMDlg')
  247. def test_12_clone_vm(self, mock_clone):
  248. self.vm = self.qapp.add_new_vm("AppVM", "test-vm", "blue")
  249. self.dialog = vm_settings.VMSettingsWindow(
  250. self.vm, qapp=self.qtapp, qubesapp=self.qapp, init_page="basic")
  251. self.assertTrue(self.dialog.clone_vm_button.isEnabled())
  252. self.dialog.clone_vm_button.click()
  253. mock_clone.assert_called_once_with(self.qtapp, self.qapp,
  254. src_vm=self.vm)
  255. @unittest.mock.patch('PyQt5.QtWidgets.QMessageBox.warning')
  256. @unittest.mock.patch('PyQt5.QtWidgets.QProgressDialog')
  257. @unittest.mock.patch('PyQt5.QtWidgets.QInputDialog.getText')
  258. @unittest.mock.patch('qubesmanager.common_threads.RemoveVMThread')
  259. def test_13_remove_vm(self, mock_thread, mock_input, _, mock_warning):
  260. self.vm = self.qapp.add_new_vm("AppVM", "test-vm", "blue")
  261. self.dialog = vm_settings.VMSettingsWindow(
  262. self.vm, qapp=self.qtapp, qubesapp=self.qapp, init_page="basic")
  263. self.assertTrue(self.dialog.delete_vm_button.isEnabled())
  264. # try with a wrong name
  265. mock_input.return_value = ("test-vm2", True)
  266. self.dialog.delete_vm_button.click()
  267. self.assertEqual(mock_warning.call_count, 1)
  268. # and now correct one
  269. mock_input.return_value = ("test-vm", True)
  270. self.dialog.delete_vm_button.click()
  271. mock_thread.assert_called_with(self.vm)
  272. mock_thread().start.assert_called_with()
  273. # Advanced Tab
  274. def test_20_advanced_loads(self):
  275. self.vm = self.qapp.add_new_vm("AppVM", "test-vm", "blue")
  276. self.dialog = vm_settings.VMSettingsWindow(
  277. self.vm, qapp=self.qtapp, qubesapp=self.qapp, init_page="advanced")
  278. self.assertEqual(self.dialog.init_mem.value(), self.vm.memory,
  279. "Incorrect initial memory")
  280. # default maxmem
  281. self.assertEqual(self.dialog.max_mem_size.value(),
  282. self.vm.property_get_default('maxmem'),
  283. "Maxmem incorrectly displayed for default value")
  284. self.assertEqual(self.dialog.vcpus.value(), self.vm.vcpus,
  285. "Incorrect number of VCPUs")
  286. self.assertTrue(self.dialog.include_in_balancing.isChecked(),
  287. "Include in memory balancing incorrectly not checked")
  288. # debug mode
  289. self.assertEqual(self.dialog.run_in_debug_mode.isChecked(),
  290. self.vm.debug,
  291. "Incorrect 'run in debug mode' state")
  292. # kernel
  293. self.assertTrue(self.vm.kernel in self.dialog.kernel.currentText(),
  294. "Kernel displayed incorrectly")
  295. # default dispvm
  296. self.assertTrue(
  297. str(self.vm.default_dispvm) in
  298. self.dialog.default_dispvm.currentText(),
  299. "Default dispVM incorrectly displayed")
  300. self.assertEqual(self.vm.template_for_dispvms,
  301. self.dialog.dvm_template_checkbox.isChecked(),
  302. "Incorrectly shown to be template for dispvms")
  303. # virtmode
  304. self.assertTrue("default" in self.dialog.virt_mode.currentText())
  305. self.assertTrue("PVH" in self.dialog.virt_mode.currentText())
  306. def test_21_nondefaultmaxmem(self):
  307. self.vm = self.qapp.add_new_vm("AppVM", "test-vm", "blue")
  308. self.vm.maxmem = 3500
  309. self.dialog = vm_settings.VMSettingsWindow(
  310. self.vm, qapp=self.qtapp, qubesapp=self.qapp, init_page="advanced")
  311. self.assertEqual(self.dialog.max_mem_size.value(), 3500)
  312. self.dialog.include_in_balancing.setChecked(False)
  313. self._click_ok()
  314. self.assertEqual(self.vm.maxmem, 0)
  315. self.dialog.deleteLater()
  316. self.qtapp.processEvents()
  317. self.dialog = vm_settings.VMSettingsWindow(
  318. self.vm, qapp=self.qtapp, qubesapp=self.qapp, init_page="advanced")
  319. self.assertFalse(self.dialog.include_in_balancing.isChecked())
  320. self.dialog.include_in_balancing.setChecked(True)
  321. self.assertEqual(self.dialog.max_mem_size.value(), 3500)
  322. self._click_ok()
  323. self.assertEqual(self.vm.maxmem, 3500)
  324. def test_22_initmem(self):
  325. self.vm = self.qapp.add_new_vm("AppVM", "test-vm", "blue")
  326. self.vm.memory = 500
  327. self.dialog = vm_settings.VMSettingsWindow(
  328. self.vm, qapp=self.qtapp, qubesapp=self.qapp, init_page="advanced")
  329. self.assertEqual(self.dialog.init_mem.value(), 500,
  330. "Incorrect initial memory")
  331. self.dialog.init_mem.setValue(600)
  332. self._click_ok()
  333. self.assertEqual(self.vm.memory, 600, "Setting initial memory failed")
  334. def test_23_vcpus(self):
  335. self.vm = self.qapp.add_new_vm("AppVM", "test-vm", "blue")
  336. self.vm.vcpus = 1
  337. self.dialog = vm_settings.VMSettingsWindow(
  338. self.vm, qapp=self.qtapp, qubesapp=self.qapp, init_page="advanced")
  339. self.assertEqual(self.dialog.vcpus.value(), 1,
  340. "Incorrect number of VCPUs")
  341. self.dialog.vcpus.setValue(2)
  342. self._click_ok()
  343. self.assertEqual(self.vm.vcpus, 2,
  344. "Incorrect number of VCPUs")
  345. def test_24_kernel(self):
  346. self.vm = self.qapp.add_new_vm("AppVM", "test-vm", "blue")
  347. self.dialog = vm_settings.VMSettingsWindow(
  348. self.vm, qapp=self.qtapp, qubesapp=self.qapp, init_page="advanced")
  349. self.dialog.show()
  350. new_kernel = self._set_noncurrent(self.dialog.kernel)
  351. self._click_ok()
  352. self.assertEqual(self.vm.kernel, new_kernel)
  353. self.dialog.deleteLater()
  354. self.qtapp.processEvents()
  355. self.dialog = vm_settings.VMSettingsWindow(
  356. self.vm, qapp=self.qtapp, qubesapp=self.qapp, init_page="advanced")
  357. self.dialog.show()
  358. self._set_default(self.dialog.kernel)
  359. self._click_ok()
  360. self.assertTrue(self.vm.property_is_default('kernel'))
  361. def test_25_virtmode_change(self):
  362. self.vm = self.qapp.add_new_vm("AppVM", "test-vm", "blue")
  363. modes = ["HVM", "PVH", "PV"]
  364. for mode in modes:
  365. self.dialog = vm_settings.VMSettingsWindow(
  366. self.vm, qapp=self.qtapp, qubesapp=self.qapp,
  367. init_page="advanced")
  368. self._set_value(self.dialog.virt_mode, mode)
  369. self._click_ok()
  370. self.assertEqual(self.vm.virt_mode.upper(), mode)
  371. self.dialog.deleteLater()
  372. self.qtapp.processEvents()
  373. self.dialog = vm_settings.VMSettingsWindow(
  374. self.vm, qapp=self.qtapp, qubesapp=self.qapp, init_page="advanced")
  375. self._set_default(self.dialog.virt_mode)
  376. self._click_ok()
  377. self.assertTrue(self.vm.property_is_default('virt_mode'))
  378. def test_26_default_dispvm(self):
  379. self.vm = self.qapp.add_new_vm("AppVM", "test-vm", "blue")
  380. self.dialog = vm_settings.VMSettingsWindow(
  381. self.vm, qapp=self.qtapp, qubesapp=self.qapp, init_page="advanced")
  382. new_dvm = self._set_noncurrent(self.dialog.default_dispvm)
  383. self._click_ok()
  384. self.assertEqual(self.vm.default_dispvm.name, new_dvm)
  385. self.dialog.deleteLater()
  386. self.qtapp.processEvents()
  387. self.dialog = vm_settings.VMSettingsWindow(
  388. self.vm, qapp=self.qtapp, qubesapp=self.qapp, init_page="advanced")
  389. self._set_default(self.dialog.default_dispvm)
  390. self._click_ok()
  391. self.assertTrue(self.vm.property_is_default('default_dispvm'))
  392. @unittest.mock.patch('subprocess.check_call')
  393. def test_27_boot_cdrom(self, mock_call):
  394. self.vm = self.qapp.add_new_vm("AppVM", "test-vm", "blue")
  395. self.dialog = vm_settings.VMSettingsWindow(
  396. self.vm, qapp=self.qtapp, qubesapp=self.qapp, init_page="advanced")
  397. self.dialog.boot_from_device_button.click()
  398. mock_call.assert_called_with(['qubes-vm-boot-from-device', "test-vm"])
  399. def test_28_advanced_debug_false(self):
  400. self.vm = self.qapp.add_new_vm("AppVM", "test-vm", "blue")
  401. self.dialog = vm_settings.VMSettingsWindow(
  402. self.vm, qapp=self.qtapp, qubesapp=self.qapp, init_page="advanced")
  403. self.dialog.show()
  404. self.dialog.run_in_debug_mode.setChecked(False)
  405. self._click_ok()
  406. self.assertFalse(self.vm.debug,
  407. "Debug mode not set to false")
  408. def test_28_advanced_debug_true(self):
  409. self.vm = self.qapp.add_new_vm("AppVM", "test-vm", "blue")
  410. self.dialog = vm_settings.VMSettingsWindow(
  411. self.vm, qapp=self.qtapp, qubesapp=self.qapp, init_page="advanced")
  412. self.dialog.show()
  413. self.dialog.run_in_debug_mode.setChecked(True)
  414. self._click_ok()
  415. self.assertTrue(self.vm.debug,
  416. "Debug mode not set to true")
  417. def _click_ok(self):
  418. okwidget = self.dialog.buttonBox.button(
  419. self.dialog.buttonBox.Ok)
  420. QtTest.QTest.mouseClick(okwidget, QtCore.Qt.LeftButton)
  421. def _click_cancel(self):
  422. cancelwidget = self.dialog.buttonBox.button(
  423. self.dialog.buttonBox.Cancel)
  424. QtTest.QTest.mouseClick(cancelwidget, QtCore.Qt.LeftButton)
  425. def _set_noncurrent(self, widget):
  426. if widget.count() < 2:
  427. self.skipTest("not enough choices for " + widget.objectName())
  428. widget.setCurrentIndex(0)
  429. while widget.currentText().endswith("(current)") \
  430. or widget.currentText().startswith("(none)"):
  431. widget.setCurrentIndex(widget.currentIndex() + 1)
  432. return widget.currentText()
  433. def _set_default(self, widget):
  434. if widget.count() < 2:
  435. self.skipTest("not enough choices for " + widget.objectName())
  436. widget.setCurrentIndex(0)
  437. while "default" not in widget.currentText():
  438. widget.setCurrentIndex(widget.currentIndex() + 1)
  439. return widget.currentText()
  440. def _set_none(self, widget):
  441. if widget.count() < 2:
  442. self.skipTest("not enough choices for " + widget.objectName())
  443. widget.setCurrentIndex(0)
  444. while "none" not in widget.currentText():
  445. widget.setCurrentIndex(widget.currentIndex() + 1)
  446. return widget.currentText()
  447. def _set_value(self, widget, value):
  448. if widget.count() < 2:
  449. self.skipTest("not enough choices for " + widget.objectName())
  450. widget.setCurrentIndex(0)
  451. while value != widget.currentText():
  452. widget.setCurrentIndex(widget.currentIndex() + 1)
  453. return widget.currentText()
  454. if __name__ == "__main__":
  455. ha_syslog = logging.handlers.SysLogHandler('/dev/log')
  456. ha_syslog.setFormatter(
  457. logging.Formatter('%(name)s[%(process)d]: %(message)s'))
  458. logging.root.addHandler(ha_syslog)
  459. unittest.main()