|
|
|
@ -6,7 +6,9 @@ from calculate.templates.template_engine import TemplateEngine, Variables,\
|
|
|
|
|
from calculate.templates.template_processor import TemplateExecutor
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CHROOT_PATH = os.path.join(os.getcwd(), 'tests/templates/testfiles/test_template_engine_root')
|
|
|
|
|
CHROOT_PATH = os.path.join(
|
|
|
|
|
os.getcwd(),
|
|
|
|
|
'tests/templates/testfiles/test_template_engine_root')
|
|
|
|
|
|
|
|
|
|
APPENDS_SET = TemplateExecutor(cl_config_path=os.path.join(
|
|
|
|
|
CHROOT_PATH,
|
|
|
|
@ -263,7 +265,23 @@ parameter_2 = {{ vars_1.var_1 }}'''
|
|
|
|
|
text = template_engine.template_text
|
|
|
|
|
assert text == output_text
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('case',
|
|
|
|
|
def test_constant_value_in_the_begin_of_condition(self):
|
|
|
|
|
datavars_module = Variables({'vars_1':
|
|
|
|
|
Variables({'var_1':
|
|
|
|
|
['a', 4.2, 'b', 'c']})})
|
|
|
|
|
input_template = '''{% calculate name = 'filename',
|
|
|
|
|
'a' in vars_1.var_1, 4.2 in vars_1.var_1 -%}
|
|
|
|
|
Template completed'''
|
|
|
|
|
output_text = 'Template completed'
|
|
|
|
|
template_engine = TemplateEngine(appends_set=APPENDS_SET,
|
|
|
|
|
datavars_module=datavars_module,
|
|
|
|
|
chroot_path=CHROOT_PATH)
|
|
|
|
|
template_engine.process_template_from_string(input_template, FILE)
|
|
|
|
|
text = template_engine.template_text
|
|
|
|
|
assert text == output_text
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
|
'case',
|
|
|
|
|
[
|
|
|
|
|
{
|
|
|
|
|
"name": "pattern not found",
|
|
|
|
@ -300,8 +318,8 @@ parameter_2 = {{ vars_1.var_1 }}'''
|
|
|
|
|
"grep": "'/test_grep', '^STATUSLINE=true'",
|
|
|
|
|
"result": ""
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
ids=lambda x:x["name"])
|
|
|
|
|
],
|
|
|
|
|
ids=lambda x: x["name"])
|
|
|
|
|
def test_grep(self, case):
|
|
|
|
|
datavars_module = Variables({'vars_1':
|
|
|
|
|
Variables({'var_1':
|
|
|
|
@ -318,7 +336,8 @@ parameter_2 = {{ vars_1.var_1 }}'''
|
|
|
|
|
text = template_engine.template_text
|
|
|
|
|
assert text == output_text
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('case',
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
|
'case',
|
|
|
|
|
[
|
|
|
|
|
{
|
|
|
|
|
"name": "exists directory",
|
|
|
|
@ -345,8 +364,8 @@ parameter_2 = {{ vars_1.var_1 }}'''
|
|
|
|
|
"exists": "/test_exists_qwerty",
|
|
|
|
|
"result": ""
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
ids=lambda x:x["name"])
|
|
|
|
|
],
|
|
|
|
|
ids=lambda x: x["name"])
|
|
|
|
|
def test_exists(self, case):
|
|
|
|
|
datavars_module = Variables({'vars_1':
|
|
|
|
|
Variables({'var_1':
|
|
|
|
|