http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/b89fdde2/tests/extensions/aria_extension_tosca/simple_v1_0/templates/node_template/test_node_template_artifacts.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/templates/node_template/test_node_template_artifacts.py b/tests/extensions/aria_extension_tosca/simple_v1_0/templates/node_template/test_node_template_artifacts.py new file mode 100644 index 0000000..e9ccc89 --- /dev/null +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/templates/node_template/test_node_template_artifacts.py @@ -0,0 +1,307 @@ +# -*- 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. + +""" +Here we are testing not only artifacts attached to node templates, but also artifacts attached to +node types. The reason is that artifacts attached node types use the same property assignment +(rather than definition) syntax we see in templates. +""" + +import pytest + +from ... import data +from ......mechanisms.utils import matrix + + +# Artifacts attached to a node template +TEMPLATE_MACROS = """ +{% macro artifacts() %} +node_types: + MyType: {} +topology_template: + node_templates: + my_node: + type: MyType + artifacts: {{ caller()|indent(8) }} +{%- endmacro %} +""" + +# Artifacts attached to a node type +TYPE_MACROS = """ +{% macro artifacts() %} +node_types: + MyType: + artifacts: {{ caller()|indent(6) }} +{%- endmacro %} +""" + +MACROS = { + 'template': TEMPLATE_MACROS, + 'type': TYPE_MACROS +} + +PERMUTATIONS = ( + 'template', + 'type' +) + + + +# Artifacts section + +@pytest.mark.parametrize('macros,value', matrix(PERMUTATIONS, data.NOT_A_DICT)) +def test_node_template_artifacts_section_syntax_type(parser, macros, value): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{%- call artifacts() -%} +{{ value }} +{% endcall %} +""", dict(value=value)).assert_failure() + + +@pytest.mark.parametrize('macros', PERMUTATIONS) +def test_node_template_artifacts_section_syntax_empty(parser, macros): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{%- call artifacts() -%} +{} +{% endcall %} +""").assert_success() + + +# Artifact + +@pytest.mark.parametrize('macros,value', matrix(PERMUTATIONS, data.NOT_A_DICT)) +def test_node_template_artifact_syntax_type(parser, macros, value): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{%- call artifacts() %} +my_artifact: {{ value }} +{% endcall %} +""", dict(value=value)).assert_failure() + + +@pytest.mark.parametrize('macros', PERMUTATIONS) +def test_node_template_artifact_syntax_unsupported(parser, macros): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{%- call artifacts() %} +my_artifact: + type: MyType + unsupported: {} +{% endcall %} +""").assert_failure() + + +@pytest.mark.parametrize('macros', PERMUTATIONS) +def test_node_template_artifact_syntax_empty(parser, macros): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{%- call artifacts() %} +my_artifact: {} # "type" and "file" are required +{% endcall %} +""").assert_failure() + + +# Type + +@pytest.mark.parametrize('macros,value', matrix(PERMUTATIONS, data.NOT_A_STRING)) +def test_node_template_artifact_type_syntax_type(parser, macros, value): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{%- call artifacts() %} +my_artifact: + type: {{ value }} + file: a file +{% endcall %} +""", dict(value=value)).assert_failure() + + +@pytest.mark.parametrize('macros', PERMUTATIONS) +def test_node_template_artifact_type_unknown(parser, macros): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{%- call artifacts() %} +my_artifact: + type: UnknownType + file: a file +{% endcall %} +""").assert_failure() + + +# File + +@pytest.mark.parametrize('macros,value', matrix(PERMUTATIONS, data.NOT_A_STRING)) +def test_node_template_artifact_file_syntax_type(parser, macros, value): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +artifact_types: + MyType: {} +{%- call artifacts() %} +my_artifact: + type: MyType + file: {{ value }} +{% endcall %} +""", dict(value=value)).assert_failure() + + +@pytest.mark.parametrize('macros', PERMUTATIONS) +def test_node_template_artifact_file(parser, macros): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +artifact_types: + MyType: {} +{%- call artifacts() %} +my_artifact: + type: MyType + file: a file +{% endcall %} +""").assert_success() + + +# Description + +@pytest.mark.parametrize('macros,value', matrix(PERMUTATIONS, data.NOT_A_STRING)) +def test_node_template_artifact_description_syntax_type(parser, macros, value): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +artifact_types: + MyType: {} +{%- call artifacts() %} +my_artifact: + type: MyType + file: a file + description: {{ value }} +{% endcall %} +""", dict(value=value)).assert_failure() + + +@pytest.mark.parametrize('macros', PERMUTATIONS) +def test_node_template_artifact_description(parser, macros): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +artifact_types: + MyType: {} +{%- call artifacts() %} +my_artifact: + type: MyType + file: a file + description: a description +{% endcall %} +""").assert_success() + + +# Repository + +@pytest.mark.parametrize('macros,value', matrix(PERMUTATIONS, data.NOT_A_STRING)) +def test_node_template_artifact_repository_syntax_type(parser, macros, value): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +artifact_types: + MyType: {} +{%- call artifacts() %} +my_artifact: + type: MyType + file: a file + repository: {{ value }} +{% endcall %} +""", dict(value=value)).assert_failure() + + +@pytest.mark.parametrize('macros', PERMUTATIONS) +def test_node_template_artifact_repository_unknown(parser, macros): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +artifact_types: + MyType: {} +{%- call artifacts() %} +my_artifact: + type: MyType + file: a file + repository: unknown +{% endcall %} +""").assert_failure() + + +@pytest.mark.parametrize('macros', PERMUTATIONS) +def test_node_template_artifact_repository(parser, macros): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +repositories: + my_repository: + url: a url +artifact_types: + MyType: {} +{%- call artifacts() %} +my_artifact: + type: MyType + file: a file + repository: my_repository +{% endcall %} +""").assert_success() + + +# Deploy path + +@pytest.mark.parametrize('macros,value', matrix(PERMUTATIONS, data.NOT_A_STRING)) +def test_node_template_artifact_deploy_path_syntax_type(parser, macros, value): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +artifact_types: + MyType: {} +{%- call artifacts() %} +my_artifact: + type: MyType + file: a file + deploy_path: {{ value }} +{% endcall %} +""", dict(value=value)).assert_failure() + + +@pytest.mark.parametrize('macros', PERMUTATIONS) +def test_node_template_artifact_deploy_path(parser, macros): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +artifact_types: + MyType: {} +{%- call artifacts() %} +my_artifact: + type: MyType + file: a file + deploy_path: a path +{% endcall %} +""").assert_success() + + +# Unicode + +@pytest.mark.parametrize('macros', PERMUTATIONS) +def test_node_template_artifact_unicode(parser, macros): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +repositories: + ç¥è庫: + url: 網å +artifact_types: + é¡å: {} +{%- call artifacts() %} +ç¥å¨: + type: é¡å + file: æ件 + repository: ç¥è庫 + deploy_path: è·¯å¾ +{% endcall %} +""").assert_success()
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/b89fdde2/tests/extensions/aria_extension_tosca/simple_v1_0/templates/node_template/test_node_template_directives.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/templates/node_template/test_node_template_directives.py b/tests/extensions/aria_extension_tosca/simple_v1_0/templates/node_template/test_node_template_directives.py new file mode 100644 index 0000000..5ea2c13 --- /dev/null +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/templates/node_template/test_node_template_directives.py @@ -0,0 +1,77 @@ +# -*- 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 + + +@pytest.mark.parametrize('value', data.NOT_A_LIST) +def test_node_template_directives_syntax_type(parser, value): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +node_types: + MyType: {} +topology_template: + node_templates: + my_node: + type: MyType + directives: {{ value }} +""", dict(value=value)).assert_failure() + + +@pytest.mark.parametrize('value', data.NOT_A_STRING) +def test_node_template_directives_syntax_element_type(parser, value): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +node_types: + MyType: {} +topology_template: + node_templates: + my_node: + type: MyType + directives: [ {{ value }} ] +""", dict(value=value)).assert_failure() + + +def test_node_template_directives_syntax_empty(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +node_types: + MyType: {} +topology_template: + node_templates: + my_node: + type: MyType + directives: [] +""").assert_success() + + +# Unicode + +def test_node_template_directives_unicode(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +node_types: + é¡å: {} +topology_template: + node_templates: + ç¯é»: + type: é¡å + directives: + - æç¤ºä¸ + - æç¤ºäº +""").assert_success() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/b89fdde2/tests/extensions/aria_extension_tosca/simple_v1_0/templates/node_template/test_node_template_node_filter_constraints.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/templates/node_template/test_node_template_node_filter_constraints.py b/tests/extensions/aria_extension_tosca/simple_v1_0/templates/node_template/test_node_template_node_filter_constraints.py new file mode 100644 index 0000000..fad439e --- /dev/null +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/templates/node_template/test_node_template_node_filter_constraints.py @@ -0,0 +1,346 @@ +# -*- 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. + +""" +Compare with test_type_properties.py. Note that though the constraints are the same, their syntax +is very different, making it difficult to test all permutations together. +""" + + +import pytest + +from ... import data +from ......mechanisms.utils import matrix + + +# Properties for node filter in node template +MAIN_MACROS = """ +{% macro additions() %} +data_types: + MyType: + properties: + my_field: + type: string +node_types: + MyType1: {} + MyType2: + properties: + data_property: + type: MyType + string_property: + type: string +{%- endmacro %} +{% macro properties() %} + node_filter: + properties: {{ caller()|indent(10) }} +{%- endmacro %} +""" + +# Capability properties for node filter in node template +MAIN_CAPABILITY_MACROS = """ +{% macro additions() %} +data_types: + MyType: + properties: + my_field: + type: string +capability_types: + MyType: + properties: + data_property: + type: MyType + string_property: + type: string +node_types: + MyType1: {} + MyType2: + capabilities: + my_capability: MyType +{%- endmacro %} +{% macro properties() %} + node_filter: + capabilities: + - my_capability: + properties: {{ caller()|indent(16) }} +{%- endmacro %} +""" + +# Properties for node filter in requirement +REQUIREMENT_MACROS = """ +{% macro additions() %} +data_types: + MyType: + properties: + my_field: + type: string +capability_types: + MyType: {} +node_types: + MyType1: + requirements: + - my_requirement: + capability: MyType + MyType2: + properties: + data_property: + type: MyType + string_property: + type: string + capabilities: + my_capability: MyType +{%- endmacro %} +{% macro properties() %} + requirements: + - my_requirement: + node: MyType2 + node_filter: + properties: {{ caller()|indent(16) }} +{%- endmacro %} +""" + +# Capability properties for node filter in requirement +REQUIREMENT_CAPABILITY_MACROS = """ +{% macro additions() %} +data_types: + MyType: + properties: + my_field: + type: string +capability_types: + MyType: + properties: + data_property: + type: MyType + string_property: + type: string +node_types: + MyType1: + requirements: + - my_requirement: + capability: MyType + MyType2: + capabilities: + my_capability: MyType +{%- endmacro %} +{% macro properties() %} + requirements: + - my_requirement: + node: MyType2 + node_filter: + capabilities: + - my_capability: + properties: {{ caller()|indent(22) }} +{%- endmacro %} +""" + +MACROS = { + 'main': MAIN_MACROS, + 'requirement': REQUIREMENT_MACROS, + 'main-capability': MAIN_CAPABILITY_MACROS, + 'requirement-capability': REQUIREMENT_CAPABILITY_MACROS +} + +PERMUTATIONS = ( + 'main', 'requirement', 'main-capability', 'requirement-capability' +) + + + +@pytest.mark.parametrize('macros,value', matrix(PERMUTATIONS, data.NOT_A_DICT_WITH_ONE_KEY)) +def test_node_template_node_filter_constraints_syntax_type(parser, macros, value): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +topology_template: + node_templates: + my_node: + type: MyType1 +{%- call properties() %} +- data_property: {{ value }} +{% endcall %} +""", dict(value=value)).assert_failure() + + +@pytest.mark.parametrize('macros', PERMUTATIONS) +def test_node_template_node_filter_constraints_syntax_empty(parser, macros): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +topology_template: + node_templates: + my_node: + type: MyType1 +{%- call properties() %} +- data_property: {} +{% endcall %} +""").assert_failure() + + +@pytest.mark.parametrize('macros', PERMUTATIONS) +def test_node_template_node_filter_constraints_syntax_unsupported(parser, macros): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +topology_template: + node_templates: + my_node: + type: MyType1 +{%- call properties() %} +- data_property: { unsupported: a string } +{% endcall %} +""").assert_failure() + + +@pytest.mark.parametrize('macros,constraint', matrix(PERMUTATIONS, data.CONSTRAINTS_WITH_VALUE)) +def test_node_template_node_filter_constraints_with_value(parser, macros, constraint): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +topology_template: + node_templates: + my_node: + type: MyType1 +{%- call properties() %} +- data_property: { {{ constraint }}: {my_field: a string} } +{% endcall %} +""", dict(constraint=constraint)).assert_success() + + +@pytest.mark.parametrize('macros,constraint', matrix(PERMUTATIONS, + data.CONSTRAINTS_WITH_VALUE_LIST)) +def test_node_template_node_filter_constraints_with_value_list(parser, macros, constraint): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +topology_template: + node_templates: + my_node: + type: MyType1 +{%- call properties() %} +- data_property: { {{ constraint }}: [ {my_field: a}, {my_field: b}, {my_field: c} ] } +{% endcall %} +""", dict(constraint=constraint)).assert_success() + + +@pytest.mark.parametrize('macros,constraint', matrix(PERMUTATIONS, + data.CONSTRAINTS_WITH_VALUE_RANGE)) +def test_node_template_node_filter_constraints_with_value_range(parser, macros, constraint): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +topology_template: + node_templates: + my_node: + type: MyType1 +{%- call properties() %} +- data_property: { {{ constraint }}: [ {my_field: string a}, {my_field: string b} ] } +{% endcall %} +""", dict(constraint=constraint)).assert_success() + + +@pytest.mark.parametrize('macros,constraint', matrix(PERMUTATIONS, + data.CONSTRAINTS_WITH_VALUE_RANGE)) +def test_node_template_node_filter_constraints_with_value_range_too_many(parser, macros, + constraint): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +topology_template: + node_templates: + my_node: + type: MyType1 +{%- call properties() %} +- data_property: { {{ constraint }}: [ {my_field: a}, {my_field: b}, {my_field: c} ] } +{% endcall %} +""", dict(constraint=constraint)).assert_failure() + + +@pytest.mark.parametrize('macros,constraint', matrix(PERMUTATIONS, + data.CONSTRAINTS_WITH_VALUE_RANGE)) +def test_node_template_node_filter_constraints_with_value_range_bad(parser, macros, constraint): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +topology_template: + node_templates: + my_node: + type: MyType1 +{%- call properties() %} +- data_property: { {{ constraint }}: [ {my_field: string b}, {my_field: string a} ] } +{% endcall %} +""", dict(constraint=constraint)).assert_failure() + + +@pytest.mark.parametrize('macros', PERMUTATIONS) +def test_node_template_node_filter_constraints_pattern(parser, macros): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +topology_template: + node_templates: + my_node: + type: MyType1 +{%- call properties() %} +- string_property: { pattern: ^pattern$ } +{% endcall %} +""").assert_success() + + +@pytest.mark.parametrize('macros', PERMUTATIONS) +def test_node_template_node_filter_constraints_pattern_bad(parser, macros): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +topology_template: + node_templates: + my_node: + type: MyType1 +{%- call properties() %} +- string_property: { pattern: ( } +{% endcall %} +""").assert_failure() + + +@pytest.mark.parametrize('macros,constraint', matrix(PERMUTATIONS, + data.CONSTRAINTS_WITH_VALUE_NON_NEGATIVE_INT)) +def test_node_template_node_filter_constraints_with_value_integer(parser, macros, constraint): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +topology_template: + node_templates: + my_node: + type: MyType1 +{%- call properties() %} +- string_property: { {{ constraint }}: 1 } +{% endcall %} +""", dict(constraint=constraint)).assert_success() + + +@pytest.mark.parametrize('macros,constraint', matrix(PERMUTATIONS, + data.CONSTRAINTS_WITH_VALUE_NON_NEGATIVE_INT)) +def test_node_template_node_filter_constraints_with_value_integer_bad(parser, macros, constraint): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +topology_template: + node_templates: + my_node: + type: MyType1 +{%- call properties() %} +- string_property: { {{ constraint }}: -1 } +{% endcall %} +""", dict(constraint=constraint)).assert_failure() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/b89fdde2/tests/extensions/aria_extension_tosca/simple_v1_0/templates/node_template/test_node_template_node_filters.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/templates/node_template/test_node_template_node_filters.py b/tests/extensions/aria_extension_tosca/simple_v1_0/templates/node_template/test_node_template_node_filters.py new file mode 100644 index 0000000..0a54961 --- /dev/null +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/templates/node_template/test_node_template_node_filters.py @@ -0,0 +1,313 @@ +# -*- 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 + + +# Node filter in node template +MAIN_MACROS = """ +{% macro additions() %} +node_types: + MyType1: {} + MyType2: + properties: + my_property: + type: string +{%- endmacro %} +{% macro node_filter() %} + node_filter: {{ caller()|indent(8) }} +{%- endmacro %} +""" + + +# Node filter in requirement +REQUIREMENT_MACROS = """ +{% macro additions() %} +capability_types: + MyType: + properties: + my_property: + type: string +node_types: + MyType1: + requirements: + - my_requirement: + capability: MyType + MyType2: + properties: + my_property: + type: string + capabilities: + my_capability: MyType +{%- endmacro %} +{% macro node_filter() %} + requirements: + - my_requirement: + node: MyType2 + node_filter: {{ caller()|indent(14) }} +{%- endmacro %} +""" + +MACROS = { + 'main': MAIN_MACROS, + 'requirement': REQUIREMENT_MACROS +} + +PERMUTATIONS = ( + 'main', 'requirement' +) + + +@pytest.mark.parametrize('macros,value', matrix(PERMUTATIONS, data.NOT_A_DICT)) +def test_node_template_node_filter_syntax_type(parser, macros, value): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +topology_template: + node_templates: + my_node: + type: MyType1 +{%- call node_filter() -%} +{{ value }} +{% endcall %} +""", dict(value=value)).assert_failure() + + +@pytest.mark.parametrize('macros', PERMUTATIONS) +def test_node_template_node_filter_syntax_unsupported(parser, macros): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +topology_template: + node_templates: + my_node: + type: MyType1 +{%- call node_filter() %} +unsupported: {} +{% endcall %} +""").assert_failure() + + +@pytest.mark.parametrize('macros', PERMUTATIONS) +def test_node_template_node_filter_syntax_empty(parser, macros): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +topology_template: + node_templates: + my_node: + type: MyType1 +{%- call node_filter() -%} +{} +{% endcall %} +""").assert_success() + + +# Properties section + +@pytest.mark.parametrize('macros,value', matrix(PERMUTATIONS, data.NOT_A_LIST)) +def test_node_template_node_filter_properties_section_syntax_type(parser, macros, value): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +topology_template: + node_templates: + my_node: + type: MyType1 +{%- call node_filter() %} +properties: {{ value }} +{% endcall %} +""", dict(value=value)).assert_failure() + + +@pytest.mark.parametrize('macros', PERMUTATIONS) +def test_node_template_node_filter_properties_section_syntax_empty(parser, macros): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +topology_template: + node_templates: + my_node: + type: MyType1 +{%- call node_filter() %} +properties: [] +{% endcall %} +""").assert_success() + + +# Capabilities section + +@pytest.mark.parametrize('macros,value', matrix(PERMUTATIONS, data.NOT_A_LIST)) +def test_node_template_node_filter_capabilities_section_syntax_type(parser, macros, value): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +topology_template: + node_templates: + my_node: + type: MyType1 +{%- call node_filter() %} +capabilities: {{ value }} +{% endcall %} +""", dict(value=value)).assert_failure() + + +@pytest.mark.parametrize('macros', PERMUTATIONS) +def test_node_template_node_filter_capabilities_section_syntax_empty(parser, macros): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +topology_template: + node_templates: + my_node: + type: MyType1 +{%- call node_filter() %} +capabilities: [] +{% endcall %} +""").assert_success() + + +# Capability + +@pytest.mark.parametrize('macros,value', matrix(PERMUTATIONS, data.NOT_A_DICT)) +def test_node_template_node_filter_capability_syntax_type(parser, macros, value): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +topology_template: + node_templates: + my_node: + type: MyType1 +{%- call node_filter() %} +capabilities: + - my_capability: {{ value }} +{% endcall %} +""", dict(value=value)).assert_failure() + + +@pytest.mark.parametrize('macros', PERMUTATIONS) +def test_node_template_node_filter_capability_syntax_unsupported(parser, macros): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +topology_template: + node_templates: + my_node: + type: MyType1 +{%- call node_filter() %} +capabilities: + - my_capability: + unsupported: {} +{% endcall %} +""").assert_failure() + + +@pytest.mark.parametrize('macros', PERMUTATIONS) +def test_node_template_node_filter_capability_syntax_empty(parser, macros): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +topology_template: + node_templates: + my_node: + type: MyType1 +{%- call node_filter() %} +capabilities: + - my_capability: {} +{% endcall %} +""").assert_success() + + +# Capability properties section + +@pytest.mark.parametrize('macros,value', matrix(PERMUTATIONS, data.NOT_A_LIST)) +def test_node_template_node_filter_capability_properties_section_syntax_type(parser, macros, value): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +topology_template: + node_templates: + my_node: + type: MyType1 +{%- call node_filter() %} +capabilities: + - my_capability: + properties: {{ value }} +{% endcall %} +""", dict(value=value)).assert_failure() + + +@pytest.mark.parametrize('macros', PERMUTATIONS) +def test_node_template_node_filter_capability_properties_section_syntax_empty(parser, macros): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +topology_template: + node_templates: + my_node: + type: MyType1 +{%- call node_filter() %} +capabilities: + - my_capability: + properties: [] +{% endcall %} +""").assert_success() + + +# Unicode + +def test_node_template_node_filter_unicode(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +capability_types: + é¡å: {} +node_types: + é¡åä¸: + requirements: + - éæ±: + capability: é¡å + é¡åäº: + properties: + 屬æ§: + type: string + capabilities: + è½å: é¡å +topology_template: + node_templates: + 模æ¿: + type: é¡åä¸ + node_filter: + properties: + - 屬æ§: { equal: å¼ } + capabilities: + - my_capability: + properties: + - 屬æ§: { equal: å¼ } + requirements: + - éæ±: + node: é¡åäº + node_filter: + properties: + - 屬æ§: { equal: å¼ } + capabilities: + - è½å: + properties: + - 屬æ§: { equal: å¼ } +""").assert_success() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/b89fdde2/tests/extensions/aria_extension_tosca/simple_v1_0/templates/node_template/test_node_template_requirements.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/templates/node_template/test_node_template_requirements.py b/tests/extensions/aria_extension_tosca/simple_v1_0/templates/node_template/test_node_template_requirements.py new file mode 100644 index 0000000..fdf6f16 --- /dev/null +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/templates/node_template/test_node_template_requirements.py @@ -0,0 +1,853 @@ +# -*- 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 + + +# Section + +@pytest.mark.parametrize('value', data.NOT_A_LIST) +def test_node_template_requirements_section_syntax_type(parser, value): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +node_types: + MyType: {} +topology_template: + node_templates: + my_node: + type: MyType + requirements: {{ value }} +""", dict(value=value)).assert_failure() + + +def test_node_template_requirements_section_syntax_empty(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +node_types: + MyType: {} +topology_template: + node_templates: + my_node: + type: MyType + requirements: [] +""").assert_success() + + +# Requirement + +@pytest.mark.parametrize('value', data.NOT_A_DICT_OR_STRING) +def test_node_template_requirement_syntax_type(parser, value): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +node_types: + MyType: {} +topology_template: + node_templates: + my_node: + type: MyType + requirements: + - my_requirement: {{ value }} +""", dict(value=value)).assert_failure() + + +def test_node_template_requirement_syntax_unsupported(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +capability_types: + MyType: {} +node_types: + MyType: + requirements: + - my_requirement: MyType +topology_template: + node_templates: + my_node: + type: MyType + requirements: + - my_requirement: + unsupported: {} +""").assert_failure() + + +def test_node_template_requirement_empty(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +capability_types: + MyType: {} +node_types: + MyType: + requirements: + - my_requirement: MyType +topology_template: + node_templates: + my_node: + type: MyType + requirements: + - my_requirement: {} +""").assert_success() + + +# Capability + +def test_node_template_requirement_capability_unknown(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +capability_types: + MyType: {} +node_types: + MyType: + requirements: + - my_requirement: MyType +topology_template: + node_templates: + my_node: + type: MyType + requirements: + - my_requirement: + capability: unknown # neither a type nor a name +""").assert_failure() + + +# Capability type + +def test_node_template_requirement_capability_type_same(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +capability_types: + MyType: {} +node_types: + MyType: + requirements: + - my_requirement: MyType +topology_template: + node_templates: + my_node: + type: MyType + requirements: + - my_requirement: + capability: MyType +""").assert_success() + + +def test_node_template_requirement_capability_type_derived(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +capability_types: + MyType1: {} + MyType2: + derived_from: MyType1 +node_types: + MyType: + requirements: + - my_requirement: MyType1 +topology_template: + node_templates: + my_node: + type: MyType + requirements: + - my_requirement: + capability: MyType2 +""").assert_success() + + +def test_node_template_requirement_capability_type_not_derived(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +capability_types: + MyType1: + derived_from: MyType2 + MyType2: {} +node_types: + MyType: + requirements: + - my_requirement: MyType1 +topology_template: + node_templates: + my_node: + type: MyType + requirements: + - my_requirement: + capability: MyType2 +""").assert_failure() + + +def test_node_template_requirement_capability_type_short_form(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +capability_types: + MyType: {} +node_types: + MyType: + requirements: + - my_requirement: MyType +topology_template: + node_templates: + my_node: + type: MyType + requirements: + - my_requirement: MyType +""").assert_success() + + +# Capability definition name + +def test_node_template_requirement_capability_name(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +capability_types: + MyType: {} +node_types: + MyType1: + requirements: + - my_requirement: MyType + MyType2: + capabilities: + my_capability: MyType +topology_template: + node_templates: + my_node1: + type: MyType1 + requirements: + - my_requirement: + node: my_node2 + capability: my_capability + my_node2: + type: MyType2 +""").assert_success() + + +def test_node_template_requirement_capability_name_derived(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +capability_types: + MyType1: {} + MyType2: + derived_from: MyType1 +node_types: + MyType1: + requirements: + - my_requirement: MyType1 + MyType2: + capabilities: + my_capability: MyType2 +topology_template: + node_templates: + my_node1: + type: MyType1 + requirements: + - my_requirement: + node: my_node2 + capability: my_capability + my_node2: + type: MyType2 +""").assert_success() + + +def test_node_template_requirement_capability_name_not_derived(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +capability_types: + MyType1: {} + MyType2: {} +node_types: + MyType1: + requirements: + - my_requirement: MyType1 + MyType2: + capabilities: + my_capability: MyType2 +topology_template: + node_templates: + my_node1: + type: MyType1 + requirements: + - my_requirement: + node: my_node2 + capability: my_capability + my_node2: + type: MyType2 +""").assert_failure() + + +# Node + +def test_node_template_requirement_node_unknown(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +capability_types: + MyType: {} +node_types: + MyType: + requirements: + - my_requirement: MyType +topology_template: + node_templates: + my_node: + type: MyType + requirements: + - my_requirement: + node: unknown +""").assert_failure() + + +# Node type + +def test_node_template_requirement_node_type_undefined(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +capability_types: + MyType1: {} + MyType2: + derived_from: MyType1 +node_types: + MyType1: + requirements: + - my_requirement: MyType1 + MyType2: + capabilities: + my_capability: MyType2 +topology_template: + node_templates: + my_node: + type: MyType1 + requirements: + - my_requirement: + node: MyType2 +""").assert_success() + + +def test_node_template_requirement_node_type_same(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +capability_types: + MyType1: {} + MyType2: + derived_from: MyType1 +node_types: + MyType1: + requirements: + - my_requirement: + capability: MyType1 + node: MyType2 + MyType2: + capabilities: + my_capability: MyType2 +topology_template: + node_templates: + my_node: + type: MyType1 + requirements: + - my_requirement: + node: MyType2 +""").assert_success() + + +def test_node_template_requirement_node_type_derived(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +capability_types: + MyType1: {} + MyType2: + derived_from: MyType1 +node_types: + MyType1: + requirements: + - my_requirement: + capability: MyType1 + node: MyType2 + MyType2: + capabilities: + my_capability: MyType2 + MyType3: + derived_from: MyType2 +topology_template: + node_templates: + my_node: + type: MyType1 + requirements: + - my_requirement: + node: MyType3 +""").assert_success() + + +def test_node_template_requirement_node_type_not_derived(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +capability_types: + MyType1: {} + MyType2: + derived_from: MyType1 +node_types: + MyType1: + requirements: + - my_requirement: + capability: MyType1 + node: MyType2 + MyType2: + capabilities: + my_capability: MyType2 + MyType3: {} +topology_template: + node_templates: + my_node: + type: MyType1 + requirements: + - my_requirement: + node: MyType3 +""").assert_failure() + + +# Node template + +def test_node_template_requirement_node_template_undefined(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +capability_types: + MyType1: {} + MyType2: + derived_from: MyType1 +node_types: + MyType1: + requirements: + - my_requirement: MyType1 + MyType2: + capabilities: + my_capability: MyType2 +topology_template: + node_templates: + my_node1: + type: MyType1 + requirements: + - my_requirement: + node: my_node2 + my_node2: + type: MyType2 +""").assert_success() + + +def test_node_template_requirement_node_template_same(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +capability_types: + MyType1: {} + MyType2: + derived_from: MyType1 +node_types: + MyType1: + requirements: + - my_requirement: + capability: MyType1 + node: MyType2 + MyType2: + capabilities: + my_capability: MyType2 +topology_template: + node_templates: + my_node1: + type: MyType1 + requirements: + - my_requirement: + node: my_node2 + my_node2: + type: MyType2 +""").assert_success() + + +def test_node_template_requirement_node_template_derived(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +capability_types: + MyType1: {} + MyType2: + derived_from: MyType1 +node_types: + MyType1: + requirements: + - my_requirement: + capability: MyType1 + node: MyType2 + MyType2: + capabilities: + my_capability: MyType2 + MyType3: + derived_from: MyType2 +topology_template: + node_templates: + my_node1: + type: MyType1 + requirements: + - my_requirement: + node: my_node2 + my_node2: + type: MyType3 +""").assert_success() + + +def test_node_template_requirement_node_template_not_derived(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +capability_types: + MyType1: {} + MyType2: {} +node_types: + MyType1: + requirements: + - my_requirement: + capability: MyType1 + node: MyType2 + MyType2: + capabilities: + my_capability: MyType2 + MyType3: {} +topology_template: + node_templates: + my_node1: + type: MyType1 + requirements: + - my_requirement: + node: my_node2 + my_node2: + type: MyType3 +""").assert_failure() + + +# Relationship + +def test_node_template_requirement_relationship_syntax_unsupported(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +capability_types: + MyType: {} +relationship_types: + MyType: {} +node_types: + MyType: + requirements: + - my_requirement: + capability: MyType + relationship: MyType +topology_template: + node_templates: + my_node: + type: MyType + requirements: + - my_requirement: + capability: MyType + relationship: + type: MyType + unsupported: {} +""").assert_failure() + + +def test_node_template_requirement_relationship_syntax_empty(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +capability_types: + MyType: {} +relationship_types: + MyType: {} +node_types: + MyType: + requirements: + - my_requirement: + capability: MyType + relationship: MyType +topology_template: + node_templates: + my_node: + type: MyType + requirements: + - my_requirement: + capability: MyType + relationship: {} +""").assert_success() + + +def test_node_template_requirement_relationship_unknown(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +capability_types: + MyType: {} +relationship_types: + MyType: {} +node_types: + MyType: + requirements: + - my_requirement: + capability: MyType + relationship: MyType +topology_template: + node_templates: + my_node: + type: MyType + requirements: + - my_requirement: + capability: MyType + relationship: unknown +""").assert_failure() + + +# Relationship type + +def test_node_template_requirement_relationship_type_same(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +capability_types: + MyType: {} +relationship_types: + MyType: {} +node_types: + MyType: + requirements: + - my_requirement: + capability: MyType + relationship: MyType +topology_template: + node_templates: + my_node: + type: MyType + requirements: + - my_requirement: + capability: MyType + relationship: + type: MyType +""").assert_success() + + +def test_node_template_requirement_relationship_type_derived(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +capability_types: + MyType: {} +relationship_types: + MyType1: {} + MyType2: + derived_from: MyType1 +node_types: + MyType: + requirements: + - my_requirement: + capability: MyType + relationship: MyType1 +topology_template: + node_templates: + my_node: + type: MyType + requirements: + - my_requirement: + capability: MyType + relationship: + type: MyType2 +""").assert_success() + + +def test_node_template_requirement_relationship_type_not_derived(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +capability_types: + MyType: {} +relationship_types: + MyType1: + derived_from: MyType2 + MyType2: {} +node_types: + MyType: + requirements: + - my_requirement: + capability: MyType + relationship: MyType1 +topology_template: + node_templates: + my_node: + type: MyType + requirements: + - my_requirement: + capability: MyType + relationship: + type: MyType2 +""").assert_failure() + + +def test_node_template_requirement_relationship_type_short_form(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +capability_types: + MyType: {} +relationship_types: + MyType: {} +node_types: + MyType: + requirements: + - my_requirement: + capability: MyType + relationship: MyType +topology_template: + node_templates: + my_node: + type: MyType + requirements: + - my_requirement: + capability: MyType + relationship: MyType +""").assert_success() + + +# Relationship template + +def test_node_template_requirement_relationship_template_same(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +capability_types: + MyType: {} +relationship_types: + MyType: {} +node_types: + MyType: + requirements: + - my_requirement: + capability: MyType + relationship: MyType +topology_template: + relationship_templates: + my_relationship: + type: MyType + node_templates: + my_node: + type: MyType + requirements: + - my_requirement: + capability: MyType + relationship: + type: my_relationship +""").assert_success() + + +def test_node_template_requirement_relationship_template_derived(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +capability_types: + MyType: {} +relationship_types: + MyType1: {} + MyType2: + derived_from: MyType1 +node_types: + MyType: + requirements: + - my_requirement: + capability: MyType + relationship: MyType1 +topology_template: + relationship_templates: + my_relationship: + type: MyType2 + node_templates: + my_node: + type: MyType + requirements: + - my_requirement: + capability: MyType + relationship: + type: my_relationship +""").assert_success() + + +def test_node_template_requirement_relationship_template_not_derived(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +capability_types: + MyType: {} +relationship_types: + MyType1: + derived_from: MyType2 + MyType2: {} +node_types: + MyType: + requirements: + - my_requirement: + capability: MyType + relationship: MyType1 +topology_template: + relationship_templates: + my_relationship: + type: MyType2 + node_templates: + my_node: + type: MyType + requirements: + - my_requirement: + capability: MyType + relationship: + type: my_relationship +""").assert_failure() + + +def test_node_template_requirement_relationship_template_short_form(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +capability_types: + MyType: {} +relationship_types: + MyType: {} +node_types: + MyType: + requirements: + - my_requirement: + capability: MyType + relationship: MyType +topology_template: + relationship_templates: + my_relationship: + type: MyType + node_templates: + my_node: + type: MyType + requirements: + - my_requirement: + capability: MyType + relationship: my_relationship +""").assert_success() + + +# Unicode + +def test_node_template_requirement_unicode(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +capability_types: + é¡å: {} +relationship_types: + é¡å: {} +node_types: + é¡å: + requirements: + - éæ±: + capability: é¡å + relationship: é¡å +topology_template: + relationship_templates: + éä¿: + type: é¡å + node_templates: + ç¯é»: + type: é¡å + requirements: + - éæ±: + capability: é¡å + relationship: éä¿ +""").assert_success() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/b89fdde2/tests/extensions/aria_extension_tosca/simple_v1_0/templates/test_group.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/templates/test_group.py b/tests/extensions/aria_extension_tosca/simple_v1_0/templates/test_group.py new file mode 100644 index 0000000..cf7f54d --- /dev/null +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/templates/test_group.py @@ -0,0 +1,159 @@ +# -*- 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 + + +# Members + +@pytest.mark.parametrize('value', data.NOT_A_LIST) +def test_group_members_syntax_type(parser, value): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +group_types: + MyType: {} +topology_template: + groups: + my_group: + type: MyType + members: {{ value }} +""", dict(value=value)).assert_failure() + + +@pytest.mark.parametrize('value', data.NOT_A_STRING) +def test_group_members_syntax_element_type(parser, value): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +group_types: + MyType: {} +topology_template: + groups: + my_group: + type: MyType + members: [ {{ value }} ] +""", dict(value=value)).assert_failure() + + +def test_group_members_syntax_empty(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +group_types: + MyType: {} +topology_template: + groups: + my_group: + type: MyType + members: [] +""").assert_success() + + +def test_group_members(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +node_types: + MyType1: {} + MyType2: {} +group_types: + MyType: + members: [ MyType1, MyType2 ] +topology_template: + node_templates: + my_node1: + type: MyType1 + my_node2: + type: MyType2 + groups: + my_group: + type: MyType + members: [ my_node1, my_node2 ] +""").assert_success() + + +def test_group_members_derived(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +node_types: + MyType1: {} + MyType2: + derived_from: MyType1 +group_types: + MyType: + members: [ MyType1 ] +topology_template: + node_templates: + my_node: + type: MyType2 + groups: + my_group: + type: MyType + members: [ my_node ] +""").assert_success() + + +def test_group_members_not_derived(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +node_types: + MyType1: {} + MyType2: {} +group_types: + MyType: + members: [ MyType1 ] +topology_template: + node_templates: + my_node: + type: MyType2 + groups: + my_group: + type: MyType + members: [ my_node ] +""").assert_failure() + + +def test_group_members_unknown(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +group_types: + MyType: {} +topology_template: + groups: + my_group: + type: MyType + members: [ unknown ] +""").assert_failure() + + +# Unicode + +def test_group_unicode(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +node_types: + é¡å: {} +group_types: + é¡å: + members: [ é¡å ] +topology_template: + node_templates: + ç¯é»: + type: é¡å + groups: + æ¿ç: + type: é¡å + members: [ ç¯é» ] +""").assert_success() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/b89fdde2/tests/extensions/aria_extension_tosca/simple_v1_0/templates/test_policy.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/templates/test_policy.py b/tests/extensions/aria_extension_tosca/simple_v1_0/templates/test_policy.py new file mode 100644 index 0000000..4828583 --- /dev/null +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/templates/test_policy.py @@ -0,0 +1,272 @@ +# -*- 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 + + +# Targets + +@pytest.mark.parametrize('value', data.NOT_A_LIST) +def test_policy_targets_syntax_type(parser, value): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +policy_types: + MyType: {} +topology_template: + policies: + my_policy: + type: MyType + targets: {{ value }} +""", dict(value=value)).assert_failure() + + +@pytest.mark.parametrize('value', data.NOT_A_STRING) +def test_policy_targets_syntax_element_type(parser, value): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +policy_types: + MyType: {} +topology_template: + policies: + my_policy: + type: MyType + targets: [ {{ value }} ] +""", dict(value=value)).assert_failure() + + +def test_policy_targets_syntax_empty(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +policy_types: + MyType: {} +topology_template: + policies: + my_policy: + type: MyType + targets: [] +""").assert_success() + + +def test_policy_targets_nodes(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +node_types: + MyType1: {} + MyType2: {} +policy_types: + MyType: + targets: [ MyType1, MyType2 ] +topology_template: + node_templates: + my_node1: + type: MyType1 + my_node2: + type: MyType2 + policies: + my_policy: + type: MyType + targets: [ my_node1, my_node2 ] +""").assert_success() + + +def test_policy_targets_nodes_derived(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +node_types: + MyType1: {} + MyType2: + derived_from: MyType1 +policy_types: + MyType: + targets: [ MyType1 ] +topology_template: + node_templates: + my_node: + type: MyType2 + policies: + my_policy: + type: MyType + targets: [ my_node ] +""").assert_success() + + +def test_policy_targets_nodes_not_derived(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +node_types: + MyType1: + derived_from: MyType2 + MyType2: {} +policy_types: + MyType: + targets: [ MyType1 ] +topology_template: + node_templates: + my_node: + type: MyType2 + policies: + my_policy: + type: MyType + targets: [ my_node ] +""").assert_failure() + + +def test_policy_targets_groups(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +group_types: + MyType1: {} + MyType2: {} +policy_types: + MyType: + targets: [ MyType1, MyType2 ] +topology_template: + groups: + my_group1: + type: MyType1 + my_group2: + type: MyType2 + policies: + my_policy: + type: MyType + targets: [ my_group1, my_group2 ] +""").assert_success() + + +def test_policy_targets_groups_derived(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +group_types: + MyType1: {} + MyType2: + derived_from: MyType1 +policy_types: + MyType: + targets: [ MyType1 ] +topology_template: + groups: + my_group: + type: MyType2 + policies: + my_policy: + type: MyType + targets: [ my_group ] +""").assert_success() + + +def test_policy_targets_groups_not_derived(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 + MyType1: {} + MyType1: + derived_from: MyType2 + MyType2: {} +policy_types: + MyType: + targets: [ MyType1 ] +topology_template: + groups: + my_group: + type: MyType2 + policies: + my_policy: + type: MyType + targets: [ my_group ] +""").assert_failure() + + +def test_policy_targets_nodes_and_groups(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +node_types: + MyNodeType: {} +group_types: + MyGroupType: {} +policy_types: + MyType: + targets: [ MyNodeType, MyGroupType ] +topology_template: + node_templates: + my_node: + type: MyNodeType + groups: + my_group: + type: MyGroupType + policies: + my_policy: + type: MyType + targets: [ my_node, my_group ] +""").assert_success() + + +def test_policy_targets_ambiguous(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +node_types: + MyNodeType: {} +group_types: + MyGroupType: {} +policy_types: + MyType: + targets: [ MyNodeType, MyGroupType ] +topology_template: + node_templates: + my_template: + type: MyNodeType + groups: + my_template: + type: MyGroupType + policies: + my_policy: + type: MyType + targets: [ my_template ] +""").assert_success() + + +def test_policy_targets_unknown(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +policy_types: + MyType: {} +topology_template: + policies: + my_policy: + type: MyType + targets: [ unknown ] +""").assert_failure() + + +# Unicode + +def test_policy_unicode(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +node_types: + é¡å: {} +policy_types: + é¡å: + targets: [ é¡å ] +topology_template: + node_templates: + ç¯é»: + type: é¡å + policies: + æ¿ç: + type: é¡å + targets: [ ç¯é» ] +""").assert_success() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/b89fdde2/tests/extensions/aria_extension_tosca/simple_v1_0/templates/test_substitution_mappings.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/templates/test_substitution_mappings.py b/tests/extensions/aria_extension_tosca/simple_v1_0/templates/test_substitution_mappings.py new file mode 100644 index 0000000..8903b97 --- /dev/null +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/templates/test_substitution_mappings.py @@ -0,0 +1,449 @@ +# -*- 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 + + +@pytest.mark.parametrize('value', data.NOT_A_DICT) +def test_substitution_mappings_syntax_type(parser, value): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +topology_template: + substitution_mappings: {{ value }} +""", dict(value=value)).assert_failure() + + +def test_substitution_mappings_syntax_unsupported(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +node_types: + MyType: {} +topology_template: + substitution_mappings: + node_type: MyType + unsupported: {} +""").assert_failure() + + +def test_substitution_mappings_syntax_empty(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +topology_template: + substitution_mappings: {} # "node_type" is required +""").assert_failure() + + +# Node type + +def test_substitution_mappings_node_type_syntax_type(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +topology_template: + description: a description + substitution_mappings: + node_type: {{ value }} +""").assert_failure() + + +# Requirements section + +@pytest.mark.parametrize('value', data.NOT_A_DICT) +def test_substitution_mappings_requirements_section_syntax_type(parser, value): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +node_types: + MyType: {} +topology_template: + substitution_mappings: + node_type: MyType + requirements: {{ value }} +""", dict(value=value)).assert_failure() + + +def test_substitution_mappings_requirements_section_syntax_empty(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +node_types: + MyType: {} +topology_template: + substitution_mappings: + node_type: MyType + requirements: {} +""").assert_success() + + +# Requirement + +@pytest.mark.parametrize('value', data.NOT_A_LIST_OF_TWO) +def test_substitution_mappings_requirement_syntax_type(parser, value): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +capability_types: + MyType: {} +node_types: + MyType: + requirements: + - my_requirement: + capability: MyType +topology_template: + substitution_mappings: + node_type: MyType + requirements: + my_requirement: {{ value }} +""", dict(value=value)).assert_failure() + + +def test_substitution_mappings_requirement_same(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +capability_types: + MyType: {} +node_types: + MyType: + requirements: + - my_requirement: + capability: MyType + MyInternalType: + requirements: + - my_internal_requirement: + capability: MyType +topology_template: + node_templates: + my_template: + type: MyInternalType + substitution_mappings: + node_type: MyType + requirements: + my_requirement: [ my_template, my_internal_requirement ] +""").assert_success() + + +def test_substitution_mappings_requirement_derived(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +capability_types: + MyType1: {} + MyType2: + derived_from: MyType1 +node_types: + MyType: + requirements: + - my_requirement: + capability: MyType1 + MyInternalType: + requirements: + - my_internal_requirement: + capability: MyType2 +topology_template: + node_templates: + my_template: + type: MyInternalType + substitution_mappings: + node_type: MyType + requirements: + my_requirement: [ my_template, my_internal_requirement ] +""").assert_success() + + +def test_substitution_mappings_requirement_bad(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +capability_types: + MyType1: {} + MyType2: {} +node_types: + MyType: + requirements: + - my_requirement: + capability: MyType1 + MyInternalType: + requirements: + - my_internal_requirement: + capability: MyType2 +topology_template: + node_templates: + my_template: + type: MyInternalType + substitution_mappings: + node_type: MyType + requirements: + my_requirement: [ my_template, my_internal_requirement ] +""").assert_failure() + + +def test_substitution_mappings_requirement_unknown(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +capability_types: + MyType: {} +node_types: + MyType: + requirements: + - my_requirement: + capability: MyType + MyInternalType: + requirements: + - my_internal_requirement: + capability: MyType +topology_template: + node_templates: + my_template: + type: MyInternalType + substitution_mappings: + node_type: MyType + requirements: + unknown: [ my_template, my_internal_requirement ] +""").assert_failure() + + +def test_substitution_mappings_requirement_unknown_mapped_template(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +capability_types: + MyType: {} +node_types: + MyType: + requirements: + - my_requirement: + capability: MyType + MyInternalType: + requirements: + - my_internal_requirement: + capability: MyType +topology_template: + node_templates: + my_template: + type: MyInternalType + substitution_mappings: + node_type: MyType + requirements: + my_requirement: [ unknown, my_internal_requirement ] +""").assert_failure() + + +def test_substitution_mappings_requirement_unknown_mapped_requirement(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +capability_types: + MyType: {} +node_types: + MyType: + requirements: + - my_requirement: + capability: MyType + MyInternalType: + requirements: + - my_internal_requirement: + capability: MyType +topology_template: + node_templates: + my_template: + type: MyInternalType + substitution_mappings: + node_type: MyType + requirements: + my_requirement: [ my_template, unknown ] +""").assert_failure() + + +# Capabilities section + +@pytest.mark.parametrize('value', data.NOT_A_DICT) +def test_substitution_mappings_capabilities_section_syntax_type(parser, value): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +node_types: + MyType: {} +topology_template: + substitution_mappings: + node_type: MyType + capabilities: {{ value }} +""", dict(value=value)).assert_failure() + + +def test_substitution_mappings_capabilities_section_syntax_empty(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +node_types: + MyType: {} +topology_template: + substitution_mappings: + node_type: MyType + capabilities: {} +""").assert_success() + + +# Capability + +@pytest.mark.parametrize('value', data.NOT_A_LIST_OF_TWO) +def test_substitution_mappings_capability_syntax_type(parser, value): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +capability_types: + MyType: {} +node_types: + MyType: + capabilities: + my_capability: MyType +topology_template: + substitution_mappings: + node_type: MyType + capabilities: + my_capability: {{ value }} +""", dict(value=value)).assert_failure() + + +def test_substitution_mappings_capability_same(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +capability_types: + MyType: {} +node_types: + MyType: + capabilities: + my_capability: MyType + MyInternalType: + capabilities: + my_internal_capability: MyType +topology_template: + node_templates: + my_template: + type: MyInternalType + substitution_mappings: + node_type: MyType + capabilities: + my_capability: [ my_template, my_internal_capability ] +""").assert_success() + + +def test_substitution_mappings_capability_derived(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +capability_types: + MyType1: {} + MyType2: + derived_from: MyType1 +node_types: + MyType: + capabilities: + my_capability: MyType1 + MyInternalType: + capabilities: + my_internal_capability: MyType2 +topology_template: + node_templates: + my_template: + type: MyInternalType + substitution_mappings: + node_type: MyType + capabilities: + my_capability: [ my_template, my_internal_capability ] +""").assert_success() + + +def test_substitution_mappings_capability_bad(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +capability_types: + MyType1: {} + MyType2: {} +node_types: + MyType: + capabilities: + my_capability: MyType1 + MyInternalType: + capabilities: + my_internal_capability: MyType2 +topology_template: + node_templates: + my_template: + type: MyInternalType + substitution_mappings: + node_type: MyType + capabilities: + my_capability: [ my_template, my_internal_capability ] +""").assert_failure() + + +def test_substitution_mappings_capability_unknown(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +capability_types: + MyType: {} +node_types: + MyType: + capabilities: + my_capability: MyType + MyInternalType: + capabilities: + my_internal_capability: MyType +topology_template: + node_templates: + my_template: + type: MyInternalType + substitution_mappings: + node_type: MyType + capabilities: + unknown: [ my_template, my_internal_capability ] +""").assert_failure() + + +def test_substitution_mappings_capability_unknown_mapped_template(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +capability_types: + MyType: {} +node_types: + MyType: + capabilities: + my_capability: MyType + MyInternalType: + capabilities: + my_internal_capability: MyType +topology_template: + node_templates: + my_template: + type: MyInternalType + substitution_mappings: + node_type: MyType + capabilities: + my_capability: [ unknown, my_internal_capability ] +""").assert_failure() + + +def test_substitution_mappings_capability_unknown_mapped_capability(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +capability_types: + MyType: {} +node_types: + MyType: + capabilities: + my_capability: MyType + MyInternalType: + capabilities: + my_internal_capability: MyType +topology_template: + node_templates: + my_template: + type: MyInternalType + substitution_mappings: + node_type: MyType + capabilities: + my_capability: [ my_template, unknown ] +""").assert_failure() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/b89fdde2/tests/extensions/aria_extension_tosca/simple_v1_0/templates/test_topology_template.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/templates/test_topology_template.py b/tests/extensions/aria_extension_tosca/simple_v1_0/templates/test_topology_template.py new file mode 100644 index 0000000..ac86a4a --- /dev/null +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/templates/test_topology_template.py @@ -0,0 +1,61 @@ +# -*- 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 + + +@pytest.mark.parametrize('value', data.NOT_A_DICT) +def test_topology_template_syntax_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_syntax_unsupported(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +topology_template: + unsupported: {} +""").assert_failure() + + +def test_topology_template_syntax_empty(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +topology_template: {} +""").assert_success() + + +# Description + +@pytest.mark.parametrize('value', data.NOT_A_STRING) +def test_topology_template_description_syntax_type(parser, value): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +topology_template: + description: {{ value }} +""", dict(value=value)).assert_failure() + + +def test_topology_template_description(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +topology_template: + description: a description +""").assert_success() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/b89fdde2/tests/extensions/aria_extension_tosca/simple_v1_0/test_dsl_definitions.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/test_dsl_definitions.py b/tests/extensions/aria_extension_tosca/simple_v1_0/test_dsl_definitions.py new file mode 100644 index 0000000..3defb70 --- /dev/null +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/test_dsl_definitions.py @@ -0,0 +1,47 @@ +# -*- 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 + + +@pytest.mark.parametrize('value', data.PRIMITIVE_VALUES) +def test_dsl_definitions_syntax_anything(parser, value): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +dsl_definitions: {{ value }} +""", dict(value=value)).assert_success() + + +def test_dsl_definitions_anchor(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +dsl_definitions: + key: &ANCHOR + field: a value +""").assert_success() + + +# Unicode + +def test_dsl_definitions_unicode(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +dsl_definitions: + å®ç¾©: &ANCHOR # YAML does not allow the anchor name to be Unicode + é å: å¼ +""").assert_success() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/b89fdde2/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 new file mode 100644 index 0000000..07a0d9b --- /dev/null +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/test_imports.py @@ -0,0 +1,200 @@ +# -*- 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.web_server import WebServer + + +# Fixtures + +NODE_TYPE_IMPORT = """ +node_types: + MyNode: {} +""" + +NODE_TYPE_IMPORT_UNICODE = """ +node_types: + é¡å: {} +""" + +BAD_IMPORT = """ +node_types: + MyNode: + derived_from: UnknownType +""" + +@pytest.fixture(scope='session') +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_UNICODE) + repository.add_text_yaml('/imports/bad.yaml', BAD_IMPORT) + with repository: + yield repository.root + + +# Imports section + +@pytest.mark.parametrize('value', data.NOT_A_LIST) +def test_imports_section_syntax_type(parser, value): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +imports: {{ value }} +""", dict(value=value)).assert_failure() + + +def test_imports_section_syntax_empty(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +imports: [] +""").assert_success() + + +# Import + +@pytest.mark.parametrize('value', data.NOT_A_DICT_OR_STRING) +def test_import_syntax_type(parser, value): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +imports: + - {{ value }} +""", dict(value=value)).assert_failure() + + +def test_import_syntax_unsupported(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +imports: + - unsupported: {} +""").assert_failure() + + +def test_import_syntax_empty(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +imports: + - {} # "file" is required +""").assert_failure() + + +# File + +@pytest.mark.parametrize('value', data.NOT_A_DICT_OR_STRING) +def test_import_file_syntax_type(parser, value): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +imports: + - file: {{ value }} +""", dict(value=value)).assert_failure() + + +def test_import_file_short_form(parser, repository): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +imports: + - {{ repository }}/imports/node-type.yaml +topology_template: + node_templates: + my_node: + type: MyNode +""", dict(repository=repository)).assert_success() + + +def test_import_file(parser, repository): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +imports: + - file: {{ repository }}/imports/node-type.yaml +topology_template: + node_templates: + my_node: + type: MyNode +""", dict(repository=repository)).assert_success() + + +# Repository + +@pytest.mark.xfail(reason='not yet implemented') +def test_import_repository(parser, repository): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +repositories: + my_repository: + url: {{ repository }}/imports/ +imports: + - file: node-type.yaml + repository: my_repository +topology_template: + node_templates: + my_node: + type: MyNode +""", dict(repository=repository)).assert_success() + + +# Namespace + +@pytest.mark.xfail(reason='not yet implemented') +def test_import_namespace(parser, repository): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +imports: + - file: {{ repository }}/imports/node-type.yaml + namespace_uri: + namespace_prefix: my_namespace +topology_template: + node_templates: + my_node: + type: my_namespace.MyNode +""", dict(repository=repository)).assert_success() + + +# Bad imports + +def test_import_not_found(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +imports: + - does_not_exist +""").assert_failure() + + +def test_import_bad(parser, repository): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +imports: + - {{ repository }}/imports/bad.yaml +topology_template: + node_templates: + my_node: + type: MyNode +""", dict(repository=repository)).assert_failure() + + +# Unicode + +def test_import_unicode(parser, repository): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +imports: + - {{ repository }}/imports/ç¯é»é¡å.yaml +topology_template: + node_templates: + 模æ¿: + type: é¡å +""", dict(repository=repository)).assert_success() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/b89fdde2/tests/extensions/aria_extension_tosca/simple_v1_0/test_metadata.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/test_metadata.py b/tests/extensions/aria_extension_tosca/simple_v1_0/test_metadata.py new file mode 100644 index 0000000..f80c40b --- /dev/null +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/test_metadata.py @@ -0,0 +1,98 @@ +# -*- 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 + + +NORMATIVE_FIELD_NAMES = ('template_name', 'template_author', 'template_version') + + +# Metadata section + +@pytest.mark.parametrize('value', data.NOT_A_DICT) +def test_metadata_section_syntax_type(parser, value): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +metadata: {{ value }} +""", dict(value=value)).assert_failure() + + +def test_metadata_section_syntax_empty(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +metadata: {} +""").assert_success() + + +# Fields + +@pytest.mark.parametrize('field,value', matrix( + NORMATIVE_FIELD_NAMES, + data.NOT_A_STRING +)) +def test_metadata_normative_fields_syntax_type(parser, field, value): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +metadata: + {{ field }}: {{ value }} +""", dict(field=field, value=value)).assert_failure() + + +@pytest.mark.parametrize('value', data.NOT_A_STRING) +def test_metadata_non_normative_fields_syntax_type(parser, value): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +metadata: + non_normative: {{ value }} +""", dict(value=value)).assert_failure() + + +# Template version + +@pytest.mark.parametrize('value', data.GOOD_VERSIONS) +def test_metadata_normative_template_version(parser, value): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +metadata: + template_version: {{ value }} +""", dict(value=value)).assert_success() + + +@pytest.mark.parametrize('value', data.BAD_VERSIONS) +def test_metadata_normative_template_bad_version(parser, value): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +metadata: + template_version: {{ value }} +""", dict(value=value)).assert_failure() + + +# Unicode + +def test_metadata_unicode(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +metadata: + template_name: è© å調 + template_author: è© å調 + template_version: 1.0.0.è© å調-10 + non_normative1: è© åèª¿ä¸ + non_normative2: è© åèª¿äº + non_normative3: è© åèª¿ä¸ +""").assert_success()