app: add VMCollection.values()

Let it behave more like a dict()
This commit is contained in:
Marek Marczykowski-Górecki 2017-08-08 22:11:48 +02:00
parent 7d476f8ba2
commit 7d25f1bf2b
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
2 changed files with 25 additions and 0 deletions

View File

@ -109,6 +109,11 @@ class VMCollection(object):
self.refresh_cache()
return self._vm_list.keys()
def values(self):
'''Get list of VM objects.'''
self.refresh_cache()
return [self[name] for name in self._vm_list]
class QubesBase(qubesadmin.base.PropertyHolder):
'''Main Qubes application'''

View File

@ -80,6 +80,26 @@ class TC_00_VMCollection(qubesadmin.tests.QubesTestCase):
del self.app.domains['test-vm']
self.assertAllCalled()
def test_005_keys(self):
self.app.expected_calls[('dom0', 'admin.vm.List', None, None)] = \
b'0\x00test-vm class=AppVM state=Running\n' \
b'test-vm2 class=AppVM state=Running\n'
self.assertEqual(set(self.app.domains.keys()),
set(['test-vm', 'test-vm2']))
self.assertAllCalled()
def test_006_values(self):
self.app.expected_calls[('dom0', 'admin.vm.List', None, None)] = \
b'0\x00test-vm class=AppVM state=Running\n' \
b'test-vm2 class=AppVM state=Running\n'
values = self.app.domains.values()
for obj in values:
self.assertIsInstance(obj, qubesadmin.vm.AppVM)
self.assertEqual(set([vm.name for vm in values]),
set(['test-vm', 'test-vm2']))
self.assertAllCalled()
class TC_10_QubesBase(qubesadmin.tests.QubesTestCase):
def test_010_new_simple(self):