Example #1
0
def test_render_invalid_ref():
    t = {
        "Parameters": {"testParam": {"Default": "Test Value"}},
        "Conditions": {"Bar": {"Fn::Equals": [{"Ref": "testParam"}, "Test Value"]}},
        "Resources": {
            "Foo": {"Condition": "Bar", "Properties": {"Name": {"Ref": "FAKE!"}}}
        },
    }

    template = Template(t)

    with pytest.raises(Exception) as ex:
        _ = template.render()

    assert "not a valid Resource" in str(ex)
Example #2
0
def test_render_true():
    t = {
        "Parameters": {"testParam": {"Default": "Test Value"}},
        "Conditions": {"Bar": {"Fn::Equals": [{"Ref": "testParam"}, "Test Value"]}},
        "Resources": {"Foo": {"Condition": "Bar"}},
    }

    template = Template(t)

    result = template.render()

    assert t is not result, "Should not pass back a pointer to the same dict."

    assert template.Region == Template.Region, "Should set the default region."

    assert "Foo" in result["Resources"], "Resources should not be empty."

    assert result["Conditions"]["Bar"], "Condition should be true."

    assert result["Metadata"], "Metadata should be set."
Example #3
0
def test_render_false():
    params = {"testParam": "Not Test Value"}

    t = {
        "Parameters": {"testParam": {"Default": "Test Value"}},
        "Conditions": {"Bar": {"Fn::Equals": [{"Ref": "testParam"}, "Test Value"]}},
        "Resources": {
            "Foo": {"Condition": "Bar"},
            "Foobar": {
                "Properties": {"Something": {"Fn::Sub": "This is a ${testParam}"}}
            },
        },
    }

    template = Template(t)

    result = template.render(params, region="us-west-2")

    assert template.Region != Template.Region, "Should not set the default region."

    assert "Foo" not in result["Resources"], "Resources should be empty."

    assert not result["Conditions"]["Bar"], "Condition should be false."