Example #1
0
def test_render_template_nested():
    """Nested values from a configparser instance should
    render as values not as the name of the section
    """
    from tapis_cli.templating import render_template
    source = 'App Name {{ app.name }} is cool'
    rendered = render_template(source)
    raise SystemError(rendered)
Example #2
0
def test_render_template_nested():
    """Nested values from a configparser instance should
    render as values not as the name of the section
    """
    from tapis_cli.templating import render_template
    source = 'App Name {{ app.name }} is cool'
    rendered = render_template(source, passed_vals={'app': {'name': 'abcdef'}})
    assert 'abcdef' in str(rendered)
Example #3
0
def test_render_template_pass_dict():
    """Values will be rendered from a passed dict
    """
    from tapis_cli.templating import render_template
    source = '{{ variable1 }} static'
    env = {'variable1': 'nonstatic', 'variable2': 'unstatic'}
    rendered = render_template(source, passed_vals=env)
    assert 'nonstatic' in rendered
    assert 'unstatic' not in rendered
Example #4
0
 def _render_json_file_contents(self, passed_vals):
     """Transform the JSON file contents by rendering it as a Jinja template
     """
     payload = getattr(self, 'json_file_contents')
     txt_payload = json.dumps(payload)
     txt_payload = templating.render_template(txt_payload,
                                              passed_vals=passed_vals)
     payload = json.loads(txt_payload)
     setattr(self, 'json_file_contents', payload)
     return self.json_file_contents
Example #5
0
def test_render_template_undefined_var():
    """Empty variables are allowed in template after rendering
    """
    # Until the allow_undefined is actually implemented, empty variables will
    # not raise an error. Revisit this test when it is implemented.
    from tapis_cli.templating import render_template
    source = '{{ variable_a }} static'
    env = {'variable1': 'nonstatic', 'variable2': 'unstatic'}
    rendered = render_template(source, passed_vals=env)
    assert rendered is not None
Example #6
0
def test_render_template_passed_vals_supercede_builtin():
    """Values in a passed dict should override default/discovered values
    """
    from pbr.version import VersionInfo
    from tapis_cli import PKG_NAME
    from tapis_cli.templating import render_template

    version_info = VersionInfo(PKG_NAME)
    version_string = version_info.version_string()

    source = 'Tapis CLI version {{ tapis_cli_version }} is cool'
    env = {}
    rendered = render_template(source, passed_vals=env)
    assert version_string in rendered

    # Pass over-ride value
    env = {'tapis_cli_version': 9000}
    rendered = render_template(source, passed_vals=env)
    assert '9000' in rendered