def test_execute_with_triggers(self): triggers = [Flag(action='regMatch', args={'regex': 'aaa'})] step = Step(app='HelloWorld', action='helloWorld', triggers=triggers) instance = AppInstance.create(app_name='HelloWorld', device_name='device1') step.send_data_to_trigger({"data_in": {"data": 'aaa'}}) result = {'triggered': False} @callbacks.data_sent.connect def callback_is_sent(sender, **kwargs): if kwargs['callback_name'] == "Trigger Step Taken": result['triggered'] = True step.execute(instance.instance, {}) self.assertTrue(result['triggered'])
def test_execute_multiple_triggers(self): triggers = [Flag(action='regMatch', args={'regex': 'aaa'})] step = Step(app='HelloWorld', action='helloWorld', triggers=triggers) instance = AppInstance.create(app_name='HelloWorld', device_name='device1') step.send_data_to_trigger({"data_in": {"data": 'a'}}) trigger_taken = {'triggered': 0} trigger_not_taken = {'triggered': 0} @callbacks.data_sent.connect def callback_is_sent(sender, **kwargs): if kwargs['callback_name'] == "Trigger Step Taken": trigger_taken['triggered'] += 1 elif kwargs['callback_name'] == "Trigger Step Not Taken": step.send_data_to_trigger({"data_in": {"data": 'aaa'}}) trigger_not_taken['triggered'] += 1 step.execute(instance.instance, {}) self.assertEqual(trigger_taken['triggered'], 1) self.assertEqual(trigger_not_taken['triggered'], 1)