http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1efb1e5e/tests/extensions/aria_extension_tosca/simple_v1_0/functions/test_function_get_input.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/functions/test_function_get_input.py b/tests/extensions/aria_extension_tosca/simple_v1_0/functions/test_function_get_input.py new file mode 100644 index 0000000..a4c97a4 --- /dev/null +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/functions/test_function_get_input.py @@ -0,0 +1,94 @@ +# -*- 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. + + +def test_functions_get_input_unknown(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +node_types: + MyType: + properties: + my_parameter: + type: string +topology_template: + node_templates: + my_node: + type: MyType + properties: + my_parameter: { get_input: unknown } +""").assert_failure() + + +def test_functions_get_input(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +node_types: + MyType: + properties: + my_parameter: + type: string +topology_template: + inputs: + my_input: + type: string + node_templates: + my_node: + type: MyType + properties: + my_parameter: { get_input: my_input } +""").assert_success() + + +def test_functions_get_input_nested(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +node_types: + MyType: + properties: + my_parameter: + type: string +topology_template: + inputs: + my_input: + type: string + node_templates: + my_node: + type: MyType + properties: + my_parameter: { get_input: { concat: [ my, _, input ] } } +""").assert_success() + + +# Unicode + +def test_functions_get_input_unicode(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +node_types: + é¡å: + properties: + åæ¸: + type: string +topology_template: + inputs: + è¾å ¥: + type: string + node_templates: + 模æ¿: + type: é¡å + properties: + åæ¸: { get_input: è¾å ¥ } +""").assert_success()
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1efb1e5e/tests/extensions/aria_extension_tosca/simple_v1_0/functions/test_function_get_nodes_of_type.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/functions/test_function_get_nodes_of_type.py b/tests/extensions/aria_extension_tosca/simple_v1_0/functions/test_function_get_nodes_of_type.py new file mode 100644 index 0000000..ffa2f9c --- /dev/null +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/functions/test_function_get_nodes_of_type.py @@ -0,0 +1,70 @@ +# -*- 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. + + +def test_functions_get_nodes_of_type_unknown(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +node_types: + MyType: + properties: + my_parameter: + type: string +topology_template: + node_templates: + my_node: + type: MyType + properties: + my_parameter: { get_nodes_of_type: unknown } +""", import_profile=True).assert_failure() + + +def test_functions_get_nodes_of_type(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +node_types: + MyType: + properties: + my_parameter: + type: list + entry_schema: string +topology_template: + node_templates: + my_node: + type: MyType + properties: + my_parameter: { get_nodes_of_type: MyType } +""", import_profile=True).assert_success() + + +# Unicode + +def test_functions_get_nodes_of_type_unicode(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +node_types: + é¡å: + properties: + åæ¸: + type: list + entry_schema: string +topology_template: + node_templates: + 模æ¿: + type: é¡å + properties: + åæ¸: { get_nodes_of_type: é¡å } +""", import_profile=True).assert_success() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1efb1e5e/tests/extensions/aria_extension_tosca/simple_v1_0/functions/test_function_get_operation_output.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/functions/test_function_get_operation_output.py b/tests/extensions/aria_extension_tosca/simple_v1_0/functions/test_function_get_operation_output.py new file mode 100644 index 0000000..c115d0d --- /dev/null +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/functions/test_function_get_operation_output.py @@ -0,0 +1,84 @@ +# -*- 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. + + +# Syntax + +def test_functions_get_operation_output_syntax_empty(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +node_types: + MyType: + properties: + my_parameter: + type: string +topology_template: + node_templates: + my_node: + type: MyType + properties: + my_parameter: { get_operation_output: [] } # needs at least two args +""").assert_failure() + + +# Arguments + +def test_functions_get_operation_output(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +interface_types: + MyType: + my_operation: {} +node_types: + MyType: + properties: + my_parameter: + type: string + interfaces: + MyInterface: + type: MyType +topology_template: + node_templates: + my_node: + type: MyType + properties: + my_parameter: { get_operation_output: [ my_node, MyInterface, my_operation, my_variable ] } +""").assert_success() + + +# Unicode + +def test_functions_get_operation_output_unicode(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +interface_types: + é¡å: + æè¡: {} +node_types: + é¡å: + properties: + åæ¸: + type: string + interfaces: + æ¥å£: + type: é¡å +topology_template: + node_templates: + 模æ¿: + type: é¡å + properties: + åæ¸: { get_operation_output: [ 模æ¿, æ¥å£, æè¡, è®é ] } +""").assert_success() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1efb1e5e/tests/extensions/aria_extension_tosca/simple_v1_0/functions/test_function_token.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/functions/test_function_token.py b/tests/extensions/aria_extension_tosca/simple_v1_0/functions/test_function_token.py new file mode 100644 index 0000000..8f99824 --- /dev/null +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/functions/test_function_token.py @@ -0,0 +1,119 @@ +# -*- 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. + + +def test_functions_token_syntax_empty(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +node_types: + MyType: + properties: + my_parameter: + type: string +topology_template: + node_templates: + my_node: + type: MyType + properties: + my_parameter: { token: [] } # needs exactly three args +""").assert_failure() + + +def test_functions_token_syntax_index_type(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +node_types: + MyType: + properties: + my_parameter: + type: string +topology_template: + node_templates: + my_node: + type: MyType + properties: + my_parameter: { token: [ hello world, ' ', c ] } +""").assert_failure() + + +def test_functions_token_syntax_index_negative(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +node_types: + MyType: + properties: + my_parameter: + type: string +topology_template: + node_templates: + my_node: + type: MyType + properties: + my_parameter: { token: [ hello world, ' ', -1 ] } +""").assert_failure() + + +def test_functions_token(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +node_types: + MyType: + properties: + my_parameter: + type: string +topology_template: + node_templates: + my_node: + type: MyType + properties: + my_parameter: { token: [ hello world, ' ', 1 ] } +""").assert_success() + + +def test_functions_token_nested(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +node_types: + MyType: + properties: + my_parameter: + type: string +topology_template: + node_templates: + my_node: + type: MyType + properties: + my_parameter: { token: [ { token: [ hello/goodbye world, ' ', 0 ] }, '/', 1 ] } +""").assert_success() + + +# Unicode + +def test_functions_token_unicode(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +node_types: + é¡å: + properties: + åæ¸: + type: string +topology_template: + node_templates: + 模æ¿: + type: é¡å + properties: + åæ¸: { token: [ 'ä½ å¥½ï¼ä¸ç', 'ï¼', 1 ] } +""").assert_success() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1efb1e5e/tests/extensions/aria_extension_tosca/simple_v1_0/functions/test_functions_modelable_entity.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/functions/test_functions_modelable_entity.py b/tests/extensions/aria_extension_tosca/simple_v1_0/functions/test_functions_modelable_entity.py new file mode 100644 index 0000000..365971a --- /dev/null +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/functions/test_functions_modelable_entity.py @@ -0,0 +1,247 @@ +# -*- 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 + + +# TODO: +# other keywords (HOST, SOURCE, TARGET) +# requirements +# capabilities + + +PERMUTATIONS = ( + ('get_property', 'properties'), + ('get_attribute', 'attributes') +) + + +# Syntax + +@pytest.mark.parametrize('function,section', PERMUTATIONS) +def test_functions_modelable_entity_syntax_empty(parser, function, section): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +node_types: + MyType: + {{ section }}: + my_parameter: + type: string +topology_template: + node_templates: + my_node: + type: MyType + {{ section }}: + my_parameter: { {{ function }}: [] } # needs at least two args +""", dict(function=function, section=section)).assert_failure() + + +@pytest.mark.parametrize('function,section', PERMUTATIONS) +def test_functions_modelable_entity_syntax_single(parser, function, section): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +node_types: + MyType: + {{ section }}: + my_parameter: + type: string +topology_template: + node_templates: + my_node: + type: MyType + {{ section }}: + my_parameter: { {{ function }}: [ SELF ] } # needs at least two args +""", dict(function=function, section=section)).assert_failure() + + +# Entities + +@pytest.mark.parametrize('function,section', PERMUTATIONS) +def test_functions_modelable_entity_same(parser, function, section): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +node_types: + MyType: + {{ section }}: + my_parameter1: + type: string + my_parameter2: + type: string + default: a value +topology_template: + node_templates: + my_node: + type: MyType + {{ section }}: + my_parameter1: { {{ function }}: [ my_node, my_parameter2 ] } +""", dict(function=function, section=section)).assert_success() + + +@pytest.mark.parametrize('function,section', PERMUTATIONS) +def test_functions_modelable_entity_other(parser, function, section): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +node_types: + MyType: + {{ section }}: + my_parameter1: + type: string + my_parameter2: + type: string + default: a value +topology_template: + node_templates: + my_node1: + type: MyType + {{ section }}: + my_parameter1: { {{ function }}: [ my_node2, my_parameter2 ] } + my_node2: + type: MyType + {{ section }}: + my_parameter1: a value +""", dict(function=function, section=section)).assert_success() + + +@pytest.mark.parametrize('function,section', PERMUTATIONS) +def test_functions_modelable_entity_unknown(parser, function, section): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +node_types: + MyType: + properties: + my_parameter: + type: string +topology_template: + node_templates: + my_node: + type: MyType + {{ section }}: + my_parameter: { get_property: [ unknown, my_parameter ] } +""", dict(function=function, section=section)).assert_failure() + + +# Cyclical + +@pytest.mark.parametrize('function,section', PERMUTATIONS) +def test_functions_modelable_entity_cyclical_simple(parser, function, section): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +node_types: + MyType: + {{ section }}: + my_parameter: + type: string +topology_template: + node_templates: + my_node: + type: MyType + {{ section }}: + my_parameter: { {{ function }}: [ my_node, my_parameter ] } +""", dict(function=function, section=section)).assert_failure() + + +@pytest.mark.parametrize('function,section', PERMUTATIONS) +def test_functions_modelable_entity_cyclical_complex(parser, function, section): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +node_types: + MyType: + {{ section }}: + my_parameter1: + type: string + my_parameter2: + type: string +topology_template: + node_templates: + my_node: + type: MyType + {{ section }}: + my_parameter1: { {{ function }}: [ my_node, my_parameter2 ] } + my_parameter2: { {{ function }}: [ my_node, my_parameter1 ] } +""", dict(function=function, section=section)).assert_failure() + + +@pytest.mark.parametrize('function,section', PERMUTATIONS) +def test_functions_modelable_entity_sub(parser, function, section): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +data_types: + MyType: + properties: + my_field: + type: string +node_types: + MyType: + {{ section }}: + my_parameter1: + type: string + my_parameter2: + type: MyType + default: + my_field: a value +topology_template: + node_templates: + my_node: + type: MyType + {{ section }}: + my_parameter1: { {{ function }}: [ my_node, my_parameter2, my_field ] } +""", dict(function=function, section=section)).assert_success() + + +# Keywords + +@pytest.mark.parametrize('function,section', PERMUTATIONS) +def test_functions_modelable_entity_self(parser, function, section): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +node_types: + MyType: + {{ section }}: + my_parameter1: + type: string + my_parameter2: + type: string + default: a value +topology_template: + node_templates: + my_node: + type: MyType + {{ section }}: + my_parameter1: { {{ function }}: [ SELF, my_parameter2 ] } +""", dict(function=function, section=section)).assert_success() + + +# Unicode + +@pytest.mark.parametrize('function,section', PERMUTATIONS) +def test_functions_modelable_entity_unicode(parser, function, section): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +node_types: + é¡å: + {{ section }}: + åæ¸ä¸: + type: string + åæ¸äº: + type: string + default: å¼ +topology_template: + node_templates: + 模æ¿: + type: é¡å + {{ section }}: + åæ¸ä¸: { {{ function }}: [ 模æ¿, åæ¸äº ] } +""", dict(function=function, section=section)).assert_success() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1efb1e5e/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/1efb1e5e/tests/extensions/aria_extension_tosca/simple_v1_0/templates/common/__init__.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/templates/common/__init__.py b/tests/extensions/aria_extension_tosca/simple_v1_0/templates/common/__init__.py new file mode 100644 index 0000000..ae1e83e --- /dev/null +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/templates/common/__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/1efb1e5e/tests/extensions/aria_extension_tosca/simple_v1_0/templates/common/test_copy.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/templates/common/test_copy.py b/tests/extensions/aria_extension_tosca/simple_v1_0/templates/common/test_copy.py new file mode 100644 index 0000000..7d333e4 --- /dev/null +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/templates/common/test_copy.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 pytest + +from ... import data +from ......mechanisms.utils import matrix + + +PERMUTATIONS = ('node', 'relationship') + + +@pytest.mark.parametrize('name,value', matrix(PERMUTATIONS, data.NOT_A_STRING)) +def test_templates_copy_syntax_type(parser, name, value): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +{{ name }}_types: + MyType: {} +topology_template: + {{ section }}: + my_template: + type: MyType + copying_template: + copy: {{ value }} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], value=value)).assert_failure() + + +@pytest.mark.parametrize('name', PERMUTATIONS) +def test_templates_copy(parser, name): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +{{ name }}_types: + MyType: {} +topology_template: + {{ section }}: + my_template: + type: MyType + copying_template: + copy: my_template +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name])).assert_success() + + +@pytest.mark.parametrize('name', PERMUTATIONS) +def test_templates_copy_unknown(parser, name): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +{{ name }}_types: + MyType: {} +topology_template: + {{ section }}: + my_template: + type: MyType + copying_template: + copy: unknown +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name])).assert_failure() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1efb1e5e/tests/extensions/aria_extension_tosca/simple_v1_0/templates/common/test_template_interface.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/templates/common/test_template_interface.py b/tests/extensions/aria_extension_tosca/simple_v1_0/templates/common/test_template_interface.py new file mode 100644 index 0000000..98ccc8c --- /dev/null +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/templates/common/test_template_interface.py @@ -0,0 +1,914 @@ +# -*- 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 + +from ... import data +from ......mechanisms.utils import matrix + + +MAIN_MACROS = """ +{% macro additions() %} +{%- endmacro %} +{% macro type_interfaces() %} + interfaces: {{ caller()|indent(6) }} +{%- endmacro %} +{% macro interfaces() %} + interfaces: {{ caller()|indent(8) }} +{%- endmacro %} +""" + +RELATIONSHIP_MACROS = """ +{% macro additions() %} +capability_types: + MyType: {} +relationship_types: + MyType: {} +{%- endmacro %} +{% macro type_interfaces() %} + requirements: + - my_requirement: + capability: MyType + relationship: + type: MyType + interfaces: {{ caller()|indent(14) }} +{%- endmacro %} +{% macro interfaces() %} + requirements: + - my_requirement: + relationship: + interfaces: {{ caller()|indent(16) }} +{%- endmacro %} +""" + +RELATIONSHIP_TYPE_MACROS = """ +{% macro additions() %} +capability_types: + MyType: {} +{%- endmacro %} +{% macro type_interfaces() %} + requirements: + - my_requirement: + capability: MyType + relationship: + type: MyType +relationship_types: + MyType: + interfaces: {{ caller()|indent(6) }} +{%- endmacro %} +{% macro interfaces() %} + requirements: + - my_requirement: + relationship: + interfaces: {{ caller()|indent(16) }} +{%- endmacro %} +""" + +RELATIONSHIP_TEMPLATE_MACROS = """ +{% macro additions() %} +capability_types: + MyType: {} +{%- endmacro %} +{% macro type_interfaces() %} + requirements: + - my_requirement: + capability: MyType + relationship: + type: MyType +relationship_types: + MyType: + interfaces: {{ caller()|indent(6) }} +{%- endmacro %} +{% macro interfaces() %} + requirements: + - my_requirement: + relationship: my_template + relationship_templates: + my_template: + type: MyType + interfaces: {{ caller()|indent(8) }} +{%- endmacro %} +""" + +MACROS = { + 'main': MAIN_MACROS, + 'relationship': RELATIONSHIP_MACROS, + 'relationship-type': RELATIONSHIP_TYPE_MACROS, + 'relationship-template': RELATIONSHIP_TEMPLATE_MACROS +} + +PERMUTATIONS = ( + ('main', 'node'), + ('main', 'group'), + ('main', 'relationship'), + ('relationship', 'node'), + ('relationship-type', 'node'), + ('relationship-template', 'node') +) + + +# Interfaces section + +@pytest.mark.parametrize('macros,name,value', matrix( + PERMUTATIONS, + data.NOT_A_DICT, + counts=(2, 1) +)) +def test_template_interfaces_section_syntax_type(parser, macros, name, value): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +interface_types: + MyType: {} +{{ name }}_types: + MyType: +{%- call type_interfaces() -%} +{} +{% endcall %} +topology_template: + {{ section }}: + my_template: + type: MyType +{%- call interfaces() -%} +{{ value }} +{% endcall %} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], value=value)).assert_failure() + + +@pytest.mark.parametrize('macros,name', PERMUTATIONS) +def test_template_interfaces_section_syntax_empty(parser, macros, name): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +interface_types: + MyType: {} +{{ name }}_types: + MyType: +{%- call type_interfaces() -%} +{} +{% endcall %} +topology_template: + {{ section }}: + my_template: + type: MyType +{%- call interfaces() -%} +{} +{% endcall %} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name])).assert_success() + + +# Interface + +@pytest.mark.parametrize('macros,name,value', matrix( + PERMUTATIONS, + data.NOT_A_DICT, + counts=(2, 1) +)) +def test_template_interface_syntax_type(parser, macros, name, value): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +interface_types: + MyType: {} +{{ name }}_types: + MyType: +{%- call type_interfaces() %} +MyInterface: + type: MyType +{% endcall %} +topology_template: + {{ section }}: + my_template: + type: MyType +{%- call interfaces() %} +MyInterface: {{ value }} +{% endcall %} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], value=value)).assert_failure() + + +@pytest.mark.parametrize('macros,name', PERMUTATIONS) +def test_template_interface_syntax_empty(parser, macros, name): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +interface_types: + MyType: {} +{{ name }}_types: + MyType: +{%- call type_interfaces() %} +MyInterface: + type: MyType +{% endcall %} +topology_template: + {{ section }}: + my_template: + type: MyType +{%- call interfaces() %} +MyInterface: {} +{% endcall %} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name])).assert_success() + + +# Interface input + +@pytest.mark.parametrize('macros,name,value', matrix( + PERMUTATIONS, + data.NOT_A_DICT, + counts=(2, 1) +)) +def test_template_interface_inputs_section_syntax_type(parser, macros, name, value): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +interface_types: + MyType: {} +{{ name }}_types: + MyType: +{%- call type_interfaces() %} +MyInterface: + type: MyType +{% endcall %} +topology_template: + {{ section }}: + my_template: + type: MyType +{%- call interfaces() %} +MyInterface: + inputs: {{ value }} +{% endcall %} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], value=value)).assert_failure() + + +@pytest.mark.parametrize('macros,name', PERMUTATIONS) +def test_template_interface_inputs_section_syntax_empty(parser, macros, name): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +interface_types: + MyType: {} +{{ name }}_types: + MyType: +{%- call type_interfaces() %} +MyInterface: + type: MyType +{% endcall %} +topology_template: + {{ section }}: + my_template: + type: MyType +{%- call interfaces() %} +MyInterface: + inputs: {} +{% endcall %} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name])).assert_success() + + +@pytest.mark.parametrize('macros,name,type_name,value', matrix( + PERMUTATIONS, + data.PARAMETER_VALUES, + counts=(2, 2) +)) +def test_template_interface_input_from_type(parser, macros, name, type_name, value): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +data_types: + MyType: + properties: + my_field: + type: string +interface_types: + MyType: {} +{{ name }}_types: + MyType: +{%- call type_interfaces() %} +MyInterface: + type: MyType + inputs: + my_input: + type: {{ type_name }} +{% endcall %} +topology_template: + {{ section }}: + my_template: + type: MyType +{%- call interfaces() %} +MyInterface: + inputs: + my_input: {{ value }} +{% endcall %} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], type_name=type_name, + value=value)).assert_success() + + +@pytest.mark.parametrize('macros,name,type_name,value', matrix( + PERMUTATIONS, + data.PARAMETER_VALUES, + counts=(2, 2) +)) +def test_template_interface_input_from_interface_type(parser, macros, name, type_name, value): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +data_types: + MyType: + properties: + my_field: + type: string +interface_types: + MyType: + inputs: + my_input: + type: {{ type_name }} +{{ name }}_types: + MyType: +{%- call type_interfaces() %} +MyInterface: + type: MyType +{% endcall %} +topology_template: + {{ section }}: + my_template: + type: MyType +{%- call interfaces() %} +MyInterface: + inputs: + my_input: {{ value }} +{% endcall %} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], type_name=type_name, + value=value)).assert_success() + + +@pytest.mark.parametrize('macros,name', PERMUTATIONS) +def test_template_interface_input_missing(parser, macros, name): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +interface_types: + MyType: {} +{{ name }}_types: + MyType: +{%- call type_interfaces() %} +MyInterface: + type: MyType +{% endcall %} +topology_template: + {{ section }}: + my_template: + type: MyType +{%- call interfaces() %} +MyInterface: + inputs: + my_input: a value +{% endcall %} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name]), + adhoc_inputs=False).assert_failure() + + +# Operation + +@pytest.mark.parametrize('macros,name,value', matrix( + PERMUTATIONS, + data.NOT_A_DICT_OR_STRING, + counts=(2, 1) +)) +def test_template_interface_operation_syntax_type(parser, macros, name, value): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +interface_types: + MyType: {} +{{ name }}_types: + MyType: +{%- call type_interfaces() %} +MyInterface: + type: MyType + my_operation: {} +{% endcall %} +topology_template: + {{ section }}: + my_template: + type: MyType +{%- call interfaces() %} +MyInterface: + my_operation: {{ value }} +{% endcall %} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], value=value)).assert_failure() + + +@pytest.mark.parametrize('macros,name', PERMUTATIONS) +def test_template_interface_operation_syntax_unsupported(parser, macros, name): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +interface_types: + MyType: {} +{{ name }}_types: + MyType: +{%- call type_interfaces() %} +MyInterface: + type: MyType + my_operation: {} +{% endcall %} +topology_template: + {{ section }}: + my_template: + type: MyType +{%- call interfaces() %} +MyInterface: + my_operation: + unsupported: {} +{% endcall %} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name])).assert_failure() + + +@pytest.mark.parametrize('macros,name', PERMUTATIONS) +def test_template_interface_operation_syntax_empty(parser, macros, name): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +interface_types: + MyType: {} +{{ name }}_types: + MyType: +{%- call type_interfaces() %} +MyInterface: + type: MyType + my_operation: {} +{% endcall %} +topology_template: + {{ section }}: + my_template: + type: MyType +{%- call interfaces() %} +MyInterface: + my_operation: {} +{% endcall %} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name])).assert_success() + + +@pytest.mark.parametrize('macros,name', PERMUTATIONS) +def test_template_interface_operation_from_type(parser, macros, name): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +interface_types: + MyType: {} +{{ name }}_types: + MyType: +{%- call type_interfaces() %} +MyInterface: + type: MyType + my_operation: {} +{% endcall %} +topology_template: + {{ section }}: + my_template: + type: MyType +{%- call interfaces() %} +MyInterface: + my_operation: {} +{% endcall %} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name])).assert_success() + + +@pytest.mark.parametrize('macros,name', PERMUTATIONS) +def test_template_interface_operation_from_interface_type(parser, macros, name): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +interface_types: + MyType: + my_operation: {} +{{ name }}_types: + MyType: +{%- call type_interfaces() %} +MyInterface: + type: MyType +{% endcall %} +topology_template: + {{ section }}: + my_template: + type: MyType +{%- call interfaces() %} +MyInterface: + my_operation: {} +{% endcall %} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name])).assert_success() + + +@pytest.mark.parametrize('macros,name', PERMUTATIONS) +def test_template_interface_operation_missing(parser, macros, name): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +interface_types: + MyType: {} +{{ name }}_types: + MyType: +{%- call type_interfaces() %} +MyInterface: + type: MyType +{% endcall %} +topology_template: + {{ section }}: + my_template: + type: MyType +{%- call interfaces() %} +MyInterface: + my_operation: {} +{% endcall %} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name])).assert_failure() + + +# Operation implementation + +@pytest.mark.parametrize('macros,name,value', matrix( + PERMUTATIONS, + data.NOT_A_DICT_OR_STRING, + counts=(2, 1) +)) +def test_template_interface_operation_implementation_syntax_type(parser, macros, name, value): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +interface_types: + MyType: {} +{{ name }}_types: + MyType: +{%- call type_interfaces() %} +MyInterface: + type: MyType + my_operation: {} +{% endcall %} +topology_template: + {{ section }}: + my_template: + type: MyType +{%- call interfaces() %} +MyInterface: + my_operation: + implementation: {{ value }} +{% endcall %} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], value=value)).assert_failure() + + +@pytest.mark.parametrize('macros,name', PERMUTATIONS) +def test_template_interface_operation_implementation_syntax_unsupported(parser, macros, name): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +interface_types: + MyType: {} +{{ name }}_types: + MyType: +{%- call type_interfaces() %} +MyInterface: + type: MyType + my_operation: {} +{% endcall %} +topology_template: + {{ section }}: + my_template: + type: MyType +{%- call interfaces() %} +MyInterface: + my_operation: + implementation: + unsupported: {} +{% endcall %} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name])).assert_failure() + + +@pytest.mark.parametrize('macros,name', PERMUTATIONS) +def test_template_interface_operation_implementation_syntax_empty(parser, macros, name): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +interface_types: + MyType: {} +{{ name }}_types: + MyType: +{%- call type_interfaces() %} +MyInterface: + type: MyType + my_operation: {} +{% endcall %} +topology_template: + {{ section }}: + my_template: + type: MyType +{%- call interfaces() %} +MyInterface: + my_operation: + implementation: {} +{% endcall %} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name])).assert_success() + + +@pytest.mark.parametrize('macros,name,value', matrix( + PERMUTATIONS, + data.NOT_A_STRING, + counts=(2, 1) +)) +def test_template_interface_operation_implementation_primary_syntax_type(parser, macros, name, + value): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +interface_types: + MyType: {} +{{ name }}_types: + MyType: +{%- call type_interfaces() %} +MyInterface: + type: MyType + my_operation: {} +{% endcall %} +topology_template: + {{ section }}: + my_template: + type: MyType +{%- call interfaces() %} +MyInterface: + my_operation: + implementation: + primary: {{ value }} +{% endcall %} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], value=value)).assert_failure() + + +@pytest.mark.parametrize('macros,name', PERMUTATIONS) +def test_template_interface_operation_implementation_primary_short_form(parser, macros, name): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +interface_types: + MyType: {} +{{ name }}_types: + MyType: +{%- call type_interfaces() %} +MyInterface: + type: MyType + my_operation: {} +{% endcall %} +topology_template: + {{ section }}: + my_template: + type: MyType +{%- call interfaces() %} +MyInterface: + my_operation: + implementation: an implementation +{% endcall %} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name])).assert_success() + + +@pytest.mark.parametrize('macros,name,value', matrix( + PERMUTATIONS, + data.NOT_A_LIST, + counts=(2, 1) +)) +def test_template_interface_operation_implementation_dependencies_syntax_type(parser, macros, name, + value): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +interface_types: + MyType: {} +{{ name }}_types: + MyType: +{%- call type_interfaces() %} +MyInterface: + type: MyType + my_operation: {} +{% endcall %} +topology_template: + {{ section }}: + my_template: + type: MyType +{%- call interfaces() %} +MyInterface: + my_operation: + implementation: + dependencies: {{ value }} +{% endcall %} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], value=value)).assert_failure() + + +@pytest.mark.parametrize('macros,name,value', matrix( + PERMUTATIONS, + data.NOT_A_STRING, + counts=(2, 1) +)) +def test_template_interface_operation_implementation_dependencies_syntax_element_type(parser, + macros, name, + value): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +interface_types: + MyType: {} +{{ name }}_types: + MyType: +{%- call type_interfaces() %} +MyInterface: + type: MyType + my_operation: {} +{% endcall %} +topology_template: + {{ section }}: + my_template: + type: MyType +{%- call interfaces() %} +MyInterface: + my_operation: + implementation: + dependencies: + - {{ value }} +{% endcall %} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], value=value)).assert_failure() + + +@pytest.mark.parametrize('macros,name', PERMUTATIONS) +def test_template_interface_operation_implementation_dependencies_syntax_empty(parser, macros, + name): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +interface_types: + MyType: {} +{{ name }}_types: + MyType: +{%- call type_interfaces() %} +MyInterface: + type: MyType + my_operation: {} +{% endcall %} +topology_template: + {{ section }}: + my_template: + type: MyType +{%- call interfaces() %} +MyInterface: + my_operation: + implementation: + dependencies: [] +{% endcall %} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name])).assert_success() + + +# Operation input + +@pytest.mark.parametrize('macros,name,type_name,value', matrix( + PERMUTATIONS, + data.PARAMETER_VALUES, + counts=(2, 2) +)) +def test_template_interface_operation_input_from_type(parser, macros, name, type_name, value): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +data_types: + MyType: + properties: + my_field: + type: string +interface_types: + MyType: {} +{{ name }}_types: + MyType: +{%- call type_interfaces() %} +MyInterface: + type: MyType + my_operation: + inputs: + my_input: + type: {{ type_name }} +{% endcall %} +topology_template: + {{ section }}: + my_template: + type: MyType +{%- call interfaces() %} +MyInterface: + my_operation: + inputs: + my_input: {{ value }} +{% endcall %} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], type_name=type_name, + value=value)).assert_success() + + +@pytest.mark.parametrize('macros,name,type_name,value', matrix( + PERMUTATIONS, + data.PARAMETER_VALUES, + counts=(2, 2) +)) +def test_template_interface_operation_input_from_interface_type(parser, macros, name, type_name, + value): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +data_types: + MyType: + properties: + my_field: + type: string +interface_types: + MyType: + my_operation: + inputs: + my_input: + type: {{ type_name }} +{{ name }}_types: + MyType: +{%- call type_interfaces() %} +MyInterface: + type: MyType +{% endcall %} +topology_template: + {{ section }}: + my_template: + type: MyType +{%- call interfaces() %} +MyInterface: + my_operation: + inputs: + my_input: {{ value }} +{% endcall %} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], type_name=type_name, + value=value)).assert_success() + + +@pytest.mark.parametrize('macros,name', PERMUTATIONS) +def test_template_interface_operation_input_missing(parser, macros, name): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +interface_types: + MyType: {} +{{ name }}_types: + MyType: +{%- call type_interfaces() %} +MyInterface: + type: MyType + my_operation: {} +{% endcall %} +topology_template: + {{ section }}: + my_template: + type: MyType +{%- call interfaces() %} +MyInterface: + my_operation: + inputs: + my_input: a value +{% endcall %} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name]), + adhoc_inputs=False).assert_failure() + + +# Unicode + +@pytest.mark.parametrize('macros,name', PERMUTATIONS) +def test_template_interface_unicode(parser, macros, name): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +interface_types: + é¡å: {} +{{ name }}_types: + é¡å: +{%- call type_interfaces() %} +æ¥å£: + type: é¡å + æè¡: + inputs: + è¼¸å ¥: + type: string +{% endcall %} +topology_template: + {{ section }}: + 模æ¿: + type: é¡å +{%- call interfaces() %} +æ¥å£: + æè¡: + inputs: + è¼¸å ¥: å¼ +{% endcall %} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name])).assert_success() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1efb1e5e/tests/extensions/aria_extension_tosca/simple_v1_0/templates/common/test_template_parameters.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/templates/common/test_template_parameters.py b/tests/extensions/aria_extension_tosca/simple_v1_0/templates/common/test_template_parameters.py new file mode 100644 index 0000000..c5fcd30 --- /dev/null +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/templates/common/test_template_parameters.py @@ -0,0 +1,781 @@ +# -*- 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. + +""" +Unified testing for properties, attributes, and inputs. + +Additional tests for properties are in test_template_properties.py. +""" + +import pytest + +from ... import data +from ......mechanisms.utils import matrix + + +# Assigning to parameters defined at a type +MAIN_MACROS = """ +{% macro additions() %} +{%- endmacro %} +{% macro type_parameters() %} + {{ parameter_section }}: {{ caller()|indent(6) }} +{%- endmacro %} +{% macro parameters() %} + {{ parameter_section }}: {{ caller()|indent(8) }} +{%- endmacro %} +""" + +# Assigning to parameters defined at a capability type +CAPABILITY_MACROS = """ +{% macro additions() %} +{%- endmacro %} +{% macro type_parameters() %} + capabilities: + my_capability: + type: MyType +capability_types: + MyType: + {{ parameter_section }}: {{ caller()|indent(6) }} +{%- endmacro %} +{% macro parameters() %} + capabilities: + my_capability: + {{ parameter_section }}: {{ caller()|indent(12) }} +{%- endmacro %} +""" + +# Assigning to parameters defined at an artifact type +ARTIFACT_MACROS = """ +{% macro additions() %} +{%- endmacro %} +{% macro type_parameters() %} {} +artifact_types: + MyType: + {{ parameter_section }}: {{ caller()|indent(6) }} +{%- endmacro %} +{% macro parameters() %} + artifacts: + my_artifact: + type: MyType + file: a file + {{ parameter_section }}: {{ caller()|indent(12) }} +{%- endmacro %} +""" + +# Assigning to inputs defined at an interface type +INTERFACE_MACROS = """ +{% macro additions() %} +{%- endmacro %} +{% macro type_parameters() %} + interfaces: + MyInterface: + type: MyType +interface_types: + MyType: + {{ parameter_section }}: {{ caller()|indent(6) }} +{%- endmacro %} +{% macro parameters() %} + interfaces: + MyInterface: + {{ parameter_section }}: {{ caller()|indent(12) }} +{%- endmacro %} +""" + +# Assigning to inputs defined at an operation of an interface type +OPERATION_MACROS = """ +{% macro additions() %} +{%- endmacro %} +{% macro type_parameters() %} + interfaces: + MyInterface: + type: MyType +interface_types: + MyType: + my_operation: + {{ parameter_section }}: {{ caller()|indent(8) }} +{%- endmacro %} +{% macro parameters() %} + interfaces: + MyInterface: + my_operation: + {{ parameter_section }}: {{ caller()|indent(14) }} +{%- endmacro %} +""" + +# Assigning to inputs defined (added/overridden) at an interface of the template's type +LOCAL_INTERFACE_MACROS = """ +{% macro additions() %} +interface_types: + MyType: {} +{%- endmacro %} +{% macro type_parameters() %} + interfaces: + MyInterface: + type: MyType + {{ parameter_section }}: {{ caller()|indent(10) }} +{%- endmacro %} +{% macro parameters() %} + interfaces: + MyInterface: + {{ parameter_section }}: {{ caller()|indent(12) }} +{%- endmacro %} +""" + +# Assigning to inputs defined (added/overridden) at an operation of an interface of the template's +# type +LOCAL_OPERATION_MACROS = """ +{% macro additions() %} +interface_types: + MyType: {} +{%- endmacro %} +{% macro type_parameters() %} + interfaces: + MyInterface: + type: MyType + my_operation: + {{ parameter_section }}: {{ caller()|indent(12) }} +{%- endmacro %} +{% macro parameters() %} + interfaces: + MyInterface: + my_operation: + {{ parameter_section }}: {{ caller()|indent(14) }} +{%- endmacro %} +""" + +# At a relationship of a node template, assigning to parameters defined at a relationship type +RELATIONSHIP_TYPE_MACROS = """ +{% macro additions() %} +capability_types: + MyType: {} +interface_types: + MyType: {} +{%- endmacro %} +{% macro type_parameters() %} + requirements: + - my_requirement: + capability: MyType + relationship: + type: MyType +relationship_types: + MyType: + {{ parameter_section }}: {{ caller()|indent(6) }} +{%- endmacro %} +{% macro parameters() %} + requirements: + - my_requirement: + relationship: + {{ parameter_section }}: {{ caller()|indent(16) }} +{%- endmacro %} +""" + +# At a relationship of a node template, assigning to inputs defined at an interface type +RELATIONSHIP_INTERFACE_MACROS = """ +{% macro additions() %} +capability_types: + MyType: {} +relationship_types: + MyType: {} +{%- endmacro %} +{% macro type_parameters() %} + requirements: + - my_requirement: + capability: MyType + relationship: + type: MyType + interfaces: + MyInterface: + type: MyType +interface_types: + MyType: + {{ parameter_section }}: {{ caller()|indent(8) }} +{%- endmacro %} +{% macro parameters() %} + requirements: + - my_requirement: + relationship: + interfaces: + MyInterface: + {{ parameter_section }}: {{ caller()|indent(20) }} +{%- endmacro %} +""" + +# At a relationship of a node template, assigning to inputs defined at an operation of an interface +# type +RELATIONSHIP_OPERATION_MACROS = """ +{% macro additions() %} +capability_types: + MyType: {} +relationship_types: + MyType: {} +{%- endmacro %} +{% macro type_parameters() %} + requirements: + - my_requirement: + capability: MyType + relationship: + type: MyType + interfaces: + MyInterface: + type: MyType +interface_types: + MyType: + my_operation: + {{ parameter_section }}: {{ caller()|indent(10) }} +{%- endmacro %} +{% macro parameters() %} + requirements: + - my_requirement: + relationship: + interfaces: + MyInterface: + my_operation: + {{ parameter_section }}: {{ caller()|indent(22) }} +{%- endmacro %} +""" + +# At a relationship of a node template, assigning to inputs defined (added/overridden) at an +# interface of a relationship type +RELATIONSHIP_TYPE_INTERFACE_MACROS = """ +{% macro additions() %} +capability_types: + MyType: {} +interface_types: + MyType: {} +{%- endmacro %} +{% macro type_parameters() %} + requirements: + - my_requirement: + capability: MyType + relationship: + type: MyType +relationship_types: + MyType: + interfaces: + MyInterface: + type: MyType + {{ parameter_section }}: {{ caller()|indent(10) }} +{%- endmacro %} +{% macro parameters() %} + requirements: + - my_requirement: + relationship: + interfaces: + MyInterface: + {{ parameter_section }}: {{ caller()|indent(20) }} +{%- endmacro %} +""" + +# At a relationship of a node template, assigning to inputs defined (added/overridden) at an +# operation of an interface of a relationship type +RELATIONSHIP_TYPE_OPERATION_MACROS = """ +{% macro additions() %} +capability_types: + MyType: {} +interface_types: + MyType: {} +{%- endmacro %} +{% macro type_parameters() %} + requirements: + - my_requirement: + capability: MyType + relationship: + type: MyType +relationship_types: + MyType: + interfaces: + MyInterface: + type: MyType + my_operation: + {{ parameter_section }}: {{ caller()|indent(12) }} +{%- endmacro %} +{% macro parameters() %} + requirements: + - my_requirement: + relationship: + interfaces: + MyInterface: + my_operation: + {{ parameter_section }}: {{ caller()|indent(22) }} +{%- endmacro %} +""" + +# At a relationship of a node template, assigning to inputs defined (added/overridden) at an +# interface of the relationship of the node type +RELATIONSHIP_LOCAL_INTERFACE_MACROS = """ +{% macro additions() %} +capability_types: + MyType: {} +relationship_types: + MyType: {} +interface_types: + MyType: {} +{%- endmacro %} +{% macro type_parameters() %} + requirements: + - my_requirement: + capability: MyType + relationship: + type: MyType + interfaces: + MyInterface: + type: MyType + {{ parameter_section }}: {{ caller()|indent(18) }} +{%- endmacro %} +{% macro parameters() %} + requirements: + - my_requirement: + relationship: + interfaces: + MyInterface: + {{ parameter_section }}: {{ caller()|indent(20) }} +{%- endmacro %} +""" + +# At a relationship of a node template, assigning to inputs defined (added/overridden) at an +# operation of an interface of the relationship of the node type +RELATIONSHIP_LOCAL_OPERATION_MACROS = """ +{% macro additions() %} +capability_types: + MyType: {} +relationship_types: + MyType: {} +interface_types: + MyType: {} +{%- endmacro %} +{% macro type_parameters() %} + requirements: + - my_requirement: + capability: MyType + relationship: + type: MyType + interfaces: + MyInterface: + type: MyType + my_operation: + {{ parameter_section }}: {{ caller()|indent(20) }} +{%- endmacro %} +{% macro parameters() %} + requirements: + - my_requirement: + relationship: + interfaces: + MyInterface: + my_operation: + {{ parameter_section }}: {{ caller()|indent(22) }} +{%- endmacro %} +""" + +MACROS = { + 'main': MAIN_MACROS, + 'capability': CAPABILITY_MACROS, + 'artifact': ARTIFACT_MACROS, + 'interface': INTERFACE_MACROS, + 'operation': OPERATION_MACROS, + 'local-interface': LOCAL_INTERFACE_MACROS, + 'local-operation': LOCAL_OPERATION_MACROS, + 'relationship-type': RELATIONSHIP_TYPE_MACROS, + 'relationship-interface': RELATIONSHIP_INTERFACE_MACROS, + 'relationship-operation': RELATIONSHIP_OPERATION_MACROS, + 'relationship-type-interface': RELATIONSHIP_TYPE_INTERFACE_MACROS, + 'relationship-type-operation': RELATIONSHIP_TYPE_OPERATION_MACROS, + 'relationship-local-interface': RELATIONSHIP_LOCAL_INTERFACE_MACROS, + 'relationship-local-operation': RELATIONSHIP_LOCAL_OPERATION_MACROS +} + +PERMUTATIONS = ( + ('main', 'node', 'properties'), + ('main', 'node', 'attributes'), + ('main', 'group', 'properties'), + ('main', 'relationship', 'properties'), + ('main', 'relationship', 'attributes'), + ('main', 'policy', 'properties'), + ('capability', 'node', 'properties'), + ('capability', 'node', 'attributes'), + ('artifact', 'node', 'properties'), + ('interface', 'node', 'inputs'), + ('interface', 'group', 'inputs'), + ('interface', 'relationship', 'inputs'), + ('operation', 'node', 'inputs'), + ('operation', 'group', 'inputs'), + ('operation', 'relationship', 'inputs'), + ('local-interface', 'node', 'inputs'), + ('local-interface', 'group', 'inputs'), + ('local-interface', 'relationship', 'inputs'), + ('local-operation', 'node', 'inputs'), + ('local-operation', 'group', 'inputs'), + ('local-operation', 'relationship', 'inputs'), + ('relationship-type', 'node', 'properties'), + ('relationship-interface', 'node', 'inputs'), + #('relationship-operation', 'node', 'inputs'), # fix + ('relationship-type-interface', 'node', 'inputs'), + ('relationship-type-operation', 'node', 'inputs'), # fix + ('relationship-local-interface', 'node', 'inputs'), + #('relationship-operation', 'node', 'inputs'), # fix +) + + +# Parameters section + +@pytest.mark.parametrize('macros,name,parameter_section,value', matrix( + PERMUTATIONS, + data.NOT_A_DICT, + counts=(3, 1) +)) +def test_template_parameters_section_syntax_type(parser, macros, name, parameter_section, value): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +{{ name }}_types: + MyType: +{%- call type_parameters() -%} +{} +{% endcall %} +topology_template: + {{ section }}: + my_template: + type: MyType +{%- call parameters() -%} +{{ value }} +{% endcall %} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], + parameter_section=parameter_section, value=value)).assert_failure() + + +@pytest.mark.parametrize('macros,name,parameter_section', PERMUTATIONS) +def test_template_parameters_section_syntax_empty(parser, macros, name, parameter_section): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +{{ name }}_types: + MyType: +{%- call type_parameters() -%} +{} +{% endcall %} +topology_template: + {{ section }}: + my_template: + type: MyType +{%- call parameters() -%} +{} +{% endcall %} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], + parameter_section=parameter_section)).assert_success() + + +# Parameter + +@pytest.mark.parametrize('macros,name,parameter_section', (('capability', 'node', 'attributes'),)) +def test_template_parameter_missing(parser, macros, name, parameter_section): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +{{ name }}_types: + MyType: +{%- call type_parameters() -%} +{} +{% endcall %} +topology_template: + {{ section }}: + my_template: + type: MyType +{%- call parameters() %} +my_parameter: a value +{% endcall %} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], + parameter_section=parameter_section)).assert_failure() + + +# Entry schema + +@pytest.mark.parametrize('macros,name,parameter_section,values', matrix( + PERMUTATIONS, + data.ENTRY_SCHEMA_VALUES, + counts=(3, 1) +)) +def test_template_parameter_map(parser, macros, name, parameter_section, values): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +data_types: + MyType: + properties: + my_field: + type: string + default: default value +{{ name }}_types: + MyType: +{%- call type_parameters() %} +my_parameter: + type: map + entry_schema: {{ values[0] }} +{% endcall %} +topology_template: + {{ section }}: + my_template: + type: MyType +{%- call parameters() %} +my_parameter: + key1: {{ values[1] }} + key2: {{ values[2] }} +{% endcall %} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], parameter_section=parameter_section, + values=values), import_profile=True).assert_success() + + +@pytest.mark.parametrize('macros,name,parameter_section,values', matrix( + PERMUTATIONS, + data.ENTRY_SCHEMA_VALUES_BAD, + counts=(3, 1) +)) +def test_template_parameter_map_bad(parser, macros, name, parameter_section, values): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +data_types: + MyType: + properties: + my_field: + type: string + default: default value +{{ name }}_types: + MyType: +{%- call type_parameters() %} +my_parameter: + type: map + entry_schema: {{ values[0] }} +{% endcall %} +topology_template: + {{ section }}: + my_template: + type: MyType +{%- call parameters() %} +my_parameter: + key1: {{ values[1] }} + key2: {{ values[2] }} +{% endcall %} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], parameter_section=parameter_section, + values=values), import_profile=True).assert_failure() + + +@pytest.mark.parametrize('macros,name,parameter_section', PERMUTATIONS) +def test_template_parameter_map_required_field(parser, macros, name, parameter_section): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +data_types: + MyType: + properties: + my_field: + type: string +{{ name }}_types: + MyType: +{%- call type_parameters() %} +my_parameter: + type: map + entry_schema: MyType +{% endcall %} +topology_template: + {{ section }}: + my_template: + type: MyType +{%- call parameters() %} +my_parameter: + key: {my_field: a value} +{% endcall %} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], + parameter_section=parameter_section), import_profile=True).assert_success() + + +@pytest.mark.parametrize('macros,name,parameter_section', PERMUTATIONS) +def test_template_parameter_map_required_field_bad(parser, macros, name, parameter_section): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +data_types: + MyType: + properties: + my_field: + type: string +{{ name }}_types: + MyType: +{%- call type_parameters() %} +my_parameter: + type: map + entry_schema: MyType +{% endcall %} +topology_template: + {{ section }}: + my_template: + type: MyType +{%- call parameters() %} +my_parameter: + key: {} +{% endcall %} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], + parameter_section=parameter_section), import_profile=True).assert_failure() + + +@pytest.mark.parametrize('macros,name,parameter_section,values', matrix( + PERMUTATIONS, + data.ENTRY_SCHEMA_VALUES, + counts=(3, 1) +)) +def test_template_parameter_list(parser, macros, name, parameter_section, values): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +data_types: + MyType: + properties: + my_field: + type: string + default: default value +{{ name }}_types: + MyType: +{%- call type_parameters() %} +my_parameter: + type: list + entry_schema: {{ values[0] }} +{% endcall %} +topology_template: + {{ section }}: + my_template: + type: MyType +{%- call parameters() %} +my_parameter: + - {{ values[1] }} + - {{ values[2] }} +{% endcall %} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], parameter_section=parameter_section, + values=values), import_profile=True).assert_success() + + +@pytest.mark.parametrize('macros,name,parameter_section,values', matrix( + PERMUTATIONS, + data.ENTRY_SCHEMA_VALUES_BAD, + counts=(3, 1) +)) +def test_template_parameter_list_bad(parser, macros, name, parameter_section, values): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +data_types: + MyType: + properties: + my_field: + type: string + default: default value +{{ name }}_types: + MyType: +{%- call type_parameters() %} +my_parameter: + type: list + entry_schema: {{ values[0] }} +{% endcall %} +topology_template: + {{ section }}: + my_template: + type: MyType +{%- call parameters() %} +my_parameter: + - {{ values[1] }} + - {{ values[2] }} +{% endcall %} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], parameter_section=parameter_section, + values=values), import_profile=True).assert_failure() + + +@pytest.mark.parametrize('macros,name,parameter_section', PERMUTATIONS) +def test_template_parameter_list_required_field(parser, macros, name, parameter_section): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +data_types: + MyType: + properties: + my_field: + type: string +{{ name }}_types: + MyType: +{%- call type_parameters() %} +my_parameter: + type: list + entry_schema: MyType +{% endcall %} +topology_template: + {{ section }}: + my_template: + type: MyType +{%- call parameters() %} +my_parameter: + - {my_field: a value} +{% endcall %} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], + parameter_section=parameter_section), import_profile=True).assert_success() + + +@pytest.mark.parametrize('macros,name,parameter_section', PERMUTATIONS) +def test_template_parameter_list_required_field_bad(parser, macros, name, parameter_section): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +data_types: + MyType: + properties: + my_field: + type: string +{{ name }}_types: + MyType: +{%- call type_parameters() %} +my_parameter: + type: list + entry_schema: MyType +{% endcall %} +topology_template: + {{ section }}: + my_template: + type: MyType +{%- call parameters() %} +my_parameter: + - {} +{% endcall %} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], + parameter_section=parameter_section), import_profile=True).assert_failure() + + +# Unicode + +@pytest.mark.parametrize('macros,name,parameter_section', PERMUTATIONS) +def test_template_parameter_unicode(parser, macros, name, parameter_section): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +{{ name }}_types: + é¡å: +{%- call type_parameters() %} +åæ¸: + type: string +{% endcall %} +topology_template: + {{ section }}: + 模æ¿: + type: é¡å +{%- call parameters() %} +åæ¸: å¼ +{% endcall %} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], + parameter_section=parameter_section)).assert_success() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1efb1e5e/tests/extensions/aria_extension_tosca/simple_v1_0/templates/common/test_template_parameters_properties.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/templates/common/test_template_parameters_properties.py b/tests/extensions/aria_extension_tosca/simple_v1_0/templates/common/test_template_parameters_properties.py new file mode 100644 index 0000000..bd82766 --- /dev/null +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/templates/common/test_template_parameters_properties.py @@ -0,0 +1,132 @@ +# -*- 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. + +""" +Unified testing for properties (including inputs). + +These tests are in addition to the common tests for parameters in test_template_parameters.py. +""" + +import pytest + +from .test_template_parameters import (MACROS, PERMUTATIONS as PARAMETER_PERMUTATIONS) +from ... import data +from ......mechanisms.utils import matrix + + +PERMUTATIONS = tuple( + (macros, name, parameter_section) + for macros, name, parameter_section in PARAMETER_PERMUTATIONS + if parameter_section != 'attributes' +) + + +# Required + +@pytest.mark.parametrize('macros,name,parameter_section,type_name', matrix( + PERMUTATIONS, + data.PARAMETER_TYPE_NAMES, + counts=(3, 1) +)) +def test_template_parameter_required(parser, macros, name, parameter_section, type_name): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +data_types: + MyType: + properties: + my_field: + type: string +{{ name }}_types: + MyType: +{%- call type_parameters() %} +my_parameter: + type: {{ type_name }} +{% endcall %} +topology_template: + {{ section }}: + my_template: + type: MyType +{%- call parameters() -%} +{} +{% endcall %} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], parameter_section=parameter_section, + type_name=type_name)).assert_failure() + + +@pytest.mark.parametrize('macros,name,parameter_section,type_name', matrix( + PERMUTATIONS, + data.PARAMETER_TYPE_NAMES, + counts=(3, 1) +)) +def test_template_parameter_not_required(parser, macros, name, parameter_section, type_name): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +data_types: + MyType: + properties: + my_field: + type: string +{{ name }}_types: + MyType: +{%- call type_parameters() %} +my_parameter: + type: {{ type_name }} + required: false +{% endcall %} +topology_template: + {{ section }}: + my_template: + type: MyType +{%- call parameters() -%} +{} +{% endcall %} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], parameter_section=parameter_section, + type_name=type_name)).assert_success() + + +@pytest.mark.parametrize('macros,name,parameter_section,type_name,value', matrix( + PERMUTATIONS, + data.PARAMETER_VALUES, + counts=(3, 2) +)) +def test_template_parameter_required_with_default(parser, macros, name, parameter_section, + type_name, value): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +data_types: + MyType: + properties: + my_field: + type: string +{{ name }}_types: + MyType: +{%- call type_parameters() %} +my_parameter: + type: {{ type_name }} + default: {{ value }} +{% endcall %} +topology_template: + {{ section }}: + my_template: + type: MyType +{%- call parameters() -%} +{} +{% endcall %} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], parameter_section=parameter_section, + type_name=type_name, value=value)).assert_success() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1efb1e5e/tests/extensions/aria_extension_tosca/simple_v1_0/templates/common/test_templates.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/templates/common/test_templates.py b/tests/extensions/aria_extension_tosca/simple_v1_0/templates/common/test_templates.py new file mode 100644 index 0000000..62a10ed --- /dev/null +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/templates/common/test_templates.py @@ -0,0 +1,128 @@ +# -*- 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 + +from ... import data +from ......mechanisms.utils import matrix + + +PERMUTATIONS = ('node', 'group', 'relationship', 'policy') + + +# Templates section + +@pytest.mark.parametrize('name,value', matrix( + PERMUTATIONS, + data.NOT_A_DICT +)) +def test_templates_section_syntax_type(parser, name, value): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +topology_template: + {{ section }}: {{ value }} +""", dict(section=data.TEMPLATE_NAME_SECTIONS[name], value=value)).assert_failure() + + +@pytest.mark.parametrize('name', PERMUTATIONS) +def test_templates_section_syntax_empty(parser, name): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +topology_template: + {{ section }}: {} +""", dict(section=data.TEMPLATE_NAME_SECTIONS[name])).assert_success() + + +# Template + +@pytest.mark.parametrize('name', PERMUTATIONS) +def test_template_syntax_unsupported(parser, name): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +{{ name }}_types: + MyType: {} +topology_template: + {{ section }}: + my_template: + type: MyType + unsupported: {} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name])).assert_failure() + + +@pytest.mark.parametrize('name', PERMUTATIONS) +def test_template_syntax_empty(parser, name): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +topology_template: + {{ section }}: + my_template: {} # "type" is required +""", dict(section=data.TEMPLATE_NAME_SECTIONS[name])).assert_failure() + + +# Description + +@pytest.mark.parametrize('name,value', matrix(PERMUTATIONS, data.NOT_A_STRING)) +def test_template_description_syntax_type(parser, name, value): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +{{ name }}_types: + MyType: {} +topology_template: + {{ section }}: + my_template: + type: MyType + description: {{ value }} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], value=value)).assert_failure() + + +# Type + +@pytest.mark.parametrize('name,value', matrix(PERMUTATIONS, data.NOT_A_STRING)) +def test_template_type_syntax_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_SECTIONS[name], value=value)).assert_failure() + + +@pytest.mark.parametrize('name', PERMUTATIONS) +def test_template_type_unknown(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_SECTIONS[name])).assert_failure() + + +# Unicode + +@pytest.mark.parametrize('name', PERMUTATIONS) +def test_template_unicode(parser, name): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +{{ name }}_types: + é¡å: {} +topology_template: + {{ section }}: + 模æ¿: + type: é¡å + description: æè¿° +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name])).assert_success() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1efb1e5e/tests/extensions/aria_extension_tosca/simple_v1_0/templates/node_template/__init__.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/templates/node_template/__init__.py b/tests/extensions/aria_extension_tosca/simple_v1_0/templates/node_template/__init__.py new file mode 100644 index 0000000..ae1e83e --- /dev/null +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/templates/node_template/__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.