コード例 #1
0
 def test_lookup_property_uses_settings(self, mock_settings):
     mock_settings.setting = "foobar"
     config._config = {'some/fsm.yaml': {'machines': []}}
     fsm = FSM(config_dict=self.CONFIG_DICT)
     instance = fsm.create_FSM_instance('foo', initial_system_context={})
     self.assertEqual(
         "foobar", instance._lookup_property("key", "setting", "default"))
コード例 #2
0
 def _dispatch_client_error(self, mock_time, mock_uuid, retries=0):
     mock_time.time.return_value = 100.
     mock_uuid.uuid4.return_value.hex = 'foobar'
     config._config = {'some/fsm.yaml': {'machines': []}}
     config_dict = copy.deepcopy(self.CONFIG_DICT)
     config_dict['machines'][1]['states'][0][
         'do_action'] = 'tests.aws_lambda_fsm.test_fsm.ErrorAction'
     payload = {
         "system_context": {
             "machine_name": "m",
             "current_state": "s",
             "current_event": "e",
             "correlation_id": "b",
             "steps": 999,
             "retries": retries
         },
         "user_context": {}
     }
     fsm = FSM(config_dict=config_dict)
     instance = fsm.create_FSM_instance(
         'foo',
         initial_state_name='pseudo_init',
         initial_system_context=payload['system_context'],
         initial_user_context=payload['user_context'])
     instance._dispatch_and_retry('pseudo_init', {
         'payload': json.dumps(payload),
         'source': 'dynamodb_retry'
     })
     return instance
コード例 #3
0
 def _dispatch(self, mock_send_next_event_for_dispatch):
     config._config = {'some/fsm.yaml': {'machines': []}}
     fsm = FSM(config_dict=self.CONFIG_DICT)
     payload = {
         "system_context": {
             "machine_name": "foo",
             "current_state": "s",
             "current_event": "e",
             "correlation_id": "b",
             "steps": 999,
             "retries": 0,
             "metrics": "m",
             "stream": "s",
             "topic": "z",
             "table": "t"
         },
         "user_context": {},
         "version": "0.1"
     }
     instance = fsm.create_FSM_instance(
         'foo',
         initial_state_name='pseudo_init',
         initial_system_context=payload['system_context'],
         initial_user_context=payload['user_context'])
     mock_send_next_event_for_dispatch.return_value = {'put': 'record'}
     instance._dispatch_and_retry('pseudo_init', {
         'payload': json.dumps(payload),
         'source': 'dynamodb_retry'
     })
     return instance
コード例 #4
0
    def _instance(self, initial_system_context=None):
        # test the factory
        config._config = {'some/fsm.yaml': {'machines': []}}
        fsm = FSM(config_dict=self.CONFIG_DICT)
        self.assertEqual({
            'foo': {
                'max_retries': 5,
                'states': {
                    'a': fsm.machines['foo']['states']['a'],
                    'b': fsm.machines['foo']['states']['b'],
                    'pseudo_init': fsm.machines['foo']['states']['pseudo_init'],
                    'pseudo_final': fsm.machines['foo']['states']['pseudo_final']
                },
                'transitions': {
                    'a->b:c': fsm.machines['foo']['transitions']['a->b:c'],
                    'b->pseudo_final:pseudo_final': fsm.machines['foo']['transitions']['b->pseudo_final:pseudo_final'],
                    'pseudo_init->a:pseudo_init': fsm.machines['foo']['transitions']['pseudo_init->a:pseudo_init']

                }
            }
        }, fsm.machines)

        # test the instance
        instance = fsm.create_FSM_instance('foo',
                                           initial_state_name='a',
                                           initial_system_context=initial_system_context)
        return instance
コード例 #5
0
 def _instance(self):
     config._config = {'some/fsm.yaml': {'machines': []}}
     fsm = FSM(config_dict=self.CONFIG_DICT)
     instance = fsm.create_FSM_instance(
         'foo',
         initial_state_name='pseudo_init',
         initial_system_context={'correlation_id': 'foobar'})
     return instance
コード例 #6
0
 def test_FSM_empty(self):
     config_dict = {'machines': []}
     fsm = FSM(config_dict=config_dict)
     self.assertEqual({}, fsm.machines)
     fsm = FSM(config_dict=config_dict)
     self.assertEqual({}, fsm.machines)
コード例 #7
0
 def test_correlation_id(self):
     config._config = {'some/fsm.yaml': {'machines': []}}
     fsm = FSM(config_dict=self.CONFIG_DICT)
     instance = fsm.create_FSM_instance(
         'foo', initial_system_context={'correlation_id': 'barfoo'})
     self.assertEqual('barfoo', instance.correlation_id)
コード例 #8
0
 def test_FSM_default(self):
     FSM()
コード例 #9
0
 def test_correlation_id_not_set(self, mock_uuid):
     mock_uuid.uuid4.return_value.hex = 'foobar'
     config._config = {'some/fsm.yaml': {'machines': []}}
     fsm = FSM(config_dict=self.CONFIG_DICT)
     instance = fsm.create_FSM_instance('foo')
     self.assertEqual('foobar', instance.correlation_id)
コード例 #10
0
 def test_initialize(self, mock_dispatch):
     config._config = {'some/fsm.yaml': {'machines': []}}
     fsm = FSM(config_dict=self.CONFIG_DICT)
     instance = fsm.create_FSM_instance('foo')
     instance.initialize()
     mock_dispatch.assert_called_with('foo', 'pseudo_init', None)
コード例 #11
0
 def setUp(self):
     AWS.reset()
     FSM(get_current_configuration('./fsm.yaml'))
コード例 #12
0
 def setUp(self):
     AWS.reset()
     FSM(get_current_configuration('tests/integration/fsm.yaml'))
コード例 #13
0
 def test_additional_delay_seconds(self):
     config._config = {'some/fsm.yaml': {'machines': []}}
     fsm = FSM(config_dict=self.CONFIG_DICT)
     instance = fsm.create_FSM_instance(
         'foo', initial_system_context={'additional_delay_seconds': 999})
     self.assertEqual(999, instance.additional_delay_seconds)
コード例 #14
0
 def setUp(self):
     AWS.reset()
     FSM(get_current_configuration('tests/functional/fsm.yaml'))