py34: heat.tests.test_template

test_template

* sort list of versions in ascending order before returning it
  to maintain consistency
* encode to utf-8 before hashing in test cases

test_template_format

* cast float to int explicitly
* convert offending character to bytes because pyyaml expects
  bytes in it's ReaderError exception

partial blueprint heat-python34-support

Change-Id: Ic2f84e9db1f3f7229f40e4afbc62948d9e7be6ff
This commit is contained in:
Sirushti Murugesan 2015-08-01 16:43:43 +05:30
parent 360464c20a
commit 7bac405db4
4 changed files with 16 additions and 11 deletions

View File

@ -74,7 +74,8 @@ def get_template_class(template_data):
try: try:
return _template_classes[version] return _template_classes[version]
except KeyError: except KeyError:
av_list = [v for k, v in available_versions if k == version_type] av_list = sorted(
[v for k, v in available_versions if k == version_type])
msg_data = {'version': ': '.join(version), msg_data = {'version': ': '.join(version),
'version_type': version_type, 'version_type': version_type,
'available': ', '.join(v for v in av_list)} 'available': ', '.join(v for v in av_list)}

View File

@ -289,9 +289,9 @@ class TestTemplateValidate(common.HeatTestCase):
tmpl = template.Template(t) tmpl = template.Template(t)
self.assertIsNone(tmpl.t_digest) self.assertIsNone(tmpl.t_digest)
tmpl.validate() tmpl.validate()
self.assertEqual(hashlib.sha256(six.text_type(t)).hexdigest(), self.assertEqual(
tmpl.t_digest, hashlib.sha256(six.text_type(t).encode('utf-8')).hexdigest(),
'invalid template digest') tmpl.t_digest, 'invalid template digest')
def test_template_validate_cfn_good(self): def test_template_validate_cfn_good(self):
t = { t = {
@ -375,9 +375,9 @@ class TestTemplateValidate(common.HeatTestCase):
tmpl = template.Template(t) tmpl = template.Template(t)
self.assertIsNone(tmpl.t_digest) self.assertIsNone(tmpl.t_digest)
tmpl.validate() tmpl.validate()
self.assertEqual(hashlib.sha256(six.text_type(t)).hexdigest(), self.assertEqual(hashlib.sha256(
tmpl.t_digest, six.text_type(t).encode('utf-8')).hexdigest(),
'invalid template digest') tmpl.t_digest, 'invalid template digest')
def test_template_validate_hot_good(self): def test_template_validate_hot_good(self):
t = { t = {
@ -450,8 +450,8 @@ class TemplateTest(common.HeatTestCase):
}''') }''')
init_ex = self.assertRaises(exception.InvalidTemplateVersion, init_ex = self.assertRaises(exception.InvalidTemplateVersion,
template.Template, invalid_hot_version_tmp) template.Template, invalid_hot_version_tmp)
valid_versions = ['2015-10-15', '2013-05-23', '2014-10-16', valid_versions = ['2013-05-23', '2014-10-16',
'2015-04-30'] '2015-04-30', '2015-10-15']
ex_error_msg = ('The template version is invalid: ' ex_error_msg = ('The template version is invalid: '
'"heat_template_version: 2012-12-12". ' '"heat_template_version: 2012-12-12". '
'"heat_template_version" should be one of: %s' '"heat_template_version" should be one of: %s'

View File

@ -99,7 +99,8 @@ class YamlMinimalTest(common.HeatTestCase):
def test_long_yaml(self): def test_long_yaml(self):
template = {'HeatTemplateFormatVersion': '2012-12-12'} template = {'HeatTemplateFormatVersion': '2012-12-12'}
config.cfg.CONF.set_override('max_template_size', 1024) config.cfg.CONF.set_override('max_template_size', 1024)
template['Resources'] = ['a'] * (config.cfg.CONF.max_template_size / 3) template['Resources'] = ['a'] * int(
config.cfg.CONF.max_template_size / 3)
limit = config.cfg.CONF.max_template_size limit = config.cfg.CONF.max_template_size
long_yaml = yaml.safe_dump(template) long_yaml = yaml.safe_dump(template)
self.assertTrue(len(long_yaml) > limit) self.assertTrue(len(long_yaml) > limit)
@ -151,7 +152,8 @@ class YamlParseExceptions(common.HeatTestCase):
('scanner', dict(raised_exception=yaml.scanner.ScannerError())), ('scanner', dict(raised_exception=yaml.scanner.ScannerError())),
('parser', dict(raised_exception=yaml.parser.ParserError())), ('parser', dict(raised_exception=yaml.parser.ParserError())),
('reader', ('reader',
dict(raised_exception=yaml.reader.ReaderError('', 42, 'x', '', ''))), dict(raised_exception=yaml.reader.ReaderError(
'', 42, six.b('x'), '', ''))),
] ]
def test_parse_to_value_exception(self): def test_parse_to_value_exception(self):

View File

@ -140,6 +140,8 @@ heat.tests.test_support
heat.tests.test_swift heat.tests.test_swift
heat.tests.test_swiftsignal heat.tests.test_swiftsignal
heat.tests.test_sync_point heat.tests.test_sync_point
heat.tests.test_template
heat.tests.test_template_format
heat.tests.test_timeutils heat.tests.test_timeutils
heat.tests.test_trove_cluster heat.tests.test_trove_cluster
heat.tests.test_urlfetch heat.tests.test_urlfetch