tests: extend mock objects in QubesVM tests
- allow TestQubesDB to be populated with initial data - support list() method - allow to register pre-created VM instance (useful for AdminVM, which don't accept setting qid)
This commit is contained in:
parent
e092b40350
commit
9bf0cce11e
@ -39,6 +39,7 @@ import shutil
|
|||||||
import qubes
|
import qubes
|
||||||
import qubes.exc
|
import qubes.exc
|
||||||
import qubes.config
|
import qubes.config
|
||||||
|
import qubes.devices
|
||||||
import qubes.vm
|
import qubes.vm
|
||||||
import qubes.vm.qubesvm
|
import qubes.vm.qubesvm
|
||||||
|
|
||||||
@ -79,8 +80,10 @@ class TestDeviceCollection(object):
|
|||||||
return self._list
|
return self._list
|
||||||
|
|
||||||
class TestQubesDB(object):
|
class TestQubesDB(object):
|
||||||
def __init__(self):
|
def __init__(self, data=None):
|
||||||
self.data = {}
|
self.data = {}
|
||||||
|
if data:
|
||||||
|
self.data = data
|
||||||
|
|
||||||
def write(self, path, value):
|
def write(self, path, value):
|
||||||
self.data[path] = value
|
self.data[path] = value
|
||||||
@ -92,6 +95,12 @@ class TestQubesDB(object):
|
|||||||
else:
|
else:
|
||||||
self.data.pop(path, None)
|
self.data.pop(path, None)
|
||||||
|
|
||||||
|
def list(self, prefix):
|
||||||
|
return [key for key in self.data if key.startswith(prefix)]
|
||||||
|
|
||||||
|
def close(self):
|
||||||
|
pass
|
||||||
|
|
||||||
class TestVM(object):
|
class TestVM(object):
|
||||||
# pylint: disable=too-few-public-methods
|
# pylint: disable=too-few-public-methods
|
||||||
app = TestApp()
|
app = TestApp()
|
||||||
@ -269,7 +278,8 @@ class QubesVMTestsMixin(object):
|
|||||||
pass
|
pass
|
||||||
super(QubesVMTestsMixin, self).tearDown()
|
super(QubesVMTestsMixin, self).tearDown()
|
||||||
|
|
||||||
def get_vm(self, name='test', cls=qubes.vm.qubesvm.QubesVM, **kwargs):
|
def get_vm(self, name='test', cls=qubes.vm.qubesvm.QubesVM, vm=None, **kwargs):
|
||||||
|
if not vm:
|
||||||
vm = cls(self.app, None,
|
vm = cls(self.app, None,
|
||||||
qid=kwargs.pop('qid', 1), name=qubes.tests.VMPREFIX + name,
|
qid=kwargs.pop('qid', 1), name=qubes.tests.VMPREFIX + name,
|
||||||
**kwargs)
|
**kwargs)
|
||||||
|
Loading…
Reference in New Issue
Block a user