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
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
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"))
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
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
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)
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)
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)
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)