Always convert string type params to string
Schema.to_schema_type() should convert values passed to it to the appropriate type. So if the user passed a version number of 9.4 and they defined it in the template with a string type, we should get the string '9.4' back, instead of the error "The value '9.4' is invalid for type 'string'". Co-Authored-By: Richard Lee <rblee88@gmail.com> Closes-Bug: #1353701 Change-Id: If7abd129dc7819c6ac01f9bf7dfdbe397ec09c65
This commit is contained in:
parent
58e141b2ac
commit
af21176f1a
@ -173,8 +173,6 @@ class Schema(collections.Mapping):
|
||||
elif self.type == self.NUMBER:
|
||||
return Schema.str_to_num(value)
|
||||
elif self.type == self.STRING:
|
||||
if value and not isinstance(value, basestring):
|
||||
raise ValueError()
|
||||
return str(value)
|
||||
elif self.type == self.BOOLEAN:
|
||||
return strutils.bool_from_string(str(value), strict=True)
|
||||
|
@ -390,9 +390,12 @@ class SchemaTest(testtools.TestCase):
|
||||
self.assertIsInstance(res, basestring)
|
||||
res = schema.to_schema_type('1')
|
||||
self.assertIsInstance(res, basestring)
|
||||
err = self.assertRaises(ValueError, schema.to_schema_type, 1)
|
||||
self.assertEqual('Value "1" is invalid for data type "String".',
|
||||
six.text_type(err))
|
||||
res = schema.to_schema_type(1)
|
||||
self.assertIsInstance(res, basestring)
|
||||
res = schema.to_schema_type(True)
|
||||
self.assertIsInstance(res, basestring)
|
||||
res = schema.to_schema_type(None)
|
||||
self.assertIsInstance(res, basestring)
|
||||
|
||||
def test_to_schema_type_boolean(self):
|
||||
'''Test Schema.to_schema_type method for type Boolean.'''
|
||||
|
Loading…
Reference in New Issue
Block a user