Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id A047F200D10 for ; Sat, 26 Aug 2017 00:10:52 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 9EB1F16D127; Fri, 25 Aug 2017 22:10:52 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id ECCAF16D124 for ; Sat, 26 Aug 2017 00:10:50 +0200 (CEST) Received: (qmail 2713 invoked by uid 500); 25 Aug 2017 22:10:50 -0000 Mailing-List: contact commits-help@ariatosca.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ariatosca.incubator.apache.org Delivered-To: mailing list commits@ariatosca.incubator.apache.org Received: (qmail 2704 invoked by uid 99); 25 Aug 2017 22:10:50 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 25 Aug 2017 22:10:50 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id 8C4FFC07E5 for ; Fri, 25 Aug 2017 22:10:49 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -4.222 X-Spam-Level: X-Spam-Status: No, score=-4.222 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-0.001, SPF_PASS=-0.001] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id a4TbYton1Atq for ; Fri, 25 Aug 2017 22:10:45 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with SMTP id 937C25F5B3 for ; Fri, 25 Aug 2017 22:10:43 +0000 (UTC) Received: (qmail 2617 invoked by uid 99); 25 Aug 2017 22:10:42 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 25 Aug 2017 22:10:42 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id B423DF32AD; Fri, 25 Aug 2017 22:10:42 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: emblemparade@apache.org To: commits@ariatosca.incubator.apache.org Message-Id: <51985ea93c0f407c9e350640775105c0@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: incubator-ariatosca git commit: More tests. Date: Fri, 25 Aug 2017 22:10:42 +0000 (UTC) archived-at: Fri, 25 Aug 2017 22:10:52 -0000 Repository: incubator-ariatosca Updated Branches: refs/heads/ARIA-1-parser-test-suite f7c4829b6 -> f96d5e426 More tests. * Make 'type' required in interface type Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/f96d5e42 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/f96d5e42 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/f96d5e42 Branch: refs/heads/ARIA-1-parser-test-suite Commit: f96d5e426bbe3952e1146c5226d7336f85b62214 Parents: f7c4829 Author: Tal Liron Authored: Fri Aug 25 17:10:15 2017 -0500 Committer: Tal Liron Committed: Fri Aug 25 17:10:15 2017 -0500 ---------------------------------------------------------------------- .../simple_v1_0/definitions.py | 2 +- .../simple_v1_0/modeling/parameters.py | 8 +- .../simple_v1_0/presentation/types.py | 2 +- .../simple_v1_0/conftest.py | 2 + .../aria_extension_tosca/simple_v1_0/data.py | 1 + .../simple_v1_0/templates/__init__.py | 14 + .../simple_v1_0/templates/test_templates.py | 129 ++++++++ .../simple_v1_0/test_imports.py | 10 +- .../simple_v1_0/test_templates.py | 129 -------- .../simple_v1_0/test_types.py | 153 --------- .../simple_v1_0/types/__init__.py | 14 + .../simple_v1_0/types/test_node_type.py | 68 ++++ .../types/test_node_type_capabilities.py | 72 +++++ .../types/test_node_type_interfaces.py | 72 +++++ .../types/test_node_type_requirements.py | 69 ++++ .../simple_v1_0/types/test_type_parameters.py | 318 +++++++++++++++++++ .../simple_v1_0/types/test_types.py | 152 +++++++++ 17 files changed, 925 insertions(+), 290 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/f96d5e42/extensions/aria_extension_tosca/simple_v1_0/definitions.py ---------------------------------------------------------------------- diff --git a/extensions/aria_extension_tosca/simple_v1_0/definitions.py b/extensions/aria_extension_tosca/simple_v1_0/definitions.py index 9158776..da08a07 100644 --- a/extensions/aria_extension_tosca/simple_v1_0/definitions.py +++ b/extensions/aria_extension_tosca/simple_v1_0/definitions.py @@ -283,7 +283,7 @@ class InterfaceDefinition(ExtensiblePresentation): @field_validator(type_validator('interface type', convert_name_to_full_type_name, 'interface_types')) - @primitive_field(str) + @primitive_field(str, required=True) def type(self): """ ARIA NOTE: This field is not mentioned in the spec, but is implied. http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/f96d5e42/extensions/aria_extension_tosca/simple_v1_0/modeling/parameters.py ---------------------------------------------------------------------- diff --git a/extensions/aria_extension_tosca/simple_v1_0/modeling/parameters.py b/extensions/aria_extension_tosca/simple_v1_0/modeling/parameters.py index f271b4d..5ba8d07 100644 --- a/extensions/aria_extension_tosca/simple_v1_0/modeling/parameters.py +++ b/extensions/aria_extension_tosca/simple_v1_0/modeling/parameters.py @@ -141,8 +141,8 @@ def validate_required_values(context, presentation, values, definitions): for name, definition in definitions.iteritems(): if getattr(definition, 'required', False) \ and ((values is None) or (values.get(name) is None)): - context.validation.report('required property "%s" is not assigned a value in "%s"' - % (name, presentation._fullname), + context.validation.report('required property "{0}" is not assigned a value in "{1}"' + .format(name, presentation._fullname), locator=presentation._get_child_locator('properties'), level=Issue.BETWEEN_TYPES) @@ -155,8 +155,8 @@ def merge_raw_parameter_definition(context, presentation, raw_property_definitio type2 = our_property_definition.type if type1 != type2: context.validation.report( - 'override changes type from "%s" to "%s" for property "%s" in "%s"' - % (type1, type2, property_name, presentation._fullname), + 'override changes type from "{0}" to "{1}" for property "{2}" in "{3}"' + .format(type1, type2, property_name, presentation._fullname), locator=presentation._get_child_locator(field_name, property_name), level=Issue.BETWEEN_TYPES) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/f96d5e42/extensions/aria_extension_tosca/simple_v1_0/presentation/types.py ---------------------------------------------------------------------- diff --git a/extensions/aria_extension_tosca/simple_v1_0/presentation/types.py b/extensions/aria_extension_tosca/simple_v1_0/presentation/types.py index 920ebed..bf00c0d 100644 --- a/extensions/aria_extension_tosca/simple_v1_0/presentation/types.py +++ b/extensions/aria_extension_tosca/simple_v1_0/presentation/types.py @@ -36,7 +36,7 @@ def convert_name_to_full_type_name(context, name, types_dict): # pylint: disable def get_type_by_name(context, name, *types_dict_names): """ - Gets a type either by its full name or its shorthand name or typequalified name. + Gets a type either by its full name or its shorthand name or type-qualified name. Works by checking for ``shorthand_name`` in the types' ``_extensions`` field. See also :class:`~aria_extension_tosca.v1_0.presentation.extensible.ExtensiblePresentation`. http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/f96d5e42/tests/extensions/aria_extension_tosca/simple_v1_0/conftest.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/conftest.py b/tests/extensions/aria_extension_tosca/simple_v1_0/conftest.py index 399e8c8..bd89b19 100644 --- a/tests/extensions/aria_extension_tosca/simple_v1_0/conftest.py +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/conftest.py @@ -15,6 +15,8 @@ """ PyTest configuration module. + +Add support for a "--tosca-parser" CLI option. """ import pytest http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/f96d5e42/tests/extensions/aria_extension_tosca/simple_v1_0/data.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/data.py b/tests/extensions/aria_extension_tosca/simple_v1_0/data.py index b24fb29..1edb5e3 100644 --- a/tests/extensions/aria_extension_tosca/simple_v1_0/data.py +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/data.py @@ -38,3 +38,4 @@ TEMPLATE_NAME_SECTION = { } GOOD_VERSIONS = ("'6.1'", '2.0.1', '3.1.0.beta', "'1.0.0.alpha-10'") BAD_VERSIONS = ('a_string', '1.2.3.4.5', '1.2.beta', '1.0.0.alpha-x') +STATUSES = ('supported', 'unsupported', 'experimental', 'deprecated') http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/f96d5e42/tests/extensions/aria_extension_tosca/simple_v1_0/templates/__init__.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/templates/__init__.py b/tests/extensions/aria_extension_tosca/simple_v1_0/templates/__init__.py new file mode 100644 index 0000000..ae1e83e --- /dev/null +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/templates/__init__.py @@ -0,0 +1,14 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/f96d5e42/tests/extensions/aria_extension_tosca/simple_v1_0/templates/test_templates.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/templates/test_templates.py b/tests/extensions/aria_extension_tosca/simple_v1_0/templates/test_templates.py new file mode 100644 index 0000000..98f06ca --- /dev/null +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/templates/test_templates.py @@ -0,0 +1,129 @@ +# -*- coding: utf-8 -*- +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import itertools + +import pytest + +from .. import data + + +# Syntax + +@pytest.mark.parametrize('value', data.NOT_A_DICT) +def test_topology_template_wrong_yaml_type(parser, value): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +topology_template: {{ value }} +""", dict(value=value)).assert_failure() + + +def test_topology_template_emtpy(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +topology_template: {} +""").assert_success() + + +@pytest.mark.parametrize('name,value', itertools.product( + data.TEMPLATE_NAMES, + data.NOT_A_DICT +)) +def test_template_section_wrong_yaml_type(parser, name, value): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +topology_template: + {{ section }}: {{ value }} +""", dict(section=data.TEMPLATE_NAME_SECTION[name], value=value)).assert_failure() + + +@pytest.mark.parametrize('name,value', itertools.product( + data.TEMPLATE_NAMES, + data.NOT_A_STRING +)) +def test_template_type_wrong_yaml_type(parser, name, value): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +topology_template: + {{ section }}: + my_template: + type: {{ value }} +""", dict(section=data.TEMPLATE_NAME_SECTION[name], value=value)).assert_failure() + + +# Common fields + +@pytest.mark.parametrize('name', data.TEMPLATE_NAMES) +def test_template_fields(parser, name): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +topology_template: + {{ section }}: + my_template: + type: tosca.{{ plural }}.Root + description: a description +""", dict(section=data.TEMPLATE_NAME_SECTION[name], + plural=data.TYPE_NAME_PLURAL[name])).assert_success() + + +# Of types + +@pytest.mark.parametrize('name', data.TEMPLATE_NAMES) +def test_template_of_type(parser, name): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +{{ name }}_types: + MyType: {} +topology_template: + {{ section }}: + my_template: + type: MyType +""", dict(name=name, section=data.TEMPLATE_NAME_SECTION[name])).assert_success() + + +@pytest.mark.parametrize('name', data.TEMPLATE_NAMES) +def test_template_of_type_unicode(parser, name): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +{{ name }}_types: + 類型: {} +topology_template: + {{ section }}: + 模板: + type: 類型 +""", dict(name=name, section=data.TEMPLATE_NAME_SECTION[name])).assert_success() + + +@pytest.mark.parametrize('name', data.TEMPLATE_NAMES) +def test_template_of_unknown_type(parser, name): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +topology_template: + {{ section }}: + my_template: + type: UnknownType +""", dict(section=data.TEMPLATE_NAME_SECTION[name])).assert_failure() + + +@pytest.mark.parametrize('name', data.TEMPLATE_NAMES) +def test_template_of_null_type(parser, name): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +topology_template: + {{ section }}: + my_template: + type: null +""", dict(section=data.TEMPLATE_NAME_SECTION[name])).assert_failure() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/f96d5e42/tests/extensions/aria_extension_tosca/simple_v1_0/test_imports.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/test_imports.py b/tests/extensions/aria_extension_tosca/simple_v1_0/test_imports.py index 765cd8b..4d8af8b 100644 --- a/tests/extensions/aria_extension_tosca/simple_v1_0/test_imports.py +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/test_imports.py @@ -28,6 +28,12 @@ node_types: derived_from: tosca.nodes.Root """ +NODE_TYPE_IMPORT_UNICODE = """ +node_types: + 類型: + derived_from: tosca.nodes.Root +""" + BAD_IMPORT = """ node_types: MyNode: @@ -39,7 +45,7 @@ def repository(): repository = WebServer() repository.add_text_yaml('/imports/node-type.yaml', NODE_TYPE_IMPORT) repository.add_text_yaml('/imports/{0}.yaml'.format(WebServer.escape('節點類型')), - NODE_TYPE_IMPORT) + NODE_TYPE_IMPORT_UNICODE) repository.add_text_yaml('/imports/bad.yaml', BAD_IMPORT) with repository: yield repository.root @@ -84,7 +90,7 @@ imports: topology_template: node_templates: my_node: - type: MyNode + type: 類型 """, dict(repository=repository)).assert_success() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/f96d5e42/tests/extensions/aria_extension_tosca/simple_v1_0/test_templates.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/test_templates.py b/tests/extensions/aria_extension_tosca/simple_v1_0/test_templates.py deleted file mode 100644 index 8b0fd0e..0000000 --- a/tests/extensions/aria_extension_tosca/simple_v1_0/test_templates.py +++ /dev/null @@ -1,129 +0,0 @@ -# -*- coding: utf-8 -*- -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import itertools - -import pytest - -from . import data - - -# Syntax - -@pytest.mark.parametrize('value', data.NOT_A_DICT) -def test_topology_template_wrong_yaml_type(parser, value): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -topology_template: {{ value }} -""", dict(value=value)).assert_failure() - - -def test_topology_template_emtpy(parser): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -topology_template: {} -""").assert_success() - - -@pytest.mark.parametrize('name,value', itertools.product( - data.TEMPLATE_NAMES, - data.NOT_A_DICT -)) -def test_template_section_wrong_yaml_type(parser, name, value): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -topology_template: - {{ section }}: {{ value }} -""", dict(section=data.TEMPLATE_NAME_SECTION[name], value=value)).assert_failure() - - -@pytest.mark.parametrize('name,value', itertools.product( - data.TEMPLATE_NAMES, - data.NOT_A_STRING -)) -def test_template_type_wrong_yaml_type(parser, name, value): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -topology_template: - {{ section }}: - my_template: - type: {{ value }} -""", dict(section=data.TEMPLATE_NAME_SECTION[name], value=value)).assert_failure() - - -# Common fields - -@pytest.mark.parametrize('name', data.TEMPLATE_NAMES) -def test_template_fields(parser, name): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -topology_template: - {{ section }}: - my_template: - type: tosca.{{ plural }}.Root - description: a description -""", dict(section=data.TEMPLATE_NAME_SECTION[name], - plural=data.TYPE_NAME_PLURAL[name])).assert_success() - - -# Of types - -@pytest.mark.parametrize('name', data.TEMPLATE_NAMES) -def test_template_of_type(parser, name): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -{{ name }}_types: - MyType: {} -topology_template: - {{ section }}: - my_template: - type: MyType -""", dict(name=name, section=data.TEMPLATE_NAME_SECTION[name])).assert_success() - - -@pytest.mark.parametrize('name', data.TEMPLATE_NAMES) -def test_template_of_type_unicode(parser, name): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -{{ name }}_types: - 類型: {} -topology_template: - {{ section }}: - 模板: - type: 類型 -""", dict(name=name, section=data.TEMPLATE_NAME_SECTION[name])).assert_success() - - -@pytest.mark.parametrize('name', data.TEMPLATE_NAMES) -def test_template_of_unknown_type(parser, name): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -topology_template: - {{ section }}: - my_template: - type: UnknownType -""", dict(section=data.TEMPLATE_NAME_SECTION[name])).assert_failure() - - -@pytest.mark.parametrize('name', data.TEMPLATE_NAMES) -def test_template_of_null_type(parser, name): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -topology_template: - {{ section }}: - my_template: - type: null -""", dict(section=data.TEMPLATE_NAME_SECTION[name])).assert_failure() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/f96d5e42/tests/extensions/aria_extension_tosca/simple_v1_0/test_types.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/test_types.py b/tests/extensions/aria_extension_tosca/simple_v1_0/test_types.py deleted file mode 100644 index 0699e1e..0000000 --- a/tests/extensions/aria_extension_tosca/simple_v1_0/test_types.py +++ /dev/null @@ -1,153 +0,0 @@ -# -*- coding: utf-8 -*- -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import itertools - -import pytest - -from . import data - - -# Syntax - -@pytest.mark.parametrize('name,value', itertools.product( - data.TYPE_NAMES, - data.NOT_A_DICT -)) -def test_type_wrong_yaml_type(parser, name, value): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -{{ name }}_types: - MyType: {{ value }} -""", dict(name=name, value=value)).assert_failure() - - -@pytest.mark.parametrize('name', data.TYPE_NAMES) -def test_type_empty(parser, name): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -{{ name }}_types: - MyType: {} -""", dict(name=name)).assert_success() - - -@pytest.mark.parametrize('name,value', itertools.product( - data.TYPE_NAMES, - data.NOT_A_STRING -)) -def test_type_derived_from_wrong_yaml_type(parser, name, value): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -{{ name }}_types: - MyType: - derived_from: {{ value }} -""", dict(name=name, value=value)).assert_failure() - - - -# Derivation - -@pytest.mark.parametrize('name', data.TYPE_NAMES) -def test_type_derived_from_unknown(parser, name): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -{{ name }}_types: - MyType: - derived_from: UnknownType -""", dict(name=name)).assert_failure() - - -@pytest.mark.parametrize('name', data.TYPE_NAMES) -def test_type_derived_from_null(parser, name): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -{{ name }}_types: - MyType: - derived_from: null -""", dict(name=name)).assert_failure() - - -@pytest.mark.parametrize('name', data.TYPE_NAMES) -def test_type_derived_from_self(parser, name): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -{{ name }}_types: - MyType: - derived_from: MyType -""", dict(name=name)).assert_failure() - - -@pytest.mark.parametrize('name', data.TYPE_NAMES) -def test_type_derived_from_circular(parser, name): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -{{ name }}_types: - MyType1: - derived_from: MyType3 - MyType2: - derived_from: MyType1 - MyType3: - derived_from: MyType2 -""", dict(name=name)).assert_failure() - - -@pytest.mark.parametrize('name', data.TYPE_NAMES) -def test_type_derived_from_root(parser, name): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -{{ name }}_types: - MyType: - derived_from: tosca.{{ plural }}.Root -""", dict(name=name, plural=data.TYPE_NAME_PLURAL[name])).assert_success() - - -# Common fields - -@pytest.mark.parametrize('name', data.TYPE_NAMES) -def test_type_fields(parser, name): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -{{ name }}_types: - MyType: - derived_from: tosca.{{ plural }}.Root - version: 1.0.0 - description: a description -""", dict(name=name, plural=data.TYPE_NAME_PLURAL[name])).assert_success() - - -@pytest.mark.parametrize('name', data.TYPE_NAMES) -def test_type_fields_unicode(parser, name): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -{{ name }}_types: - 類型: - derived_from: tosca.{{ plural }}.Root - version: 1.0.0.詠嘆調-10 - description: 描述 -""", dict(name=name, plural=data.TYPE_NAME_PLURAL[name])).assert_success() - - -@pytest.mark.parametrize('name,value', itertools.product( - data.TYPE_NAMES, - data.BAD_VERSIONS -)) -def test_type_bad_version(parser, name, value): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -{{ name }}_types: - MyType: - version: {{ value }} -""", dict(name=name, value=value)).assert_failure() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/f96d5e42/tests/extensions/aria_extension_tosca/simple_v1_0/types/__init__.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/types/__init__.py b/tests/extensions/aria_extension_tosca/simple_v1_0/types/__init__.py new file mode 100644 index 0000000..ae1e83e --- /dev/null +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/types/__init__.py @@ -0,0 +1,14 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/f96d5e42/tests/extensions/aria_extension_tosca/simple_v1_0/types/test_node_type.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/types/test_node_type.py b/tests/extensions/aria_extension_tosca/simple_v1_0/types/test_node_type.py new file mode 100644 index 0000000..b2767c1 --- /dev/null +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/types/test_node_type.py @@ -0,0 +1,68 @@ +# -*- coding: utf-8 -*- +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import itertools + +import pytest + +from .. import data + + +DICT_FIELD_NAMES = ('properties', 'attributes', 'capabilities', 'interfaces', 'artifacts') + + +# Syntax + +@pytest.mark.parametrize('name,value', itertools.product( + DICT_FIELD_NAMES, + data.NOT_A_DICT +)) +def test_node_type_fields_wrong_yaml_type(parser, name, value): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +node_types: + MyType: + {{ name }}: {{ value }} +""", dict(name=name, value=value)).assert_failure() + + +@pytest.mark.parametrize('value', data.NOT_A_LIST) +def test_node_type_requirements_wrong_yaml_type(parser, value): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +node_types: + MyType: + requirements: {{ value }} +""", dict(value=value)).assert_failure() + + +@pytest.mark.parametrize('name', DICT_FIELD_NAMES) +def test_node_type_fields_empty(parser, name): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +node_types: + MyType: + {{ name }}: {} +""", dict(name=name)).assert_success() + + +def test_node_type_requirements_empty(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +node_types: + MyType: + requirements: [] +""").assert_success() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/f96d5e42/tests/extensions/aria_extension_tosca/simple_v1_0/types/test_node_type_capabilities.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/types/test_node_type_capabilities.py b/tests/extensions/aria_extension_tosca/simple_v1_0/types/test_node_type_capabilities.py new file mode 100644 index 0000000..fa9af73 --- /dev/null +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/types/test_node_type_capabilities.py @@ -0,0 +1,72 @@ +# -*- coding: utf-8 -*- +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import pytest + + +# Overriding + +@pytest.mark.skip(reason='fixed in ARIA-351') +def test_node_type_capability_override_change_type_good(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +capability_types: + MyType1: + properties: + prop1: + type: string + MyType2: + derived_from: MyType1 + properties: + prop2: + type: integer +node_types: + MyType1: + capabilities: + my_capability: + type: MyType1 + MyType2: + derived_from: MyType1 + capabilities: + my_capability: + type: MyType2 +""").assert_success() + + +def test_node_type_capability_override_change_type_bad(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +capability_types: + MyType1: + properties: + prop1: + type: string + MyType2: + derived_from: MyType1 + properties: + prop2: + type: integer +node_types: + MyType1: + capabilities: + my_capability: + type: MyType2 + MyType2: + derived_from: MyType1 + capabilities: + my_capability: + type: MyType1 +""").assert_failure() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/f96d5e42/tests/extensions/aria_extension_tosca/simple_v1_0/types/test_node_type_interfaces.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/types/test_node_type_interfaces.py b/tests/extensions/aria_extension_tosca/simple_v1_0/types/test_node_type_interfaces.py new file mode 100644 index 0000000..0228c02 --- /dev/null +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/types/test_node_type_interfaces.py @@ -0,0 +1,72 @@ +# -*- coding: utf-8 -*- +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import pytest + + +# Overriding + +@pytest.mark.skip(reason='fixed in ARIA-351') +def test_node_type_interface_override_change_type_good(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +interface_types: + MyType1: + inputs: + input1: + type: string + MyType2: + derived_from: MyType1 + inputs: + input2: + type: integer +node_types: + MyType1: + interfaces: + my_interface: + type: MyType1 + MyType2: + derived_from: MyType1 + interfaces: + my_interface: + type: MyType2 +""").assert_success() + + +def test_node_type_interface_override_change_type_bad(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +interface_types: + MyType1: + inputs: + input1: + type: string + MyType2: + derived_from: MyType1 + inputs: + input2: + type: integer +node_types: + MyType1: + interfaces: + my_interface: + type: MyType2 + MyType2: + derived_from: MyType1 + interfaces: + my_interface: + type: MyType1 +""").assert_failure() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/f96d5e42/tests/extensions/aria_extension_tosca/simple_v1_0/types/test_node_type_requirements.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/types/test_node_type_requirements.py b/tests/extensions/aria_extension_tosca/simple_v1_0/types/test_node_type_requirements.py new file mode 100644 index 0000000..b823cd4 --- /dev/null +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/types/test_node_type_requirements.py @@ -0,0 +1,69 @@ +# -*- coding: utf-8 -*- +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +# Overriding + +def test_node_type_requirement_override_change_type_good1(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +capability_types: + MyType1: + properties: + prop1: + type: string + MyType2: + derived_from: MyType1 + properties: + prop2: + type: integer +node_types: + MyType1: + requirements: + - my_requirement: + capability: MyType1 + MyType2: + derived_from: MyType1 + requirements: + - my_requirement: + capability: MyType2 +""").assert_success() + + +def test_node_type_requirement_override_change_type_good2(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +capability_types: + MyType1: + properties: + prop1: + type: string + MyType2: + derived_from: MyType1 + properties: + prop2: + type: integer +node_types: + MyType1: + requirements: + - my_requirement: + capability: MyType2 + MyType2: + derived_from: MyType1 + requirements: + - my_requirement: + capability: MyType1 # you should be allowed to change the capability type to anything +""").assert_success() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/f96d5e42/tests/extensions/aria_extension_tosca/simple_v1_0/types/test_type_parameters.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/types/test_type_parameters.py b/tests/extensions/aria_extension_tosca/simple_v1_0/types/test_type_parameters.py new file mode 100644 index 0000000..be5ad43 --- /dev/null +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/types/test_type_parameters.py @@ -0,0 +1,318 @@ +# -*- coding: utf-8 -*- +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import itertools + +import pytest + +from .. import data + + +SECTIONS = ( + ('artifact', 'properties'), + ('data', 'properties'), + ('capability', 'properties'), + ('capability', 'attributes'), + ('relationship', 'properties'), + ('relationship', 'attributes'), + ('node', 'properties'), + ('node', 'attributes'), + ('group', 'properties'), + ('policy', 'properties') +) +SECTION_NAMES = ('properties', 'attributes') +ENTRY_SCHEMA_VALUES = ( + ('string', 'a string', 'another string'), + ('integer', '1', '2'), + ('float', '1.1', '2.2') +) +ENTRY_SCHEMA_VALUES_BAD = ( + ('string', 'a string', '1'), + ('integer', '1', 'a string'), + ('float', '1.1', 'a string') +) + + +# Fields + +@pytest.mark.parametrize('name,parameter_section', SECTIONS) +def test_node_type_parameter_fields(parser, name, parameter_section): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +{{ name }}_types: + MyType: + {{ parameter_section }}: + my_param: + type: string + description: a description + default: a value + status: supported +""", dict(name=name, parameter_section=parameter_section)).assert_success() + + +# Status + +@pytest.mark.parametrize( + 'name,parameter_section,value', + ((s[0], s[1], v) + for s, v in itertools.product(SECTIONS, data.STATUSES)) +) +def test_node_type_parameter_status_good(parser, name, parameter_section, value): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +{{ name }}_types: + MyType: + {{ parameter_section }}: + my_param: + type: string + status: {{ value }} +""", dict(name=name, parameter_section=parameter_section, value=value)).assert_success() + + +@pytest.mark.parametrize('name,parameter_section', SECTIONS) +def test_node_type_parameter_status_bad(parser, name, parameter_section): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +{{ name }}_types: + MyType: + {{ parameter_section }}: + my_param: + type: string + status: bad +""", dict(name=name, parameter_section=parameter_section)).assert_failure() + + +# Entry schema + +@pytest.mark.parametrize('section,values', itertools.product( + SECTION_NAMES, + ENTRY_SCHEMA_VALUES +)) +def test_node_type_parameter_map(parser, section, values): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +node_types: + MyType: + {{ section }}: + my_param: + type: map + entry_schema: {{ values[0] }} +topology_template: + node_templates: + my_template: + type: MyType + {{ section }}: + my_param: + key1: {{ values[1] }} + key2: {{ values[2] }} +""", dict(section=section, values=values)).assert_success() + + +@pytest.mark.parametrize('section,values', itertools.product( + SECTION_NAMES, + ENTRY_SCHEMA_VALUES_BAD +)) +def test_node_type_parameter_map_bad(parser, section, values): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +node_types: + MyType: + {{ section }}: + my_param: + type: map + entry_schema: {{ values[0] }} +topology_template: + node_templates: + my_template: + type: MyType + {{ section }}: + my_param: + key1: {{ values[1] }} + key2: {{ values[2] }} +""", dict(section=section, values=values)).assert_failure() + + +@pytest.mark.parametrize('section,values', itertools.product( + SECTION_NAMES, + ENTRY_SCHEMA_VALUES +)) +def test_node_type_parameter_list(parser, section, values): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +node_types: + MyType: + {{ section }}: + my_param: + type: list + entry_schema: {{ values[0] }} +topology_template: + node_templates: + my_template: + type: MyType + {{ section }}: + my_param: + - {{ values[1] }} + - {{ values[2] }} +""", dict(section=section, values=values)).assert_success() + + +@pytest.mark.parametrize('section,values', itertools.product( + SECTION_NAMES, + ENTRY_SCHEMA_VALUES_BAD +)) +def test_node_type_parameter_list_bad(parser, section, values): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +node_types: + MyType: + {{ section }}: + my_param: + type: list + entry_schema: {{ values[0] }} +topology_template: + node_templates: + my_template: + type: MyType + {{ section }}: + my_param: + - {{ values[1] }} + - {{ values[2] }} +""", dict(section=section, values=values)).assert_failure() + + +# Required + +@pytest.mark.skip(reason='fixed in ARIA-351') +def test_node_type_property_required(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +node_types: + MyType: + properties: + my_property: + type: string +topology_template: + node_templates: + my_template: + type: MyType +""").assert_failure() + + +def test_node_type_property_not_required(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +node_types: + MyType: + properties: + my_property: + type: string + required: false +topology_template: + node_templates: + my_template: + type: MyType +""").assert_success() + + +def test_node_type_property_required_with_default(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +node_types: + MyType: + properties: + my_property: + type: string + default: a string +topology_template: + node_templates: + my_template: + type: MyType +""").assert_success() + + +# Overriding + +@pytest.mark.parametrize('section', SECTION_NAMES) +def test_node_type_parameter_override_add_default(parser, section): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +node_types: + MyType1: + {{ section }}: + my_param: + type: string + MyType2: + derived_from: MyType1 + {{ section }}: + my_param: + type: string + default: my value +""", dict(section=section)).assert_success() + + +@pytest.mark.skip(reason='fixed in ARIA-351') +@pytest.mark.parametrize('section', ('properties', 'attributes')) +def test_node_type_parameter_override_change_type_good(parser, section): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +data_types: + MyType1: + properties: + field1: + type: string + MyType2: + derived_from: MyType1 + properties: + field2: + type: integer +node_types: + MyType1: + {{ section }}: + my_param: + type: MyType1 + MyType2: + derived_from: MyType1 + {{ section }}: + my_param: + type: MyType2 +""", dict(section=section)).assert_success() + + +@pytest.mark.parametrize('section', ('properties', 'attributes')) +def test_node_type_parameter_override_change_type_bad(parser, section): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +data_types: + MyType1: + properties: + field1: + type: string + MyType2: + derived_from: MyType1 + properties: + field2: + type: integer +node_types: + MyType1: + {{ section }}: + my_param: + type: MyType2 + MyType2: + derived_from: MyType1 + {{ section }}: + my_param: + type: MyType1 +""", dict(section=section)).assert_failure() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/f96d5e42/tests/extensions/aria_extension_tosca/simple_v1_0/types/test_types.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/types/test_types.py b/tests/extensions/aria_extension_tosca/simple_v1_0/types/test_types.py new file mode 100644 index 0000000..8e2f26f --- /dev/null +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/types/test_types.py @@ -0,0 +1,152 @@ +# -*- coding: utf-8 -*- +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import itertools + +import pytest + +from .. import data + + +# Syntax + +@pytest.mark.parametrize('name,value', itertools.product( + data.TYPE_NAMES, + data.NOT_A_DICT +)) +def test_type_wrong_yaml_type(parser, name, value): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +{{ name }}_types: + MyType: {{ value }} +""", dict(name=name, value=value)).assert_failure() + + +@pytest.mark.parametrize('name', data.TYPE_NAMES) +def test_type_empty(parser, name): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +{{ name }}_types: + MyType: {} +""", dict(name=name)).assert_success() + + +@pytest.mark.parametrize('name,value', itertools.product( + data.TYPE_NAMES, + data.NOT_A_STRING +)) +def test_type_derived_from_wrong_yaml_type(parser, name, value): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +{{ name }}_types: + MyType: + derived_from: {{ value }} +""", dict(name=name, value=value)).assert_failure() + + +# Derivation + +@pytest.mark.parametrize('name', data.TYPE_NAMES) +def test_type_derived_from_unknown(parser, name): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +{{ name }}_types: + MyType: + derived_from: UnknownType +""", dict(name=name)).assert_failure() + + +@pytest.mark.parametrize('name', data.TYPE_NAMES) +def test_type_derived_from_null(parser, name): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +{{ name }}_types: + MyType: + derived_from: null +""", dict(name=name)).assert_failure() + + +@pytest.mark.parametrize('name', data.TYPE_NAMES) +def test_type_derived_from_self(parser, name): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +{{ name }}_types: + MyType: + derived_from: MyType +""", dict(name=name)).assert_failure() + + +@pytest.mark.parametrize('name', data.TYPE_NAMES) +def test_type_derived_from_circular(parser, name): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +{{ name }}_types: + MyType1: + derived_from: MyType3 + MyType2: + derived_from: MyType1 + MyType3: + derived_from: MyType2 +""", dict(name=name)).assert_failure() + + +@pytest.mark.parametrize('name', data.TYPE_NAMES) +def test_type_derived_from_root(parser, name): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +{{ name }}_types: + MyType: + derived_from: tosca.{{ plural }}.Root +""", dict(name=name, plural=data.TYPE_NAME_PLURAL[name])).assert_success() + + +# Common fields + +@pytest.mark.parametrize('name', data.TYPE_NAMES) +def test_type_fields(parser, name): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +{{ name }}_types: + MyType: + derived_from: tosca.{{ plural }}.Root + version: 1.0.0 + description: a description +""", dict(name=name, plural=data.TYPE_NAME_PLURAL[name])).assert_success() + + +@pytest.mark.parametrize('name', data.TYPE_NAMES) +def test_type_fields_unicode(parser, name): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +{{ name }}_types: + 類型: + derived_from: tosca.{{ plural }}.Root + version: 1.0.0.詠嘆調-10 + description: 描述 +""", dict(name=name, plural=data.TYPE_NAME_PLURAL[name])).assert_success() + + +@pytest.mark.parametrize('name,value', itertools.product( + data.TYPE_NAMES, + data.BAD_VERSIONS +)) +def test_type_bad_version(parser, name, value): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +{{ name }}_types: + MyType: + version: {{ value }} +""", dict(name=name, value=value)).assert_failure()