Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marmarta committed Oct 28, 2024
1 parent d21b22a commit abd77fc
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 39 deletions.
16 changes: 8 additions & 8 deletions qubesmanager/tests/test_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,9 +486,9 @@ def test_25_successful_backup(self, _a, _b, mock_remove,
self.dialog.backup_finished()

self.assertFalse(self.dialog.button(
self.dialog.CancelButton).isEnabled())
QtWidgets.QWizard.WizardButton.CancelButton).isEnabled())
self.assertTrue(self.dialog.button(
self.dialog.FinishButton).isEnabled())
QtWidgets.QWizard.WizardButton.FinishButton).isEnabled())
mock_remove.assert_called_once_with(
'/etc/qubes/backup/qubes-manager-backup-tmp.conf')
self.assertEqual(mock_system.call_count, 0,
Expand Down Expand Up @@ -526,9 +526,9 @@ def test_26_success_backup_poweroff(
self.dialog.backup_finished()

self.assertFalse(self.dialog.button(
self.dialog.CancelButton).isEnabled())
QtWidgets.QWizard.WizardButton.CancelButton).isEnabled())
self.assertTrue(self.dialog.button(
self.dialog.FinishButton).isEnabled())
QtWidgets.QWizard.WizardButton.FinishButton).isEnabled())
mock_remove.assert_called_once_with(
'/etc/qubes/backup/qubes-manager-backup-tmp.conf')
mock_system.assert_called_once_with('systemctl poweroff')
Expand Down Expand Up @@ -564,9 +564,9 @@ def test_27_failed_backup(
self.dialog.backup_finished()

self.assertFalse(self.dialog.button(
self.dialog.CancelButton).isEnabled())
QtWidgets.QWizard.WizardButton.CancelButton).isEnabled())
self.assertTrue(self.dialog.button(
self.dialog.FinishButton).isEnabled())
QtWidgets.QWizard.WizardButton.FinishButton).isEnabled())
mock_remove.assert_called_once_with(
'/etc/qubes/backup/qubes-manager-backup-tmp.conf')
self.assertEqual(mock_system.call_count, 0,
Expand Down Expand Up @@ -596,9 +596,9 @@ def test_28_progress(

# see if backup is correctly in progress
self.assertTrue(self.dialog.button(
self.dialog.CancelButton).isEnabled())
QtWidgets.QWizard.WizardButton.CancelButton).isEnabled())
self.assertFalse(self.dialog.button(
self.dialog.FinishButton).isEnabled())
QtWidgets.QWizard.WizardButton.FinishButton).isEnabled())
self.assertEqual(self.dialog.progress_bar.value(), 0,
"Progress bar does not start at 0")

Expand Down
76 changes: 46 additions & 30 deletions qubesmanager/tests/test_create_new_vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ def test_02_create_simple_vm(self):
self.__click_ok()

self.mock_thread.assert_called_once_with(
self.qapp, "AppVM", "test-vm",
unittest.mock.ANY, self.qapp.default_template,
{'provides_network': False}, unittest.mock.ANY)
app=self.qapp, vmclass="AppVM", name="test-vm",
label=unittest.mock.ANY, template=self.qapp.default_template,
properties={'provides_network': False}, pool=unittest.mock.ANY)
self.mock_thread().start.assert_called_once_with()

def test_03_label(self):
Expand All @@ -80,9 +80,10 @@ def test_03_label(self):
self.__click_ok()

self.mock_thread.assert_called_once_with(
self.qapp, "AppVM", "test-vm",
self.qapp.labels['blue'], self.qapp.default_template,
unittest.mock.ANY, unittest.mock.ANY)
app=self.qapp, vmclass="AppVM", name="test-vm",
label=self.qapp.labels['blue'],
template=self.qapp.default_template,
properties=unittest.mock.ANY, pool=unittest.mock.ANY)
self.mock_thread().start.assert_called_once_with()

def test_04_template(self):
Expand All @@ -97,9 +98,10 @@ def test_04_template(self):
self.__click_ok()

self.mock_thread.assert_called_once_with(
self.qapp, "AppVM", "test-vm",
unittest.mock.ANY, template,
unittest.mock.ANY, unittest.mock.ANY)
app=self.qapp, vmclass="AppVM", name="test-vm",
label=unittest.mock.ANY,
template=template,
properties=unittest.mock.ANY, pool=unittest.mock.ANY)

def test_05_netvm(self):
netvm = None
Expand All @@ -113,9 +115,11 @@ def test_05_netvm(self):
self.__click_ok()

self.mock_thread.assert_called_once_with(
self.qapp, "AppVM", "test-vm",
unittest.mock.ANY, unittest.mock.ANY,
{'netvm': netvm, 'provides_network': False}, unittest.mock.ANY)
app=self.qapp, vmclass="AppVM", name="test-vm",
label=unittest.mock.ANY,
template=unittest.mock.ANY,
properties={'netvm': netvm, 'provides_network': False},
pool=unittest.mock.ANY)

