def test_default_paths_not_included(): task_state = Task( 'Task', resource='arn:aws:lambda:us-east-1:1234567890:function:StartLambda') assert 'ResultPath' not in task_state.to_dict() assert 'InputPath' not in task_state.to_dict() assert 'OutputPath' not in task_state.to_dict()
def test_task_state_creation(): task_state = Task('Task', resource='arn:aws:lambda:us-east-1:1234567890:function:StartLambda') task_state.add_retry(Retry(error_equals=['ErrorA', 'ErrorB'], interval_seconds=1, max_attempts=2, backoff_rate=2)) task_state.add_retry(Retry(error_equals=['ErrorC'], interval_seconds=5)) task_state.add_catch(Catch(error_equals=['States.ALL'], next_step=Pass('End State'))) assert task_state.type == 'Task' assert len(task_state.retries) == 2 assert len(task_state.catches) == 1 assert task_state.to_dict() == { 'Type': 'Task', 'Resource': 'arn:aws:lambda:us-east-1:1234567890:function:StartLambda', 'Retry': [ { 'ErrorEquals': ['ErrorA', 'ErrorB'], 'IntervalSeconds': 1, 'BackoffRate': 2, 'MaxAttempts': 2 }, { 'ErrorEquals': ['ErrorC'], 'IntervalSeconds': 5 } ], 'Catch': [ { 'ErrorEquals': ['States.ALL'], 'Next': 'End State' } ], 'End': True }
def test_task_state_creation_with_dynamic_timeout(): task_state = Task( 'Task', resource='arn:aws:lambda:us-east-1:1234567890:function:StartLambda', timeout_seconds_path='$.timeout', heartbeat_seconds_path='$.heartbeat', ) assert task_state.to_dict() == { 'Type': 'Task', 'Resource': 'arn:aws:lambda:us-east-1:1234567890:function:StartLambda', 'HeartbeatSecondsPath': '$.heartbeat', 'TimeoutSecondsPath': '$.timeout', 'End': True }
def test_paths_none(): task_state = Task('Task', resource='arn:aws:lambda:us-east-1:1234567890:function:StartLambda', result_path=None, input_path=None, output_path=None) assert 'ResultPath' in task_state.to_dict() assert task_state.to_dict()['ResultPath'] is None assert 'InputPath' in task_state.to_dict() assert task_state.to_dict()['InputPath'] is None assert 'OutputPath' in task_state.to_dict() assert task_state.to_dict()['OutputPath'] is None
def test_step_result_placeholder(): step_result = StepResult() test_step_01 = Task(state_id="StateOne", result_selector={ "ParamA": step_result["foo"], "ParamC": "SampleValueC" }) expected_repr = { "Type": "Task", "ResultSelector": { "ParamA.$": "$['foo']", "ParamC": "SampleValueC" }, "End": True } assert test_step_01.to_dict() == expected_repr
def test_task_state_add_catch_adds_catcher_to_catchers(catch, expected_catch): step = Task('Task') step.add_catch(catch) assert step.to_dict()['Catch'] == expected_catch
def test_task_state_constructor_with_catch_adds_catcher_to_catchers( catch, expected_catch): step = Task('Task', catch=catch) assert step.to_dict()['Catch'] == expected_catch
def test_task_state_add_retry_adds_retrier_to_retriers(retry, expected_retry): step = Task('Task') step.add_retry(retry) assert step.to_dict()['Retry'] == expected_retry
def test_task_state_constructor_with_retry_adds_retrier_to_retriers( retry, expected_retry): step = Task('Task', retry=retry) assert step.to_dict()['Retry'] == expected_retry