def setUp(self): super(ActionRunnerPluginTestCase, self).setUp() # counter for generating deterministic action IDs self._id_counter = 0 # ActionRunner tries to do access self._session._client.action_plugins # to get at ActionPluginManager self.client = mock.Mock() self.client.action_plugins = self.action_plugins self.session = mock.Mock() self.session._client = self.client self.action_runner = ActionRunnerPlugin(self.session)
class ActionRunnerPluginTestCase(ActionTestCase): def setUp(self): super(ActionRunnerPluginTestCase, self).setUp() # counter for generating deterministic action IDs self._id_counter = 0 # ActionRunner tries to do access self._session._client.action_plugins # to get at ActionPluginManager self.client = mock.Mock() self.client.action_plugins = self.action_plugins self.session = mock.Mock() self.session._client = self.client self.action_runner = ActionRunnerPlugin(self.session) def _run_action(self, action, args): """ Invoke an action by pretending that the manager sent a message """ id = "%s" % self._id_counter self._id_counter += 1 self.action_runner.on_message({ 'type': 'ACTION_START', 'id': id, 'action': action, 'args': args }) return id def _get_responses(self, count): # The ActionRunnerPlugin will run the action in a thread, and call send_message when it completes TIMEOUT = 2 i = 0 while self.mock_send_message_call_count < count: time.sleep(1) i += 1 if i > TIMEOUT: raise AssertionError( "Timed out after %ss waiting for %s responses (got %s)" % (TIMEOUT, count, DevicePlugin.send_message.call_count)) self.assertEqual(self.mock_send_message_call_count, count) return [args.body for args in self.mock_send_message_call_args_list]