Exemplo n.º 1
0
def test_supports_extra_jinja_vars(tmpdir):
    load = Loader(variables={'test': 'bar'})
    example = '{"Description": "{{ test | title }}"}'
    with Path(tmpdir):
        with open('test.template.json', 'w') as f:
            f.write(example)
        load.load()
        actual = json.loads(load.template())
    assert actual == {"Description": "Bar"}
Exemplo n.º 2
0
def test_module_vars_have_precedence_over_global(tmpdir):
    load = Loader(variables={'test': 'bar'})
    example = '{"Description": "{{ test }}"}'
    with Path(tmpdir):
        os.mkdir('moduledir')
        with open('moduledir/test.template.json', 'w') as f:
            f.write(example)
        with open('test.template.json', 'w') as f:
            f.write('{"Resources": {"TestResource": {"From": "Moduledir", "Properties": {"test": "baz" } }}}')
        load.load()
        actual = json.loads(load.template())
    assert actual == {"Description": "baz"}
Exemplo n.º 3
0
def test_code_passes_variables(tmpdir):
    load = Loader(variables={'SomeVariable': 'SomeValue'})
    template = '{"Resources": {"{{code("testfile")}}": "Test"}}'
    code = '{{SomeVariable}}'
    with Path(tmpdir):
        with open('test.template.json', 'w') as f:
            f.write(template)
        with open('testfile', 'w') as f:
            f.write(code)
        load.load()

        actual = json.loads(load.template())
    assert actual == {"Resources": {"SomeValue": "Test"}}