Skip to content

Commit

Permalink
tests: handle returning different response for the same request
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
marmarek committed Jul 5, 2017
1 parent 5430e04 commit 88de4f7
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions qubesadmin/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ def qubesd_call(self, dest, method, arg=None, payload=None,
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):
Expand All @@ -152,6 +157,9 @@ def assertAllCalled(self):
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
Expand Down

0 comments on commit 88de4f7

Please sign in to comment.