Tests for backup_utils file

This commit is contained in:
Marta Marczykowska-Górecka 2019-05-03 16:10:24 +02:00
parent 9252dad222
commit 9764479aff
No known key found for this signature in database
GPG Key ID: 9A752C30B26FD04B
2 changed files with 89 additions and 16 deletions

View File

@ -49,7 +49,8 @@ class BackupTest(unittest.TestCase):
self.addCleanup(self.patcher_thread.stop)
self.qapp = Qubes()
self.qtapp = QtGui.QApplication(sys.argv)
self.qtapp = QtGui.QApplication(["test", "-style", "cleanlooks"])
self.dispatcher = events.EventsDispatcher(self.qapp)
self.loop = quamash.QEventLoop(self.qtapp)
@ -61,7 +62,6 @@ class BackupTest(unittest.TestCase):
def tearDown(self):
self.dialog.hide()
self.qtapp.deleteLater()
self.dialog.deleteLater()
self.qtapp.processEvents()
@ -70,8 +70,8 @@ class BackupTest(unittest.TestCase):
self.loop.run_until_complete(asyncio.sleep(0))
self.loop.close()
del self.loop
del self.qtapp
del self.dialog
del self.qtapp
gc.collect()
super(BackupTest, self).tearDown()
@ -159,7 +159,7 @@ class BackupTest(unittest.TestCase):
self.assertTrue(self.dialog.currentPage()
is self.dialog.select_dir_page)
# required to check if next button is correctly enabled
self.dialog.dir_line_edit.setText("/home/user")
self.dialog.dir_line_edit.setText("/home")
next_button = self.dialog.button(self.dialog.NextButton)
@ -248,14 +248,14 @@ class BackupTest(unittest.TestCase):
# setup backup
self._select_location("dom0")
self.dialog.dir_line_edit.setText("/home/user")
self.dialog.dir_line_edit.setText("/home")
self.dialog.passphrase_line_edit.setText("pass")
self.dialog.passphrase_line_edit_verify.setText("pass")
self.dialog.save_profile_checkbox.setChecked(True)
self.dialog.turn_off_checkbox.setChecked(False)
self.dialog.compress_checkbox.setChecked(False)
expected_settings = {'destination_vm': "dom0",
'destination_path': "/home/user",
'destination_path': "/home",
'include': ["work"],
'passphrase_text': "pass",
'compression': False}
@ -296,14 +296,14 @@ class BackupTest(unittest.TestCase):
# setup backup
self._select_location("sys-net")
self.dialog.dir_line_edit.setText("/home/user")
self.dialog.dir_line_edit.setText("/home")
self.dialog.passphrase_line_edit.setText("longerPassPhrase")
self.dialog.passphrase_line_edit_verify.setText("longerPassPhrase")
self.dialog.save_profile_checkbox.setChecked(False)
self.dialog.turn_off_checkbox.setChecked(False)
self.dialog.compress_checkbox.setChecked(True)
expected_settings = {'destination_vm': "sys-net",
'destination_path': "/home/user",
'destination_path': "/home",
'include': ["dom0", "sys-net", "work"],
'passphrase_text': "longerPassPhrase",
'compression': True}
@ -330,7 +330,7 @@ class BackupTest(unittest.TestCase):
mock_load.return_value = {
'destination_vm': "sys-net",
'destination_path': "/home/user",
'destination_path': "/home",
'include': ["dom0", "sys-net", "work"],
'passphrase_text': "longerPassPhrase",
'compression': True
@ -347,7 +347,7 @@ class BackupTest(unittest.TestCase):
# check if settings were loaded
self.assertEqual(self.dialog.appvm_combobox.currentText(), "sys-net",
"Destination VM not loaded")
self.assertEqual(self.dialog.dir_line_edit.text(), "/home/user",
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")
@ -411,7 +411,7 @@ class BackupTest(unittest.TestCase):
is self.dialog.select_dir_page)
self._select_location("dom0")
self.dialog.dir_line_edit.setText("/home/user")
self.dialog.dir_line_edit.setText("/home")
self.dialog.passphrase_line_edit.setText("pass")
self.dialog.passphrase_line_edit_verify.setText("pass")
@ -433,7 +433,7 @@ class BackupTest(unittest.TestCase):
is self.dialog.select_dir_page)
self._select_location("dom0")
self.dialog.dir_line_edit.setText("/home/user")
self.dialog.dir_line_edit.setText("/home")
self.dialog.passphrase_line_edit.setText("pass")
self.dialog.passphrase_line_edit_verify.setText("pass")
@ -461,7 +461,7 @@ class BackupTest(unittest.TestCase):
is self.dialog.select_dir_page)
self._select_location("dom0")
self.dialog.dir_line_edit.setText("/home/user")
self.dialog.dir_line_edit.setText("/home")
self.dialog.passphrase_line_edit.setText("pass")
self.dialog.passphrase_line_edit_verify.setText("pass")
self.dialog.turn_off_checkbox.setChecked(False)
@ -501,7 +501,7 @@ class BackupTest(unittest.TestCase):
is self.dialog.select_dir_page)
self._select_location("dom0")
self.dialog.dir_line_edit.setText("/home/user")
self.dialog.dir_line_edit.setText("/home")
self.dialog.passphrase_line_edit.setText("pass")
self.dialog.passphrase_line_edit_verify.setText("pass")
self.dialog.turn_off_checkbox.setChecked(True)
@ -540,7 +540,7 @@ class BackupTest(unittest.TestCase):
is self.dialog.select_dir_page)
self._select_location("dom0")
self.dialog.dir_line_edit.setText("/home/user")
self.dialog.dir_line_edit.setText("/home")
self.dialog.passphrase_line_edit.setText("pass")
self.dialog.passphrase_line_edit_verify.setText("pass")
self.dialog.turn_off_checkbox.setChecked(True)
@ -578,7 +578,7 @@ class BackupTest(unittest.TestCase):
is self.dialog.select_dir_page)
self._select_location("dom0")
self.dialog.dir_line_edit.setText("/home/user")
self.dialog.dir_line_edit.setText("/home")
self.dialog.passphrase_line_edit.setText("pass")
self.dialog.passphrase_line_edit_verify.setText("pass")
self.dialog.turn_off_checkbox.setChecked(True)

