def test_succeed_state_creation():
    succeed_state = Succeed(state_id='Succeed', comment='This is a comment')
    assert succeed_state.state_id == 'Succeed'
    assert succeed_state.comment == 'This is a comment'
    assert succeed_state.to_dict() == {
        'Type': 'Succeed',
        'Comment': 'This is a comment'
    }
Exemple #2
0
def test_choice_state_with_placeholders():

    first_state = Task(
        'FirstState',
        resource='arn:aws:lambda:us-east-1:1234567890:function:FirstState')
    retry = Chain([Pass('Retry'), Pass('Cleanup'), first_state])

    choice_state = Choice('Is Completed?')
    choice_state.add_choice(
        ChoiceRule.BooleanEquals(choice_state.output()["Completed"], True),
        Succeed('Complete'))
    choice_state.add_choice(
        ChoiceRule.BooleanEquals(choice_state.output()["Completed"], False),
        retry)

    first_state.next(choice_state)

    result = Graph(first_state).to_dict()

    expected_repr = {
        "StartAt": "FirstState",
        "States": {
            "FirstState": {
                "Resource":
                "arn:aws:lambda:us-east-1:1234567890:function:FirstState",
                "Type": "Task",
                "Next": "Is Completed?"
            },
            "Is Completed?": {
                "Type":
                "Choice",
                "Choices": [{
                    "Variable": "$['Completed']",
                    "BooleanEquals": True,
                    "Next": "Complete"
                }, {
                    "Variable": "$['Completed']",
                    "BooleanEquals": False,
                    "Next": "Retry"
                }]
            },
            "Complete": {
                "Type": "Succeed"
            },
            "Retry": {
                "Type": "Pass",
                "Next": "Cleanup"
            },
            "Cleanup": {
                "Type": "Pass",
                "Next": "FirstState"
            }
        }
    }

    assert result == expected_repr
def test_append_states_after_terminal_state_will_fail():
    with pytest.raises(ValueError):
        chain = Chain()
        chain.append(Pass('Pass'))
        chain.append(Fail('Fail'))
        chain.append(Pass('Pass2'))

    with pytest.raises(ValueError):
        chain = Chain()
        chain.append(Pass('Pass'))
        chain.append(Succeed('Succeed'))
        chain.append(Pass('Pass2'))
Exemple #4
0
def test_wait_loop():
    first_state = Task(
        'FirstState',
        resource='arn:aws:lambda:us-east-1:1234567890:function:FirstState')
    retry = Chain([Pass('Retry'), Pass('Cleanup'), first_state])

    choice_state = Choice('Is Completed?')
    choice_state.add_choice(ChoiceRule.BooleanEquals('$.Completed', True),
                            Succeed('Complete'))
    choice_state.add_choice(ChoiceRule.BooleanEquals('$.Completed', False),
                            retry)
    first_state.next(choice_state)

    result = Graph(first_state).to_dict()
    assert result == {
        'StartAt': 'FirstState',
        'States': {
            'FirstState': {
                'Type': 'Task',
                'Resource':
                'arn:aws:lambda:us-east-1:1234567890:function:FirstState',
                'Next': 'Is Completed?'
            },
            'Is Completed?': {
                'Type':
                'Choice',
                'Choices': [{
                    'Variable': '$.Completed',
                    'BooleanEquals': True,
                    'Next': 'Complete'
                }, {
                    'Variable': '$.Completed',
                    'BooleanEquals': False,
                    'Next': 'Retry'
                }]
            },
            'Complete': {
                'Type': 'Succeed'
            },
            'Retry': {
                'Type': 'Pass',
                'Next': 'Cleanup',
            },
            'Cleanup': {
                'Type': 'Pass',
                'Next': 'FirstState'
            }
        }
    }
Exemple #5
0
def test_nested_parallel_example():
    nested_level_1 = Parallel('NestedStateLevel1')
    nested_level_1.add_branch(Succeed('NestedStateLevel2'))

    first_state = Parallel('FirstState')
    first_state.add_branch(nested_level_1)

    result = Graph(first_state,
                   comment='This is a test.',
                   version='1.0',
                   timeout_seconds=3600).to_dict()
    assert result == {
        'StartAt': 'FirstState',
        'Comment': 'This is a test.',
        'Version': '1.0',
        'TimeoutSeconds': 3600,
        'States': {
            'FirstState': {
                'Type':
                'Parallel',
                'Branches': [{
                    'StartAt': 'NestedStateLevel1',
                    'States': {
                        'NestedStateLevel1': {
                            'Type':
                            'Parallel',
                            'Branches': [{
                                'StartAt': 'NestedStateLevel2',
                                'States': {
                                    'NestedStateLevel2': {
                                        'Type': 'Succeed'
                                    }
                                }
                            }],
                            'End':
                            True
                        }
                    }
                }],
                'End':
                True
            }
        }
    }
def test_verify_succeed_state_fields():
    with pytest.raises(TypeError):
        Succeed('Succeed', unknown_field='Unknown Field')