test_backup_utils.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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.mock
  24. from PyQt5 import QtWidgets
  25. from qubesadmin import Qubes
  26. from qubesmanager import backup_utils
  27. from qubesmanager.tests import init_qtapp
  28. class BackupUtilsTest(unittest.TestCase):
  29. def setUp(self):
  30. super(BackupUtilsTest, self).setUp()
  31. self.qtapp, self.loop = init_qtapp()
  32. self.qapp = Qubes()
  33. def test_01_fill_apvms(self):
  34. dialog = QtWidgets.QDialog()
  35. combobox = QtWidgets.QComboBox()
  36. dialog.appvm_combobox = combobox
  37. dialog.qubes_app = self.qapp
  38. backup_utils.fill_appvms_list(dialog)
  39. # see if the dialog has nothing selected
  40. self.assertEqual(combobox.currentIndex(), 0,
  41. "Incorrect item selected")
  42. # the combobox should contain running VMs that are not internal and
  43. # not template
  44. expected_vm_list = [vm.name for vm in self.qapp.domains
  45. if vm.is_running() and vm.klass != 'TemplateVM'
  46. and not getattr(vm, 'internal', False)]
  47. received_vm_list = []
  48. for i in range(combobox.count()):
  49. received_vm_list.append(combobox.itemText(i))
  50. self.assertListEqual(sorted(expected_vm_list), sorted(received_vm_list),
  51. "VM list not filled correctly")
  52. if __name__ == "__main__":
  53. ha_syslog = logging.handlers.SysLogHandler('/dev/log')
  54. ha_syslog.setFormatter(
  55. logging.Formatter('%(name)s[%(process)d]: %(message)s'))
  56. logging.root.addHandler(ha_syslog)
  57. unittest.main()