Exemple #1
0
 def test_execute_with_action(self):
     context = Context('name', initial_user_context={'foo': 'bar'})
     self.assertEqual(None, context.current_state)
     action = mock.Mock()
     t = Transition('name', 'target', action=action)
     t.execute(context, 'obj')
     self.assertEqual('target', context.current_state)
     action.execute.assert_called_with({'foo': 'bar'}, 'obj')
    def _add_transition(self, machine_name, source, target, event, action=None):
        """
        A helper function to and an aws_lambda_fsm.transition.Transition instance to the machine.

        :param machine_name: a str name for the machine.
        :param source: an aws_lambda_fsm.state.State instance.
        :param target: an aws_lambda_fsm.state.State instance.
        :param event: a str event.
        :param action: an optional aws_lambda_fsm.action.Action instance.
        """
        transition_name = source.name + '->' + target.name + ':' + event
        transition = Transition(transition_name, target, action=action)
        self.machines[machine_name][MACHINE.TRANSITIONS][transition_name] = transition
        source.add_transition(transition, event)
Exemple #3
0
 def test_execute_no_action(self):
     context = Context('name')
     self.assertEqual(None, context.current_state)
     t = Transition('name', 'target')
     t.execute(context, None)
     self.assertEqual('target', context.current_state)