View File

@ -0,0 +1,73 @@
#!/usr/bin/python3
#
# The Qubes OS Project, https://www.qubes-os.org/
#
# Copyright (C) 2016 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 General Public License as published by
# the Free Software Foundation; either version 2 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
import logging.handlers
import unittest.mock
import sys
from PyQt4 import QtGui
from qubesadmin import Qubes
from qubesmanager import backup_utils
class BackupUtilsTest(unittest.TestCase):
def setUp(self):
super(BackupUtilsTest, self).setUp()
self.qapp = Qubes()
self.qtapp = QtGui.QApplication(["test", "-style", "cleanlooks"])
def tearDown(self):
self.qtapp.deleteLater()
super(BackupUtilsTest, self).tearDown()
def test_01_fill_apvms(self):
dialog = QtGui.QDialog()
combobox = QtGui.QComboBox()
dialog.appvm_combobox = combobox
dialog.qubes_app = self.qapp
backup_utils.fill_appvms_list(dialog)
# see if the dialog has nothing selected
self.assertEqual(combobox.currentIndex(), 0,
"Incorrect item selected")
# the combobox should contain running VMs that are not internal and
# not template
expected_vm_list = [vm.name for vm in self.qapp.domains
if vm.is_running() and vm.klass != 'TemplateVM'
and not getattr(vm, 'internal', False)]
received_vm_list = []
for i in range(combobox.count()):
received_vm_list.append(combobox.itemText(i))
self.assertListEqual(sorted(expected_vm_list), sorted(received_vm_list),
"VM list not filled correctly")
if __name__ == "__main__":
ha_syslog = logging.handlers.SysLogHandler('/dev/log')
ha_syslog.setFormatter(
logging.Formatter('%(name)s[%(process)d]: %(message)s'))
logging.root.addHandler(ha_syslog)
unittest.main()