diff --git a/toscaparser/elements/tosca_type_validation.py b/toscaparser/elements/tosca_type_validation.py index 82b0b46f..5f1409b3 100644 --- a/toscaparser/elements/tosca_type_validation.py +++ b/toscaparser/elements/tosca_type_validation.py @@ -48,12 +48,12 @@ class TypeValidation(object): for name in custom_type: if name not in self.ALLOWED_TYPE_SECTIONS: ExceptionCollector.appendException( - UnknownFieldError(what='Template ' + (self.import_def), + UnknownFieldError(what='Template ' + str(self.import_def), field=name)) def _validate_type_version(self, version): if version not in self.VALID_TEMPLATE_VERSIONS: ExceptionCollector.appendException( InvalidTemplateVersion( - what=version + ' in ' + self.import_def, + what=version + ' in ' + str(self.import_def), valid_versions=', '. join(self.VALID_TEMPLATE_VERSIONS))) diff --git a/toscaparser/tests/data/custom_types/invalid_template_version.yaml b/toscaparser/tests/data/custom_types/invalid_template_version.yaml new file mode 100644 index 00000000..f5fb7f14 --- /dev/null +++ b/toscaparser/tests/data/custom_types/invalid_template_version.yaml @@ -0,0 +1,7 @@ +tosca_definitions_version: tosca_simple_yaml_XXX + +node_types: + + tosca.nodes.SomeNode: + derived_from: tosca.nodes.SoftwareComponent + diff --git a/toscaparser/tests/data/test_import_invalid_template_version.yaml b/toscaparser/tests/data/test_import_invalid_template_version.yaml new file mode 100644 index 00000000..2ea4647d --- /dev/null +++ b/toscaparser/tests/data/test_import_invalid_template_version.yaml @@ -0,0 +1,13 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +imports: + - invalid: custom_types/invalid_template_version.yaml + +description: > + Test to import a template with an invalid template version. + +topology_template: + node_templates: + test: + type: tosca.nodes.SomeNode + diff --git a/toscaparser/tests/test_toscatplvalidation.py b/toscaparser/tests/test_toscatplvalidation.py index 2048a83b..28919daa 100644 --- a/toscaparser/tests/test_toscatplvalidation.py +++ b/toscaparser/tests/test_toscatplvalidation.py @@ -1441,6 +1441,18 @@ heat-translator/master/translator/tests/data/custom_types/wordpress.yaml (_('The template version "tosca_xyz" is invalid. Valid versions ' 'are "%s".') % valid_versions)) + def test_import_invalid_template_version(self): + tosca_tpl = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/test_import_invalid_template_version.yaml") + self.assertRaises(exception.ValidationError, ToscaTemplate, tosca_tpl) + valid_versions = ', '.join(ToscaTemplate.VALID_TEMPLATE_VERSIONS) + exception.ExceptionCollector.assertExceptionMessage( + exception.InvalidTemplateVersion, + (_('The template version "tosca_simple_yaml_XXX in ' + '{\'invalid\': \'custom_types/invalid_template_version.yaml\'}"' + ' is invalid. Valid versions are "%s".') % valid_versions)) + def test_node_template_capabilities_properties(self): # validating capability property values tpl_snippet = '''