diff --git a/expandybird/expansion/expansion_test.py b/expandybird/expansion/expansion_test.py index d9e8432df..196f68a79 100644 --- a/expandybird/expansion/expansion_test.py +++ b/expandybird/expansion/expansion_test.py @@ -207,6 +207,25 @@ class ExpansionTest(unittest.TestCase): self.assertEquals(result_file, expanded_template) + def testJinjaMultilineFile(self): + template = ReadTestFile('jinja_multilinefile.yaml') + + imports = {} + imports['jinja_multilinefile.jinja'] = ReadImportFile( + 'jinja_multilinefile.jinja') + imports['helpers/common.jinja'] = ReadImportFile( + 'helpers/common.jinja') + imports['multiline.txt'] = ReadImportFile('multiline.txt') + + yaml_template = yaml.safe_load(template) + + expanded_template = expansion.Expand( + str(yaml_template), imports) + + result_file = ReadTestFile('jinja_multilinefile_result.yaml') + + self.assertEquals(result_file, expanded_template) + def testPythonWithImport(self): template = ReadTestFile('python_template_with_import.yaml') @@ -248,6 +267,28 @@ class ExpansionTest(unittest.TestCase): self.assertEquals(result_file, expanded_template) + def testPythonMultilineFile(self): + template = ReadTestFile('python_multilinefile.yaml') + + imports = {} + imports['python_multilinefile.py'] = ReadImportFile( + 'python_multilinefile.py') + + imports['helpers/common.py'] = ReadImportFile('helpers/common.py') + imports['helpers/extra/common2.py'] = ReadImportFile( + 'helpers/extra/common2.py') + + imports['multiline.txt'] = ReadImportFile('multiline.txt') + + yaml_template = yaml.safe_load(template) + + expanded_template = expansion.Expand( + str(yaml_template), imports) + + result_file = ReadTestFile('python_multilinefile_result.yaml') + + self.assertEquals(result_file, expanded_template) + def testPythonWithEnvironment(self): template = ReadTestFile('python_template_with_env.yaml') diff --git a/expandybird/test/templates/jinja_multilinefile.jinja b/expandybird/test/templates/jinja_multilinefile.jinja new file mode 100644 index 000000000..a4bc0ae8c --- /dev/null +++ b/expandybird/test/templates/jinja_multilinefile.jinja @@ -0,0 +1,7 @@ +{% import 'helpers/common.jinja' as common %} +resources: +- name: {{ common.GenerateMachineName("myFrontend", "prod") }} + type: compute.v1.instance + properties: + description: '{{ imports[properties["description-file"]]|replace("\n","\n\n ") }}' + machineSize: big diff --git a/expandybird/test/templates/jinja_multilinefile.yaml b/expandybird/test/templates/jinja_multilinefile.yaml new file mode 100644 index 000000000..411bed19b --- /dev/null +++ b/expandybird/test/templates/jinja_multilinefile.yaml @@ -0,0 +1,8 @@ +imports: ["jinja_multilinefile.jinja", "helpers/common.jinja", "multiline.txt"] + +resources: +- name: jinja_multilinefile_name + type: jinja_multilinefile.jinja + properties: + description-file: multiline.txt + diff --git a/expandybird/test/templates/jinja_multilinefile_result.yaml b/expandybird/test/templates/jinja_multilinefile_result.yaml new file mode 100644 index 000000000..3eb0deb45 --- /dev/null +++ b/expandybird/test/templates/jinja_multilinefile_result.yaml @@ -0,0 +1,42 @@ +config: + resources: + - name: myFrontend-prod + properties: + description: '-----BEGIN TEST CERT----- + + Lotsof65characterlineswillfollow.Onlyseveralmorecharacterstogo!! + + Lotsof65characterlineswillfollow.Onlyseveralmorecharacterstogo!! + + Lotsof65characterlineswillfollow.Onlyseveralmorecharacterstogo!! + + Lotsof65characterlineswillfollow.Onlyseveralmorecharacterstogo!! + + Lotsof65characterlineswillfollow.Onlyseveralmorecharacterstogo!! + + Lotsof65characterlineswillfollow.Onlyseveralmorecharacterstogo!! + + Lotsof65characterlineswillfollow.Onlyseveralmorecharacterstogo!! + + Lotsof65characterlineswillfollow.Onlyseveralmorecharacterstogo!! + + Lotsof65characterlineswillfollow.Onlyseveralmorecharacterstogo!! + + Lotsof65characterlineswillfollow.Onlyseveralmorecharacterstogo!! + + Thelastlineisntalways65characters.Notsurewhy... + + -----END TEST CERT----- + + ' + machineSize: big + type: compute.v1.instance +layout: + resources: + - name: jinja_multilinefile_name + properties: + description-file: multiline.txt + resources: + - name: myFrontend-prod + type: compute.v1.instance + type: jinja_multilinefile.jinja diff --git a/expandybird/test/templates/multiline.txt b/expandybird/test/templates/multiline.txt new file mode 100644 index 000000000..e55d96d21 --- /dev/null +++ b/expandybird/test/templates/multiline.txt @@ -0,0 +1,13 @@ +-----BEGIN TEST CERT----- +Lotsof65characterlineswillfollow.Onlyseveralmorecharacterstogo!! +Lotsof65characterlineswillfollow.Onlyseveralmorecharacterstogo!! +Lotsof65characterlineswillfollow.Onlyseveralmorecharacterstogo!! +Lotsof65characterlineswillfollow.Onlyseveralmorecharacterstogo!! +Lotsof65characterlineswillfollow.Onlyseveralmorecharacterstogo!! +Lotsof65characterlineswillfollow.Onlyseveralmorecharacterstogo!! +Lotsof65characterlineswillfollow.Onlyseveralmorecharacterstogo!! +Lotsof65characterlineswillfollow.Onlyseveralmorecharacterstogo!! +Lotsof65characterlineswillfollow.Onlyseveralmorecharacterstogo!! +Lotsof65characterlineswillfollow.Onlyseveralmorecharacterstogo!! +Thelastlineisntalways65characters.Notsurewhy... +-----END TEST CERT----- diff --git a/expandybird/test/templates/python_multilinefile.py b/expandybird/test/templates/python_multilinefile.py new file mode 100644 index 000000000..c43409b96 --- /dev/null +++ b/expandybird/test/templates/python_multilinefile.py @@ -0,0 +1,22 @@ +# Copyright 2014 Google Inc. All Rights Reserved. + +"""Constructs a VM.""" + +# Verify that both ways of hierarchical imports work. +from helpers import common +import helpers.extra.common2 + + +def GenerateConfig(evaluation_context): + """Generates config of a VM.""" + + resource = {} + resource['name'] = common.GenerateMachineName('myFrontend', 'prod') + resource['type'] = 'compute.v1.instance' + resource['properties'] = { + 'description': evaluation_context.imports[ + evaluation_context.properties['description-file']], + 'machineSize': helpers.extra.common2.GenerateMachineSize() + } + + return {'resources': [resource]} diff --git a/expandybird/test/templates/python_multilinefile.yaml b/expandybird/test/templates/python_multilinefile.yaml new file mode 100644 index 000000000..142892d8a --- /dev/null +++ b/expandybird/test/templates/python_multilinefile.yaml @@ -0,0 +1,8 @@ +imports: ["python_multilinefile.py", "helpers/common.py", "helpers/common2.py", "helpers/__init__.py", "multiline.txt"] + +resources: +- name: python_multilinefile_name + type: python_multilinefile.py + properties: + description-file: multiline.txt + diff --git a/expandybird/test/templates/python_multilinefile_result.yaml b/expandybird/test/templates/python_multilinefile_result.yaml new file mode 100644 index 000000000..590ac7ad6 --- /dev/null +++ b/expandybird/test/templates/python_multilinefile_result.yaml @@ -0,0 +1,42 @@ +config: + resources: + - name: myFrontend-prod + properties: + description: '-----BEGIN TEST CERT----- + + Lotsof65characterlineswillfollow.Onlyseveralmorecharacterstogo!! + + Lotsof65characterlineswillfollow.Onlyseveralmorecharacterstogo!! + + Lotsof65characterlineswillfollow.Onlyseveralmorecharacterstogo!! + + Lotsof65characterlineswillfollow.Onlyseveralmorecharacterstogo!! + + Lotsof65characterlineswillfollow.Onlyseveralmorecharacterstogo!! + + Lotsof65characterlineswillfollow.Onlyseveralmorecharacterstogo!! + + Lotsof65characterlineswillfollow.Onlyseveralmorecharacterstogo!! + + Lotsof65characterlineswillfollow.Onlyseveralmorecharacterstogo!! + + Lotsof65characterlineswillfollow.Onlyseveralmorecharacterstogo!! + + Lotsof65characterlineswillfollow.Onlyseveralmorecharacterstogo!! + + Thelastlineisntalways65characters.Notsurewhy... + + -----END TEST CERT----- + + ' + machineSize: big + type: compute.v1.instance +layout: + resources: + - name: python_multilinefile_name + properties: + description-file: multiline.txt + resources: + - name: myFrontend-prod + type: compute.v1.instance + type: python_multilinefile.py