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_idx(): s = StateMachine() s.next( Task(resource=Resource("some", type=ResourceType.LAMBDA), name="Kermit", comment='Foo')) s.next( Task(resource=Resource("some", type=ResourceType.LAMBDA), name="Blobby", comment='Foo')) s.build() assert s.idx('Blobby') == 1 assert s.idx('Kermit') == 0 assert s.idx('NotPresent') == None
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_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_pass_wait(): s = StateMachine() s.next(Wait(name="Hold!")) s.next(Pass(name="Pass the buck")) s.next(Wait(name="Who you calling buck?", seconds=5)) s.build() assert s.count_states() == 3 assert s.last().Seconds == 5 assert s.to_json() == read_json_test_case('pass_wait')
def test_next_set_for_two_state_machine(): s = StateMachine() res = Resource(name="foores", type=ResourceType.LAMBDA) s.next(Task(resource=res, name="Kermit", comment='Foo')) s.next(Task(resource=res, name="Miss Piggy", comment='Foo')) s.build() assert len(s.get_states()) == 2 assert s.StartAt == "Kermit" assert s.get_states()[0]._next == s.get_states()[1].name(), s.printable() assert s.get_states()[-1]._next == None # only the last state should have an "End" key according to spec assert s.get_states()[0].End == None assert s.get_states()[-1].End == True
def test_add_state_does_not_update_next_property(): s = StateMachine() s.add_state( Task(resource=Resource("some", type=ResourceType.LAMBDA), name="Kermit", comment='Foo')) s.add_state( Task(resource=Resource("two", type=ResourceType.LAMBDA), name="Moia", comment='Foo')) s.build() assert s.get_states()[0]._next != s.get_states()[1].name(), s.printable()
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