__init__.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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.1 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 unittest
  21. import qubesmgmt
  22. import qubesmgmt.app
  23. class QubesTest(qubesmgmt.app.QubesBase):
  24. expected_calls = None
  25. actual_calls = None
  26. def __init__(self):
  27. super(QubesTest, self).__init__()
  28. #: expected calls and saved replies for them
  29. self.expected_calls = {}
  30. #: actual calls made
  31. self.actual_calls = []
  32. def _do_qubesd_call(self, dest, method, arg=None, payload=None):
  33. call_key = (dest, method, arg, payload)
  34. self.actual_calls.append(call_key)
  35. if call_key not in self.expected_calls:
  36. raise AssertionError('Unexpected call {!r}'.format(call_key))
  37. return_data = self.expected_calls[call_key]
  38. return self._parse_qubesd_response(return_data)
  39. class QubesTestCase(unittest.TestCase):
  40. def setUp(self):
  41. super(QubesTestCase, self).setUp()
  42. self.app = QubesTest()
  43. def assertAllCalled(self):
  44. self.assertEqual(
  45. set(self.app.expected_calls.keys()),
  46. set(self.app.actual_calls))