From 484743faf05d497d44e72db4ac83255c7f8cd60e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Thu, 9 Mar 2017 02:06:54 +0100 Subject: [PATCH] tests: add qubes-prefs tests Based on qvm-prefs. --- qubesmgmt/tests/tools/qubes_prefs.py | 68 ++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 qubesmgmt/tests/tools/qubes_prefs.py diff --git a/qubesmgmt/tests/tools/qubes_prefs.py b/qubesmgmt/tests/tools/qubes_prefs.py new file mode 100644 index 0000000..0ebdff8 --- /dev/null +++ b/qubesmgmt/tests/tools/qubes_prefs.py @@ -0,0 +1,68 @@ +# -*- encoding: utf8 -*- +# +# The Qubes OS Project, http://www.qubes-os.org +# +# Copyright (C) 2017 Marek Marczykowski-Górecki +# +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation; either version 2.1 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License along +# with this program; if not, see . + +import qubesmgmt.tests +import qubesmgmt.tests.tools +import qubesmgmt.tools.qubes_prefs + + +class TC_00_qubes_prefs(qubesmgmt.tests.QubesTestCase): + def test_000_list(self): + self.app.expected_calls[ + ('dom0', 'mgmt.global.property.List', None, None)] = \ + b'0\x00prop1\nprop2\n' + self.app.expected_calls[ + ('dom0', 'mgmt.global.property.Get', 'prop1', None)] = \ + b'0\x00default=True \'value1\'' + self.app.expected_calls[ + ('dom0', 'mgmt.global.property.Get', 'prop2', None)] = \ + b'0\x00default=False \'value2\'' + with qubesmgmt.tests.tools.StdoutBuffer() as stdout: + self.assertEqual(0, qubesmgmt.tools.qubes_prefs.main([], app=self.app)) + self.assertEqual(stdout.getvalue(), + 'prop1 D value1\n' + 'prop2 - value2\n') + self.assertAllCalled() + + def test_002_set_property(self): + self.app.expected_calls[ + ('dom0', 'mgmt.global.property.Set', 'default_user', b'testuser')]\ + = b'0\x00' + self.assertEqual(0, qubesmgmt.tools.qubes_prefs.main([ + 'default_user', 'testuser'], app=self.app)) + self.assertAllCalled() + + def test_003_invalid_property(self): + self.app.expected_calls[ + ('dom0', 'mgmt.global.property.Get', 'no_such_property', None)] = \ + b'2\x00AttributeError\x00\x00no_such_property\x00' + with self.assertRaises(SystemExit): + qubesmgmt.tools.qubes_prefs.main([ + 'no_such_property'], app=self.app) + self.assertAllCalled() + + def test_004_set_invalid_property(self): + self.app.expected_calls[ + ('dom0', 'mgmt.global.property.Set', 'no_such_property', b'value')]\ + = b'2\x00AttributeError\x00\x00no_such_property\x00' + with self.assertRaises(SystemExit): + qubesmgmt.tools.qubes_prefs.main([ + 'no_such_property', 'value'], app=self.app) + self.assertAllCalled()