From df84de486010f18b378ee5d625d08721a4f9cc05 Mon Sep 17 00:00:00 2001 From: Miguel Caballer Date: Fri, 22 Apr 2016 09:20:18 +0200 Subject: [PATCH] Bugfix to show correct error message show in case of unknown field in a datatype Change-Id: I3207b0ba7bf02154381e472dd2ee0496efdb5f20 Related-Bug: 1573139 --- toscaparser/dataentity.py | 5 ++++- toscaparser/tests/test_datatypes.py | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/toscaparser/dataentity.py b/toscaparser/dataentity.py index ebca9292..3a9b9fa1 100644 --- a/toscaparser/dataentity.py +++ b/toscaparser/dataentity.py @@ -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, diff --git a/toscaparser/tests/test_datatypes.py b/toscaparser/tests/test_datatypes.py index 58fb2fed..62e4362d 100644 --- a/toscaparser/tests/test_datatypes.py +++ b/toscaparser/tests/test_datatypes.py @@ -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__())