deb-heat/heat/tests/test_template.py
Zane Bitter 5709e08f33 Make template formats pluggable
Change-Id: I546c34db0803306feaa9bfd326a7aef837db0edb
2014-03-06 10:07:42 -05:00

95 lines
3.1 KiB
Python

# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from heat.tests.common import HeatTestCase
from heat.common import exception
from heat.engine import plugin_manager
from heat.engine import template
from heat.engine.cfn.template import CfnTemplate
class TestTemplatePluginManager(HeatTestCase):
def test_pkg_name(self):
cfn_tmpl_pkg = template.TemplatePluginManager.package_name(CfnTemplate)
self.assertEqual('heat.engine.cfn', cfn_tmpl_pkg)
def test_get(self):
tpm = template.TemplatePluginManager()
self.assertFalse(tpm.plugin_managers)
class Test(object):
plugins = tpm
test_pm = Test().plugins
self.assertTrue(isinstance(test_pm, plugin_manager.PluginManager))
self.assertEqual(tpm.plugin_managers['heat.tests'], test_pm)
class TestTemplateVersion(HeatTestCase):
versions = (('heat_template_version', '2013-05-23'),
('HeatTemplateFormatVersion', '2012-12-12'),
('AWSTemplateFormatVersion', '2010-09-09'))
def test_hot_version(self):
tmpl = {
'heat_template_version': '2013-05-23',
'foo': 'bar',
'parameters': {}
}
self.assertEqual(('heat_template_version', '2013-05-23'),
template.get_version(tmpl, self.versions))
def test_cfn_version(self):
tmpl = {
'AWSTemplateFormatVersion': '2010-09-09',
'foo': 'bar',
'Parameters': {}
}
self.assertEqual(('AWSTemplateFormatVersion', '2010-09-09'),
template.get_version(tmpl, self.versions))
def test_heat_cfn_version(self):
tmpl = {
'HeatTemplateFormatVersion': '2012-12-12',
'foo': 'bar',
'Parameters': {}
}
self.assertEqual(('HeatTemplateFormatVersion', '2012-12-12'),
template.get_version(tmpl, self.versions))
def test_missing_version(self):
tmpl = {
'foo': 'bar',
'Parameters': {}
}
self.assertEqual(('HeatTemplateFormatVersion', '2012-12-12'),
template.get_version(tmpl, self.versions))
def test_ambiguous_version(self):
tmpl = {
'AWSTemplateFormatVersion': '2010-09-09',
'HeatTemplateFormatVersion': '2012-12-12',
'foo': 'bar',
'Parameters': {}
}
self.assertRaises(exception.InvalidTemplateVersion,
template.get_version, tmpl, self.versions)