def test_machine_sets_region_and_ac(): s = StateMachine(region='eu-west-1', account=1234) s.next( Task(name="Hold!", resource=Resource("Foo", type=ResourceType.LAMBDA))) s.build() assert s.get_states()[0].Resource.region == 'eu-west-1' assert s.get_states()[0].Resource.aws_ac == 1234
def test_hello_machine(): s = StateMachine() s.next( Task(resource=Resource("some", type=ResourceType.LAMBDA), name="Kermit", comment='Foo')) s.build() assert len(s.get_states()) == 1 assert s.StartAt == s.get_states()[0].name(), str(s.get_states()[0])
def test_end_not_set_in_succeed_state(): s = StateMachine() s.next( Task(resource=Resource("some", type=ResourceType.LAMBDA), name="Blobby", comment='Foo')) s.next(Wait("Baz")) s.next(Succeed("Done")) s.build() print(s.to_json()) assert s.get_states()[-1].End is None
def test_last_orphan(): s = StateMachine() s.next( Task(resource=Resource("some", type=ResourceType.LAMBDA), name="Blobby", comment='Foo')) s.add_state(Pass("Boo")) s.add_state(Wait("Baz")) s.next(Succeed("Done")) s.build() assert s.idx('Blobby') == 0 assert s.get_states()[0].Next == 'Done'
def test_parallel(): t = Task( name="endstate", resource=Resource(name="foo-trigger", type=ResourceType.LAMBDA) ) branch_a = Branch("branchA") branch_a.next(t) branch_b = Branch("branchB") branch_b.next(t) p = Parallel("ABTest", branches=[branch_a, branch_b]) p.build() assert len(p.Branches) == 2 read_json_test_case("parallel_simple_state") == p.to_json()
def test_choice_to_json(): t = Task( name="endstate", resource=Resource(name="foo-trigger", type=ResourceType.LAMBDA) ) choices = [ChoiceCase(variable="Foovar", comparison=Comparison( comparison_type=ComparisonType.BOOLEAN_EQ, value=True), next=t) ] c = Choice(name="Foochoice", choices=choices, default=t) assert json.dumps(c, default=to_serializable) == \ """{"Type": "Choice", "Choices": [{"Variable": "Foovar", "Next": "endstate", "BooleanEquals": true}], "Default": "endstate"}"""
def test_setting_timeout_works(): t = Task("foo", timeout_seconds=7, resource=Resource( "fooRes", type=ResourceType.LAMBDA)) assert t.TimeoutSeconds == 7
def test_catcher_to_json(): c = Catcher(error_equals=[ErrorType.TASK_FAILED], next=Task("foo", resource=Resource("fooAct", type=ResourceType.ACTIVITY))) assert json.dumps(c, default=to_serializable) == read_json_test_case( "catcher_to_json")
def test_lambda_task_to_json(): assert json.dumps(Task(name="sdfdsf", resource=Resource(type=ResourceType.LAMBDA, name="trigger")), default=to_serializable) == \ """{"Type": "Task", "Resource": "arn:aws:lambda:::function:trigger", "TimeoutSeconds": 600}"""