app.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # -*- encoding: utf8 -*-
  2. #
  3. # The Qubes OS Project, http://www.qubes-os.org
  4. #
  5. # Copyright (C) 2017 Marek Marczykowski-Górecki
  6. # <marmarek@invisiblethingslab.com>
  7. #
  8. # This program is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU Lesser General Public License along
  19. # with this program; if not, see <http://www.gnu.org/licenses/>.
  20. import qubesmgmt.tests
  21. class TC_00_VMCollection(qubesmgmt.tests.QubesTestCase):
  22. def test_000_list(self):
  23. self.app.expected_calls[('dom0', 'mgmt.vm.List', None, None)] = \
  24. b'0\x00test-vm class=AppVM state=running\n'
  25. self.assertEqual(
  26. self.app.domains.keys(),
  27. ['test-vm'])
  28. self.assertAllCalled()
  29. def test_001_getitem(self):
  30. self.app.expected_calls[('dom0', 'mgmt.vm.List', None, None)] = \
  31. b'0\x00test-vm class=AppVM state=running\n'
  32. try:
  33. vm = self.app.domains['test-vm']
  34. self.assertEqual(vm._name, 'test-vm')
  35. except KeyError:
  36. self.fail('VM not found in collection')
  37. self.assertAllCalled()
  38. with self.assertRaises(KeyError):
  39. vm = self.app.domains['test-non-existent']
  40. self.assertAllCalled()
  41. def test_002_in(self):
  42. self.app.expected_calls[('dom0', 'mgmt.vm.List', None, None)] = \
  43. b'0\x00test-vm class=AppVM state=running\n'
  44. self.assertIn('test-vm', self.app.domains)
  45. self.assertAllCalled()
  46. self.assertNotIn('test-non-existent', self.app.domains)
  47. self.assertAllCalled()
  48. def test_003_iter(self):
  49. self.app.expected_calls[('dom0', 'mgmt.vm.List', None, None)] = \
  50. b'0\x00test-vm class=AppVM state=running\n'
  51. self.assertEqual([vm._name for vm in self.app.domains], ['test-vm'])
  52. self.assertAllCalled()