Merge "Fix "{}" is not a list error for json parameter type"

This commit is contained in:
Jenkins authored and Gerrit Code Review committed 2015-08-21 15:50:13 +00:00
commit 99f4869617
2 files changed
+22 -1

No files matched your search

+1 -1
View File
@@ -277,7 +277,7 @@ class Property(object):
def _get_map(self, value, validate=False):
if value is None:
value = self.has_default() and self.default() or {}
value = self.default() if self.has_default() else {}
if not isinstance(value, collections.Mapping):
# This is to handle passing Lists via Json parameters exposed
# via a provider resource, in particular lists-of-dicts which
+21
View File
@@ -898,6 +898,27 @@ class PropertyTest(common.HeatTestCase):
self.assertRaises(exception.StackValidationFailed,
p.get_value, ['1', '2', '3'], True)
def test_map_list_default(self):
schema = {'Type': 'Map',
'Default': ['foo', 'bar']}
p = properties.Property(schema)
p.schema.allow_conversion = True
self.assertEqual(jsonutils.dumps(['foo', 'bar']),
p.get_value(None))
def test_map_list_default_empty(self):
schema = {'Type': 'Map',
'Default': []}
p = properties.Property(schema)
p.schema.allow_conversion = True
self.assertEqual(jsonutils.dumps([]), p.get_value(None))
def test_map_list_no_default(self):
schema = {'Type': 'Map'}
p = properties.Property(schema)
p.schema.allow_conversion = True
self.assertEqual({}, p.get_value(None))
def test_map_string(self):
p = properties.Property({'Type': 'Map'})
self.assertRaises(TypeError, p.get_value, 'foo')