Bugfix to show correct error message show in case of unknown field in a datatype
Change-Id: I3207b0ba7bf02154381e472dd2ee0496efdb5f20 Related-Bug: 1573139
This commit is contained in:
parent
75f6b98457
commit
df84de4860
@ -91,7 +91,10 @@ class DataEntity(object):
|
||||
|
||||
# check every field
|
||||
for name, value in list(self.value.items()):
|
||||
prop_schema = Schema(name, self._find_schema(name))
|
||||
schema_name = self._find_schema(name)
|
||||
if not schema_name:
|
||||
continue
|
||||
prop_schema = Schema(name, schema_name)
|
||||
# check if field value meets type defined
|
||||
DataEntity.validate_datatype(prop_schema.type, value,
|
||||
prop_schema.entry_schema,
|
||||
|
@ -477,3 +477,30 @@ class DataTypeTest(TestCase):
|
||||
data = DataEntity('tosca.my.datatypes.TestLab', value,
|
||||
DataTypeTest.custom_type_def)
|
||||
self.assertIsNotNone(data.validate())
|
||||
|
||||
def test_incorrect_field_in_datatype(self):
|
||||
tpl_snippet = '''
|
||||
tosca_definitions_version: tosca_simple_yaml_1_0
|
||||
topology_template:
|
||||
node_templates:
|
||||
server:
|
||||
type: tosca.nodes.Compute
|
||||
|
||||
webserver:
|
||||
type: tosca.nodes.WebServer
|
||||
properties:
|
||||
admin_credential:
|
||||
user: username
|
||||
token: some_pass
|
||||
some_field: value
|
||||
requirements:
|
||||
- host: server
|
||||
'''
|
||||
tpl = yamlparser.simple_parse(tpl_snippet)
|
||||
err = self.assertRaises(exception.ValidationError, ToscaTemplate,
|
||||
None, None, None, tpl)
|
||||
self.assertIn(_('The pre-parsed input failed validation with the '
|
||||
'following error(s): \n\n\tUnknownFieldError: Data '
|
||||
'value of type "tosca.datatypes.Credential" contains'
|
||||
' unknown field "some_field". Refer to the definition'
|
||||
' to verify valid values'), err.__str__())
|
||||
|
Loading…
x
Reference in New Issue
Block a user