def test_06_provides_network(self):
self.dialog.provides_network.setChecked(True)
Expand All @@ -124,9 +128,11 @@ def test_06_provides_network(self):
self.__click_ok()

self.mock_thread.assert_called_once_with(
self.qapp, "AppVM", "test-vm",
unittest.mock.ANY, unittest.mock.ANY,
{'provides_network': True}, unittest.mock.ANY)
app=self.qapp, vmclass="AppVM", name="test-vm",
label=unittest.mock.ANY,
template=unittest.mock.ANY,
properties={'provides_network': True},
pool=unittest.mock.ANY)

@unittest.mock.patch('subprocess.check_call')
def test_07_launch_settings(self, mock_call):
Expand All @@ -138,9 +144,11 @@ def test_07_launch_settings(self, mock_call):

# make sure the thread is not reporting an error
self.mock_thread.assert_called_once_with(
self.qapp, "AppVM", "test-vm",
unittest.mock.ANY, unittest.mock.ANY,
unittest.mock.ANY, unittest.mock.ANY)
app=self.qapp, vmclass="AppVM", name="test-vm",
label=unittest.mock.ANY,
template=unittest.mock.ANY,
properties=unittest.mock.ANY,
pool=unittest.mock.ANY)

self.mock_thread().msg = None
self.dialog.create_finished()
Expand All @@ -153,9 +161,11 @@ def test_08_progress_hides(self):
self.__click_ok()

self.mock_thread.assert_called_once_with(
self.qapp, "AppVM", "test-vm",
unittest.mock.ANY, unittest.mock.ANY,
unittest.mock.ANY, unittest.mock.ANY)
app=self.qapp, vmclass="AppVM", name="test-vm",
label=unittest.mock.ANY,
template=unittest.mock.ANY,
properties=unittest.mock.ANY,
pool=unittest.mock.ANY)

# make sure the thread is not reporting an error
self.mock_thread().start.assert_called_once_with()
Expand All @@ -177,9 +187,11 @@ def test_09_standalone_clone(self):

self.__click_ok()
self.mock_thread.assert_called_once_with(
self.qapp, "StandaloneVM", "test-vm",
unittest.mock.ANY, unittest.mock.ANY,
unittest.mock.ANY, unittest.mock.ANY)
app=self.qapp, vmclass="StandaloneVM", name="test-vm",
label=unittest.mock.ANY,
template=unittest.mock.ANY,
properties=unittest.mock.ANY,
pool=unittest.mock.ANY)

@unittest.mock.patch('qubesmanager.bootfromdevice.VMBootFromDeviceWindow')
@unittest.mock.patch('qubesadmin.tools.qvm_start')
Expand All @@ -197,9 +209,11 @@ def test_10_standalone_empty(self, mock_qvm_start, mock_bootwindow):

self.__click_ok()
self.mock_thread.assert_called_once_with(
self.qapp, "StandaloneVM", "test-vm",
unittest.mock.ANY, None,
unittest.mock.ANY, unittest.mock.ANY)
app=self.qapp, vmclass="StandaloneVM", name="test-vm",
label=unittest.mock.ANY,
template=None,
properties=unittest.mock.ANY,
pool=unittest.mock.ANY)

self.mock_thread().msg = None
self.dialog.create_finished()
Expand All @@ -224,9 +238,11 @@ def test_11_standalone_empty_not_install(self, mock_call):

self.__click_ok()
self.mock_thread.assert_called_once_with(
self.qapp, "StandaloneVM", "test-vm",
unittest.mock.ANY, None,
unittest.mock.ANY, unittest.mock.ANY)
app=self.qapp, vmclass="StandaloneVM", name="test-vm",
label=unittest.mock.ANY,
template=None,
properties=unittest.mock.ANY,
pool=unittest.mock.ANY)

self.mock_thread().msg = None
self.dialog.create_finished()
Expand Down
4 changes: 3 additions & 1 deletion qubesmanager/tests/test_qube_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def test_006_correct_ip_listed(self):
ip_item = self._get_table_item(row, "IP Address")
if hasattr(vm, 'ip'):
ip_value = getattr(vm, 'ip')
ip_value = "" if ip_value is None else ip_value
ip_value = "n/a" if not ip_value else ip_value
else:
ip_value = "n/a"

Expand Down Expand Up @@ -1158,6 +1158,8 @@ def test_407_prop_change_netvm(self):
vm_row = self._find_vm_row(target_vm_name)

old_netvm = self._get_table_item(vm_row, "NetVM")
# in case of "default (...)" take "default"
old_newvm = old_netvm.split(' ')[0]
new_netvm = None
for vm in self.qapp.domains:
if getattr(vm, "provides_network", False) and vm.name != old_netvm:
Expand Down

0 comments on commit abd77fc

Please sign in to comment.