Пример #1
0
def test_setting_catcher_on_task_works():
    t2 = Task("foob",
              resource=Resource("sfs", type=ResourceType.LAMBDA))

    t = Task(
        name="catachable",
        resource=Resource(name="foo-trigger", type=ResourceType.LAMBDA),
        catch=[Catcher(error_equals=[ErrorType.TASK_FAILED], next=t2)]
    )
    assert read_json_test_case("catcher_in_the_task") == json.dumps(
        t, default=to_serializable)
Пример #2
0
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()
Пример #3
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
Пример #4
0
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
Пример #5
0
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])
Пример #6
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
Пример #7
0
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'
Пример #8
0
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
Пример #9
0
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()
Пример #10
0
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"}"""
Пример #11
0
def test_setting_timeout_works():
    t = Task("foo", timeout_seconds=7, resource=Resource(
        "fooRes", type=ResourceType.LAMBDA))
    assert t.TimeoutSeconds == 7
Пример #12
0
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")
Пример #13
0
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}"""
Пример #14
0
def test_resource_to_json():
    res = Resource(name="foo-trigger", type=ResourceType.LAMBDA,
                   aws_ac=1234, region="eu-west-1")
    assert json.dumps(res,
                      default=to_serializable) == '"arn:aws:lambda:eu-west-1:1234:function:foo-trigger"'