|
| 1 | +import time |
| 2 | +import json |
| 3 | +import pytest |
| 4 | +import boto3 |
| 5 | + |
| 6 | +@pytest.fixture |
| 7 | +def stepfunctions_client(): |
| 8 | + return boto3.client( |
| 9 | + "stepfunctions", region_name="us-east-1", endpoint_url="http://localhost:4566" |
| 10 | + ) |
| 11 | + |
| 12 | +@pytest.fixture |
| 13 | +def dynamodb_client(): |
| 14 | + return boto3.client( |
| 15 | + "dynamodb", region_name="us-east-1", endpoint_url="http://localhost:4566" |
| 16 | + ) |
| 17 | + |
| 18 | +def test_loan_broker_workflow(stepfunctions_client, dynamodb_client): |
| 19 | + response = stepfunctions_client.list_state_machines() |
| 20 | + state_machines = response["stateMachines"] |
| 21 | + |
| 22 | + state_machine_arn = None |
| 23 | + for state_machine in state_machines: |
| 24 | + if state_machine["name"].startswith( |
| 25 | + "LoanBroker-RecipientList-Stack-LoanBroker" |
| 26 | + ): |
| 27 | + state_machine_arn = state_machine["stateMachineArn"] |
| 28 | + break |
| 29 | + |
| 30 | + assert ( |
| 31 | + state_machine_arn is not None |
| 32 | + ), "State machine with specified prefix not found" |
| 33 | + |
| 34 | + dynamodb_client.put_item( |
| 35 | + TableName="LoanBrokerBanksTable", |
| 36 | + Item={ |
| 37 | + "Type": {"S": "Home"}, |
| 38 | + "BankAddress": { |
| 39 | + "L": [ |
| 40 | + {"S": "BankRecipientPremium"}, |
| 41 | + {"S": "BankRecipientUniversal"}, |
| 42 | + {"S": "BankRecipientPawnshop"}, |
| 43 | + ] |
| 44 | + }, |
| 45 | + }, |
| 46 | + ) |
| 47 | + |
| 48 | + start_response = stepfunctions_client.start_execution( |
| 49 | + stateMachineArn=state_machine_arn, |
| 50 | + name="cli-test-run", |
| 51 | + input='{"SSN": "123-45-6789", "Amount": 500000, "Term": 30}', |
| 52 | + ) |
| 53 | + execution_arn = start_response["executionArn"] |
| 54 | + |
| 55 | + time.sleep(10) |
| 56 | + |
| 57 | + describe_response = stepfunctions_client.describe_execution( |
| 58 | + executionArn=execution_arn |
| 59 | + ) |
| 60 | + output_json = json.loads(describe_response["output"]) |
| 61 | + |
| 62 | + assert "SSN" in output_json |
| 63 | + assert "Amount" in output_json |
| 64 | + assert "Term" in output_json |
| 65 | + assert "Credit" in output_json |
| 66 | + assert "Banks" in output_json |
| 67 | + assert "Quotes" in output_json |
0 commit comments