Make sure that property defaults are converted correctly
If a developer defines a default boolean as "true", then we really want True when we do "self.properties['bla']" not 'true', otherwise this is not consistent. Change-Id: I3705e573e2fd68a04b26c5589d38f84d68641738 Partial-bug: #1375151
This commit is contained in:
@@ -397,7 +397,7 @@ class Properties(collections.Mapping):
|
||||
raise ValueError('%s%s %s' % (self.error_prefix, key,
|
||||
six.text_type(e)))
|
||||
elif prop.has_default():
|
||||
return prop.default()
|
||||
return prop.get_value(None, validate)
|
||||
elif prop.required():
|
||||
raise ValueError(_('%(prefix)sProperty %(key)s not assigned') %
|
||||
{'prefix': self.error_prefix, 'key': key})
|
||||
|
||||
@@ -181,6 +181,8 @@ class CeilometerAlarmTest(HeatTestCase):
|
||||
al2 = dict((k, mox.IgnoreArg())
|
||||
for k, s in schema.items() if s.update_allowed)
|
||||
al2['alarm_id'] = mox.IgnoreArg()
|
||||
del al2['enabled']
|
||||
del al2['repeat_actions']
|
||||
self.fa.alarms.update(**al2).AndReturn(None)
|
||||
|
||||
self.m.ReplayAll()
|
||||
|
||||
@@ -922,6 +922,7 @@ class PropertiesTest(testtools.TestCase):
|
||||
'missing': {'Type': 'Integer'},
|
||||
'defaulted': {'Type': 'Integer', 'Default': 1},
|
||||
'default_override': {'Type': 'Integer', 'Default': 1},
|
||||
'default_bool': {'Type': 'Boolean', 'Default': 'false'},
|
||||
}
|
||||
data = {
|
||||
'int': 21,
|
||||
@@ -938,6 +939,9 @@ class PropertiesTest(testtools.TestCase):
|
||||
def test_string_good(self):
|
||||
self.assertEqual('foofoo', self.props['string'])
|
||||
|
||||
def test_bool_not_str(self):
|
||||
self.assertEqual(False, self.props['default_bool'])
|
||||
|
||||
def test_missing_required(self):
|
||||
self.assertRaises(ValueError, self.props.get, 'required_int')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user