Fix validation of function 'list_concat'
Now the function 'list_concat' allows string type args, like {'list_concat': 'I am string'} or {'list_concat': ['v1', 'v2']}, this patch fixes the validation to avoid string type args. Change-Id: If6d73a90e25f38a37c0503fe0b1aaa93a6fbc380 Closes-Bug: #1685434
This commit is contained in:
parent
e8e0a2483a
commit
de6a8c1be0
|
@ -1490,14 +1490,16 @@ class ListConcat(function.Function):
|
|||
def result(self):
|
||||
args = function.resolve(self.args)
|
||||
|
||||
if not isinstance(args, collections.Sequence):
|
||||
if (isinstance(args, six.string_types) or
|
||||
not isinstance(args, collections.Sequence)):
|
||||
raise TypeError(_('Incorrect arguments to "%(fn_name)s" '
|
||||
'should be: %(example)s') % self.fmt_data)
|
||||
|
||||
def ensure_list(m):
|
||||
if m is None:
|
||||
return []
|
||||
elif isinstance(m, collections.Sequence):
|
||||
elif (isinstance(m, collections.Sequence) and
|
||||
not isinstance(m, six.string_types)):
|
||||
return m
|
||||
else:
|
||||
msg = _('Incorrect arguments: Items to concat must be lists.')
|
||||
|
|
|
@ -2125,11 +2125,23 @@ conditions:
|
|||
resolved = self.resolve(snippet, tmpl)
|
||||
self.assertEqual(snippet_resolved, resolved)
|
||||
|
||||
def test_list_concat_invalid(self):
|
||||
snippet = {'list_concat': [{'k1': 'v2'}, ['v3', 'v4']]}
|
||||
def _test_list_concat_invalid(self, snippet):
|
||||
tmpl = template.Template(hot_pike_tpl_empty)
|
||||
msg = 'Incorrect arguments'
|
||||
exc = self.assertRaises(TypeError, self.resolve, snippet, tmpl)
|
||||
self.assertIn('Incorrect arguments', six.text_type(exc))
|
||||
self.assertIn(msg, six.text_type(exc))
|
||||
|
||||
def test_list_concat_with_dict_arg(self):
|
||||
snippet = {'list_concat': [{'k1': 'v2'}, ['v3', 'v4']]}
|
||||
self._test_list_concat_invalid(snippet)
|
||||
|
||||
def test_list_concat_with_string_arg(self):
|
||||
snippet = {'list_concat': 'I am string'}
|
||||
self._test_list_concat_invalid(snippet)
|
||||
|
||||
def test_list_concat_with_string_item(self):
|
||||
snippet = {'list_concat': ['v1', 'v2']}
|
||||
self._test_list_concat_invalid(snippet)
|
||||
|
||||
|
||||
class HotStackTest(common.HeatTestCase):
|
||||
|
|
Loading…
Reference in New Issue