tests: handle returning different response for the same request
Allow programming different responses for the same request when called multiple times. This is useful for example for shutdown tests - first domain is running, but after issuing shutdown request is is not.
This commit is contained in:
parent
5430e04e1c
commit
88de4f77a5
@ -135,6 +135,11 @@ class QubesTest(qubesadmin.app.QubesBase):
|
||||
if call_key not in self.expected_calls:
|
||||
raise AssertionError('Unexpected call {!r}'.format(call_key))
|
||||
return_data = self.expected_calls[call_key]
|
||||
if isinstance(return_data, list):
|
||||
try:
|
||||
return_data = return_data.pop(0)
|
||||
except IndexError:
|
||||
raise AssertionError('Extra call {!r}'.format(call_key))
|
||||
return self._parse_qubesd_response(return_data)
|
||||
|
||||
def run_service(self, dest, service, **kwargs):
|
||||
@ -152,6 +157,9 @@ class QubesTestCase(unittest.TestCase):
|
||||
self.assertEqual(
|
||||
set(self.app.expected_calls.keys()),
|
||||
set(self.app.actual_calls))
|
||||
# and also check if calls expected multiple times were called
|
||||
self.assertFalse(any(x for x in self.app.expected_calls.values() if
|
||||
isinstance(x, list)))
|
||||
|
||||
def assertNotRaises(self, excClass, callableObj=None, *args, **kwargs):
|
||||
"""Fail if an exception of class excClass is raised
|
||||
|
Loading…
Reference in New Issue
Block a user