def setUp(self): super(BackupTest, self).setUp() # mock up nonexistence of saved backup settings self.patcher_open = unittest.mock.patch('builtins.open') self.mock_open = self.patcher_open.start() self.mock_open.side_effect = FileNotFoundError() self.addCleanup(self.patcher_open.stop) # mock up the Backup Thread to avoid accidentally changing system state self.patcher_thread = unittest.mock.patch( 'qubesmanager.backup.BackupThread') self.mock_thread = self.patcher_thread.start() self.addCleanup(self.patcher_thread.stop) self.qapp = Qubes() self.qtapp = QtGui.QApplication(["test", "-style", "cleanlooks"]) self.dispatcher = events.EventsDispatcher(self.qapp) self.loop = quamash.QEventLoop(self.qtapp) self.dialog = backup.BackupVMsWindow(self.qtapp, self.qapp, self.dispatcher) self.dialog.show()
def setUp(self): super(BackupTest, self).setUp() # mock up nonexistence of saved backup settings self.patcher = unittest.mock.patch('builtins.open') self.mock_open = self.patcher.start() self.mock_open.side_effect = FileNotFoundError() self.addCleanup(self.patcher.stop) self.qapp = Qubes() self.qtapp = QtGui.QApplication(sys.argv) self.dialog = backup_gui.BackupVMsWindow(self.qtapp, self.qapp)
def test_22_loading_settings_exc(self, mock_info, mock_load): mock_load.side_effect = exc.QubesException('Error') self.dialog.hide() self.dialog.deleteLater() self.qtapp.processEvents() self.dialog = backup.BackupVMsWindow( self.qtapp, self.qapp, self.dispatcher) self.dialog.show() # check error was reported self.assertEqual(mock_info.call_count, 1, "Warning not shown")
def test_21_loading_settings_error(self, mock_load): mock_load.return_value = { 'destination_vm': "incorrect_vm", } self.dialog.hide() self.dialog.deleteLater() self.qtapp.processEvents() self.dialog = backup.BackupVMsWindow( self.qtapp, self.qapp, self.dispatcher) self.dialog.show() # check errors were detected self.assertIn('incorrect_vm', self.dialog.warning_running_label.text())
def test_21_loading_settings_error(self, mock_load): mock_load.return_value = { 'destination_vm': "incorrect_vm", } self.dialog.hide() self.dialog.deleteLater() self.qtapp.processEvents() self.dialog = backup.BackupVMsWindow(self.qtapp, self.qapp, self.dispatcher) self.dialog.show() # check errors were detected self.assertTrue(self.dialog.unrecognized_config_label.isVisible())
def test_20_loading_settings(self, mock_load): mock_load.return_value = { 'destination_vm': self.running_vm, 'destination_path': "/home", 'include': [self.dom0_name, self.vms[0], self.vms[1]], 'passphrase_text': "longerPassPhrase", 'compression': True } self.dialog.hide() self.dialog.deleteLater() self.qtapp.processEvents() self.dialog = backup.BackupVMsWindow( self.qtapp, self.qapp, self.dispatcher) self.dialog.show() # check if settings were loaded self.assertEqual(self.dialog.appvm_combobox.currentText(), self.running_vm, "Destination VM not loaded") self.assertEqual(self.dialog.dir_line_edit.text(), "/home", "Destination path not loaded") self.assertEqual(self.dialog.passphrase_line_edit.text(), "longerPassPhrase", "Passphrase not loaded") self.assertEqual(self.dialog.passphrase_line_edit_verify.text(), "longerPassPhrase", "Passphrase verify not loaded") self.assertTrue(self.dialog.compress_checkbox.isChecked()) # check that 'include' vms were not pre-selected include_in_backups_no = len( [vm for vm in self.qapp.domains if not vm.features.get('internal', False) and getattr(vm, 'include_in_backups', True)]) selected_no = self.dialog.select_vms_widget.selected_list.count() self.assertEqual(include_in_backups_no, selected_no, "Incorrect VM list selected") # check no errors were detected self.assertFalse(self.dialog.unrecognized_config_label.isVisible())