Example #1
0
def test_function_order():

    t = {
        "Parameters": {"Test": {"Value": "test"}},
        "Conditions": {"test": True},
    }

    template = Template(t)

    test_if = {
        "Fn::Cidr": {
            "Fn::If": "select",
        }
    }

    with pytest.raises(ValueError) as ex:
        _ = template.resolve_values(test_if, functions.ALL_FUNCTIONS)

    assert "Fn::If not allowed here." in str(ex)

    with pytest.raises(ValueError) as ex:
        _ = template.resolve_values({"Fn::Base64": ""}, functions.CONDITIONS)

    assert "Fn::Base64 not allowed here." in str(ex)

    with pytest.raises(ValueError) as ex:
        _ = template.resolve_values({"Fn::Not": ""}, functions.INTRINSICS)

    assert "Fn::Not not allowed here." in str(ex)
Example #2
0
def test_resolve():
    t = {
        "Parameters": {"Test": {"Value": "test"}},
        "Conditions": {"test": True},
        "Resources": {},
    }

    template = Template(t)

    result = template.resolve_values({"Ref": "Test"}, functions.ALL_FUNCTIONS)

    assert result == "test", "Should resolve the value from the template."

    with pytest.raises(Exception) as ex:
        result = template.resolve_values({"Ref": "Test2"}, functions.ALL_FUNCTIONS)

    assert "not a valid Resource" in str(ex)

    result = template.resolve_values(
        {"level1": {"Fn::If": ["test", "True", "False"]}}, functions.ALL_FUNCTIONS
    )

    assert result == {"level1": "True"}, "Should resolve nested dicts."

    result = template.resolve_values(
        [{"level1": {"Fn::If": ["test", "True", "False"]}}], functions.ALL_FUNCTIONS
    )

    assert result == [{"level1": "True"}], "Should resolve nested lists."

    result = template.resolve_values("test", functions.ALL_FUNCTIONS)

    assert result == "test", "Should return regular strings."