def test_list_runs(make_stubber, run_status, error_code):
    stepfunctions_client = boto3.client('stepfunctions')
    stepfunctions_stubber = make_stubber(stepfunctions_client)
    state_machine = StepFunctionsStateMachine(stepfunctions_client)
    state_machine.state_machine_arn = 'test-arn'
    runs = [{
        'name': name,
        'executionArn': arn
    } for name, arn in [('run-name-1', 'run-arn-1'), ('run-name-2',
                                                      'run-arn-2')]]

    stepfunctions_stubber.stub_list_executions(state_machine.state_machine_arn,
                                               runs,
                                               run_status,
                                               error_code=error_code)

    if error_code is None:
        got_runs = state_machine.list_runs(run_status)
        assert [{
            'name': run['name'],
            'executionArn': run['executionArn']
        } for run in got_runs] == runs
    else:
        with pytest.raises(ClientError) as exc_info:
            state_machine.list_runs(run_status)
        assert exc_info.value.response['Error']['Code'] == error_code
def test_describe(make_stubber, error_code):
    stepfunctions_client = boto3.client('stepfunctions')
    stepfunctions_stubber = make_stubber(stepfunctions_client)
    state_machine = StepFunctionsStateMachine(stepfunctions_client)
    state_machine.state_machine_arn = 'test-state_machine_arn'
    name = 'test-name'
    definition = 'test-definition'
    role_arn = 'test-role_arn'

    stepfunctions_stubber.stub_describe_state_machine(
        state_machine.state_machine_arn,
        name,
        definition,
        role_arn,
        error_code=error_code)

    if error_code is None:
        got_response = state_machine.describe()
        assert got_response['name'] == name
        assert got_response['definition'] == definition
        assert got_response['roleArn'] == role_arn
        assert got_response[
            'stateMachineArn'] == state_machine.state_machine_arn
    else:
        with pytest.raises(ClientError) as exc_info:
            state_machine.describe()
        assert exc_info.value.response['Error']['Code'] == error_code
def test_delete(make_stubber, error_code):
    stepfunctions_client = boto3.client('stepfunctions')
    stepfunctions_stubber = make_stubber(stepfunctions_client)
    state_machine = StepFunctionsStateMachine(stepfunctions_client)
    state_machine.state_machine_arn = 'test-state_machine_arn'

    stepfunctions_stubber.stub_delete_state_machine(
        state_machine.state_machine_arn, error_code=error_code)

    if error_code is None:
        state_machine.delete()
    else:
        with pytest.raises(ClientError) as exc_info:
            state_machine.delete()
        assert exc_info.value.response['Error']['Code'] == error_code
def test_update(make_stubber, role_arn, error_code):
    stepfunctions_client = boto3.client('stepfunctions')
    stepfunctions_stubber = make_stubber(stepfunctions_client)
    state_machine = StepFunctionsStateMachine(stepfunctions_client)
    state_machine.state_machine_arn = 'test-arn'
    definition = {'Comment': 'test-definition'}

    stepfunctions_stubber.stub_update_state_machine(
        state_machine.state_machine_arn,
        definition,
        role_arn,
        error_code=error_code)

    if error_code is None:
        state_machine.update(definition, role_arn)
    else:
        with pytest.raises(ClientError) as exc_info:
            state_machine.update(definition, role_arn)
        assert exc_info.value.response['Error']['Code'] == error_code
def test_start_run(make_stubber, run_input, error_code):
    stepfunctions_client = boto3.client('stepfunctions')
    stepfunctions_stubber = make_stubber(stepfunctions_client)
    state_machine = StepFunctionsStateMachine(stepfunctions_client)
    state_machine.state_machine_arn = 'test-arn'
    run_name = 'test-run_name'
    run_arn = 'test-run_arn'

    stepfunctions_stubber.stub_start_execution(state_machine.state_machine_arn,
                                               run_name,
                                               run_arn,
                                               run_input,
                                               error_code=error_code)

    if error_code is None:
        got_run_arn = state_machine.start_run(run_name, run_input)
        assert got_run_arn == run_arn
    else:
        with pytest.raises(ClientError) as exc_info:
            state_machine.start_run(run_name, run_input)
        assert exc_info.value.response['Error']['Code'] == error_code