From 47e346efbf73001fd19975e534d969dfb29e2bfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Wed, 10 Feb 2016 17:11:50 +0100 Subject: [PATCH] tests: initialize Qubes() object in SystemTestsMixin, add handy helpers Most of the tests needs existing template, so add helper to copy it from "host" collection. Add also helpers to reload qubes.xml - in case of modification of it from some other process. --- qubes/tests/__init__.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/qubes/tests/__init__.py b/qubes/tests/__init__.py index 21e216dd..d57b78d8 100644 --- a/qubes/tests/__init__.py +++ b/qubes/tests/__init__.py @@ -349,6 +349,32 @@ class SystemTestsMixin(object): super(SystemTestsMixin, self).setUp() self.remove_test_vms() + # need some information from the real qubes.xml - at least installed + # templates; should not be used for testing, only to initialize self.app + self.host_app = qubes.Qubes() + self.app = qubes.Qubes.create_empty_store(qubes.tests.XMLPATH, + default_kernel=self.host_app.default_kernel, + clockvm=None, + updatevm=None + ) + + def init_default_template(self, template=None): + if template is None: + template = self.host_app.default_template + + template_vm = self.app.add_new_vm(qubes.vm.templatevm.TemplateVM, + name=template.name, + uuid=template.uuid, + label='black') + self.app.default_template = template_vm + + def reload_db(self): + self.app = qubes.Qubes(qubes.tests.XMLPATH) + + def save_and_reload_db(self): + self.app.save() + self.reload_db() + def tearDown(self): super(SystemTestsMixin, self).tearDown() self.remove_test_vms()