Tests for embedding a multiline file in a template.

pull/167/head^2
Graham Welch 10 years ago
parent 2b129007d5
commit 03ce7bb50b

@ -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')

@ -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

@ -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

@ -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

@ -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-----

@ -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]}

@ -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

@ -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
Loading…
Cancel
Save