test_backup_utils.py 2.7 KB

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