How to use stepfunctions method in localstack

Best Python code snippet using localstack_python

test_stepfunctions_basics.py

Source:test_stepfunctions_basics.py Github

copy

Full Screen

1# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.2# SPDX-License-Identifier: Apache-2.03"""4Unit tests for stepfunctions_basics.py5"""6import boto37from botocore.exceptions import ClientError8import pytest9from stepfunctions_basics import StepFunctionsStateMachine10@pytest.mark.parametrize('error_code', [None, 'TestException'])11def test_create(make_stubber, error_code):12 stepfunctions_client = boto3.client('stepfunctions')13 stepfunctions_stubber = make_stubber(stepfunctions_client)14 state_machine = StepFunctionsStateMachine(stepfunctions_client)15 name = 'test-name'16 definition = {'Comment': 'test-definition'}17 role_arn = 'test-role-arn'18 arn = 'test-arn'19 stepfunctions_stubber.stub_create_state_machine(20 name, definition, role_arn, arn, error_code=error_code)21 if error_code is None:22 got_arn = state_machine.create(name, definition, role_arn)23 assert got_arn == arn24 assert state_machine.state_machine_name == name25 assert state_machine.state_machine_arn == arn26 else:27 with pytest.raises(ClientError) as exc_info:28 state_machine.create(name, definition, role_arn)29 assert exc_info.value.response['Error']['Code'] == error_code30@pytest.mark.parametrize('role_arn,error_code', [31 (None, None), ('test-role-arn', None), (None, 'TestException')])32def test_update(make_stubber, role_arn, error_code):33 stepfunctions_client = boto3.client('stepfunctions')34 stepfunctions_stubber = make_stubber(stepfunctions_client)35 state_machine = StepFunctionsStateMachine(stepfunctions_client)36 state_machine.state_machine_arn = 'test-arn'37 definition = {'Comment': 'test-definition'}38 stepfunctions_stubber.stub_update_state_machine(39 state_machine.state_machine_arn, definition, role_arn, error_code=error_code)40 if error_code is None:41 state_machine.update(definition, role_arn)42 else:43 with pytest.raises(ClientError) as exc_info:44 state_machine.update(definition, role_arn)45 assert exc_info.value.response['Error']['Code'] == error_code46@pytest.mark.parametrize('error_code', [None, 'TestException'])47def test_delete(make_stubber, error_code):48 stepfunctions_client = boto3.client('stepfunctions')49 stepfunctions_stubber = make_stubber(stepfunctions_client)50 state_machine = StepFunctionsStateMachine(stepfunctions_client)51 state_machine.state_machine_arn = 'test-state_machine_arn'52 stepfunctions_stubber.stub_delete_state_machine(53 state_machine.state_machine_arn, error_code=error_code)54 if error_code is None:55 state_machine.delete()56 else:57 with pytest.raises(ClientError) as exc_info:58 state_machine.delete()59 assert exc_info.value.response['Error']['Code'] == error_code60@pytest.mark.parametrize('found,error_code', [61 (True, None), (False, None), (True, 'TestException')])62def test_find(make_stubber, found, error_code):63 stepfunctions_client = boto3.client('stepfunctions')64 stepfunctions_stubber = make_stubber(stepfunctions_client)65 state_machine = StepFunctionsStateMachine(stepfunctions_client)66 state_machine_name = 'test-state_machine_name'67 state_machine_arn = 'test-arn'68 machine_data = [('wrong-name', 'wrong-arn')]69 if found:70 machine_data.append((state_machine_name, state_machine_arn))71 state_machines = [72 {'name': name, 'stateMachineArn': arn} for name, arn in machine_data]73 stepfunctions_stubber.stub_list_state_machines(74 state_machines, error_code=error_code)75 if error_code is None:76 got_state_machine_arn = state_machine.find(state_machine_name)77 if found:78 assert got_state_machine_arn == state_machine_arn79 else:80 assert got_state_machine_arn is None81 else:82 with pytest.raises(ClientError) as exc_info:83 state_machine.find(state_machine_name)84 assert exc_info.value.response['Error']['Code'] == error_code85@pytest.mark.parametrize('error_code', [None, 'TestException'])86def test_describe(make_stubber, error_code):87 stepfunctions_client = boto3.client('stepfunctions')88 stepfunctions_stubber = make_stubber(stepfunctions_client)89 state_machine = StepFunctionsStateMachine(stepfunctions_client)90 state_machine.state_machine_arn = 'test-state_machine_arn'91 name = 'test-name'92 definition = 'test-definition'93 role_arn = 'test-role_arn'94 stepfunctions_stubber.stub_describe_state_machine(95 state_machine.state_machine_arn, name, definition, role_arn,96 error_code=error_code)97 if error_code is None:98 got_response = state_machine.describe()99 assert got_response['name'] == name100 assert got_response['definition'] == definition101 assert got_response['roleArn'] == role_arn102 assert got_response['stateMachineArn'] == state_machine.state_machine_arn103 else:104 with pytest.raises(ClientError) as exc_info:105 state_machine.describe()106 assert exc_info.value.response['Error']['Code'] == error_code107@pytest.mark.parametrize('run_input,error_code', [108 ({'test-key': 'test-value'}, None),109 (None, None),110 ({'test-key': 'test-value'}, 'TestException')])111def test_start_run(make_stubber, run_input, error_code):112 stepfunctions_client = boto3.client('stepfunctions')113 stepfunctions_stubber = make_stubber(stepfunctions_client)114 state_machine = StepFunctionsStateMachine(stepfunctions_client)115 state_machine.state_machine_arn = 'test-arn'116 run_name = 'test-run_name'117 run_arn = 'test-run_arn'118 stepfunctions_stubber.stub_start_execution(119 state_machine.state_machine_arn, run_name, run_arn, run_input,120 error_code=error_code)121 if error_code is None:122 got_run_arn = state_machine.start_run(run_name, run_input)123 assert got_run_arn == run_arn124 else:125 with pytest.raises(ClientError) as exc_info:126 state_machine.start_run(run_name, run_input)127 assert exc_info.value.response['Error']['Code'] == error_code128@pytest.mark.parametrize('run_status,error_code', [129 ('test-run_status', None), (None, None), ('test-run_status', 'TestException')])130def test_list_runs(make_stubber, run_status, error_code):131 stepfunctions_client = boto3.client('stepfunctions')132 stepfunctions_stubber = make_stubber(stepfunctions_client)133 state_machine = StepFunctionsStateMachine(stepfunctions_client)134 state_machine.state_machine_arn = 'test-arn'135 runs = [{'name': name, 'executionArn': arn} for name, arn in136 [('run-name-1', 'run-arn-1'), ('run-name-2', 'run-arn-2')]]137 stepfunctions_stubber.stub_list_executions(138 state_machine.state_machine_arn, runs, run_status, error_code=error_code)139 if error_code is None:140 got_runs = state_machine.list_runs(run_status)141 assert [{'name': run['name'], 'executionArn': run['executionArn']}142 for run in got_runs] == runs143 else:144 with pytest.raises(ClientError) as exc_info:145 state_machine.list_runs(run_status)146 assert exc_info.value.response['Error']['Code'] == error_code147@pytest.mark.parametrize('error_code', [None, 'TestException'])148def test_stop_run(make_stubber, error_code):149 stepfunctions_client = boto3.client('stepfunctions')150 stepfunctions_stubber = make_stubber(stepfunctions_client)151 state_machine = StepFunctionsStateMachine(stepfunctions_client)152 run_arn = 'test-run_arn'153 cause = 'test cause'154 stepfunctions_stubber.stub_stop_execution(run_arn, cause, error_code=error_code)155 if error_code is None:156 state_machine.stop_run(run_arn, cause)157 else:158 with pytest.raises(ClientError) as exc_info:159 state_machine.stop_run(run_arn, cause)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful