|
|
|
@ -1,7 +1,8 @@
|
|
|
|
|
import os
|
|
|
|
|
import pytest
|
|
|
|
|
from calculate.templates.template_engine import TemplateEngine, Variables,\
|
|
|
|
|
ConditionFailed, DIR, FILE
|
|
|
|
|
ConditionFailed, DIR, FILE,\
|
|
|
|
|
TemplateSyntaxError
|
|
|
|
|
from calculate.templates.template_processor import TemplateExecutor
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -25,6 +26,14 @@ class TestTemplateEngine():
|
|
|
|
|
output_parameters.path == '/etc/path' and
|
|
|
|
|
output_parameters.force)
|
|
|
|
|
|
|
|
|
|
def test_if_an_input_template_contains_more_than_one_calculate_tag__the_template_engine_raises_the_TemplateSyntaxError_exception(self):
|
|
|
|
|
input_template = '''{% calculate name = 'filename' %}
|
|
|
|
|
{% calculate path = '/etc/path'%}
|
|
|
|
|
{% calculate force %}'''
|
|
|
|
|
template_engine = TemplateEngine(appends_set=APPENDS_SET)
|
|
|
|
|
with pytest.raises(TemplateSyntaxError):
|
|
|
|
|
template_engine.process_template_from_string(input_template, DIR)
|
|
|
|
|
|
|
|
|
|
def test_if_an_input_template_binded_with_datavars_module__variables_available_in_a_template(self):
|
|
|
|
|
input_template = '''{% calculate name = vars.var_1, path = vars.var_2, autoupdate %}'''
|
|
|
|
|
datavars_module = Variables({'vars':
|
|
|
|
@ -71,10 +80,8 @@ class TestTemplateEngine():
|
|
|
|
|
pytest.fail('Unexpected ConditionFailed exception.')
|
|
|
|
|
|
|
|
|
|
def test_if_an_input_template_contains_several_conditions_and_it_is_False__the_template_engine_raises_ConditionFailed_exception(self):
|
|
|
|
|
input_template = '''{% calculate name = vars.var_1 %}
|
|
|
|
|
{% calculate env = 'other_vars'%}
|
|
|
|
|
{% calculate var_4 < var_5 %}
|
|
|
|
|
{% calculate path = var_3, var_6 == 'value' %}'''
|
|
|
|
|
input_template = '''{% calculate name = vars.var_1, env = 'other_vars',
|
|
|
|
|
var_4 < var_5, path = var_3, var_6 == 'value' %}'''
|
|
|
|
|
|
|
|
|
|
datavars_module = Variables({'vars':
|
|
|
|
|
Variables({'var_1': 'filename',
|
|
|
|
@ -90,10 +97,9 @@ class TestTemplateEngine():
|
|
|
|
|
template_engine.process_template_from_string(input_template, DIR)
|
|
|
|
|
|
|
|
|
|
def test_if_an_input_template_contains_several_calculate_tags__the_template_engine_will_parse_them_all_and_will_contain_all_parameters_and_result_of_all_conditions(self):
|
|
|
|
|
input_template = '''{% calculate name = vars.var_1 %}
|
|
|
|
|
{% calculate env = 'other_vars, vars' %}
|
|
|
|
|
{% calculate var_4 > var_5 %}
|
|
|
|
|
{% calculate path = var_3, var_6 == 'value' %}'''
|
|
|
|
|
input_template = '''{% calculate name = vars.var_1,
|
|
|
|
|
env = 'other_vars, vars', var_4 > var_5,
|
|
|
|
|
path = var_3, var_6 == 'value' %}'''
|
|
|
|
|
datavars_module = Variables({'vars':
|
|
|
|
|
Variables({'var_1': 'filename',
|
|
|
|
|
'var_2': '/etc/path'}),
|
|
|
|
@ -111,9 +117,9 @@ class TestTemplateEngine():
|
|
|
|
|
output_parameters.env == {'other_vars', 'vars'})
|
|
|
|
|
|
|
|
|
|
def test_if_an_input_template_contains_variables_in_its_text__the_rendered_text_will_contain_values_of_this_variables(self):
|
|
|
|
|
input_template = '''{% calculate name = 'filename', force -%}
|
|
|
|
|
input_template = '''{% calculate name = 'filename', force,
|
|
|
|
|
env = 'vars_1' -%}
|
|
|
|
|
parameter_1 = {{ vars_2.var_3 }}
|
|
|
|
|
{% calculate env = 'vars_1' -%}
|
|
|
|
|
parameter_2 = {{ vars_2.var_4 }}
|
|
|
|
|
parameter_3 = {{ var_1 }}'''
|
|
|
|
|
output_text = '''parameter_1 = value_1
|
|
|
|
@ -193,8 +199,7 @@ class TestTemplateEngine():
|
|
|
|
|
|
|
|
|
|
def test_if_an_input_template_calculate_tag_contains_pkg_function_with_an_existing_package_in_its_argument__the_pkg_function_returns_version_value_of_the_package_from_package_parameter_without_any_exceptions(self):
|
|
|
|
|
input_template = '''{% calculate name = 'filename',
|
|
|
|
|
package='test-category/test-package', force -%}
|
|
|
|
|
{% calculate pkg() < 2.7 -%}'''
|
|
|
|
|
package='test-category/test-package', force, pkg() < 2.7 -%}'''
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
template_engine = TemplateEngine(appends_set=APPENDS_SET,
|
|
|
|
|