Merge "Using a number in str_replace causes an exception"

This commit is contained in:
Jenkins 2013-11-12 13:33:52 +00:00 committed by Gerrit Code Review
commit 2ddcf04480
2 changed files with 13 additions and 1 deletions

View File

@ -248,7 +248,7 @@ class HOTemplate(template.Template):
_('"params" parameter must be a dictionary')) _('"params" parameter must be a dictionary'))
for key in params.iterkeys(): for key in params.iterkeys():
value = params.get(key, '') or "" value = params.get(key, '') or ""
text = text.replace(key, value) text = text.replace(key, str(value))
return text return text
match_str_replace = lambda k, v: k in ['str_replace', 'Fn::Replace'] match_str_replace = lambda k, v: k in ['str_replace', 'Fn::Replace']

View File

@ -177,6 +177,18 @@ class HOTemplateTest(HeatTestCase):
self.assertEqual(snippet_resolved, self.assertEqual(snippet_resolved,
tmpl.resolve_replace(snippet)) tmpl.resolve_replace(snippet))
def test_str_replace_number(self):
"""Test str_replace function with numbers."""
snippet = {'str_replace': {'template': 'Template number string bar',
'params': {'number': 1}}}
snippet_resolved = 'Template 1 string bar'
tmpl = parser.Template(hot_tpl_empty)
self.assertEqual(snippet_resolved,
tmpl.resolve_replace(snippet))
def test_str_fn_replace(self): def test_str_fn_replace(self):
"""Test Fn:Replace function.""" """Test Fn:Replace function."""