Consolidate tests using Jinja templates
Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/1d8ac549 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/1d8ac549 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/1d8ac549 Branch: refs/heads/ARIA-1-parser-test-suite Commit: 1d8ac549b81f4d464169b37e54c61eb6c6626ba3 Parents: a136c92 Author: Tal Liron <[email protected]> Authored: Tue Sep 19 16:29:25 2017 -0500 Committer: Tal Liron <[email protected]> Committed: Tue Sep 19 16:29:25 2017 -0500 ---------------------------------------------------------------------- .travis.yml | 6 +- .../aria_extension_tosca/simple_v1_0/data.py | 35 +- .../simple_v1_0/templates/common/__init__.py | 14 + .../templates/common/test_template_interface.py | 598 +++++++++++++++ .../common/test_template_parameters.py | 440 +++++++++++ .../templates/common/test_templates.py | 92 +++ .../templates/test_template_interface.py | 598 --------------- .../templates/test_template_parameters.py | 423 ----------- .../simple_v1_0/templates/test_templates.py | 102 --- .../types/common/test_type_interfaces.py | 507 +++++-------- .../types/common/test_type_parameters.py | 752 +++++++++++++------ .../simple_v1_0/types/common/test_types.py | 73 +- .../node_types/test_node_type_capabilities.py | 206 +---- .../test_node_type_relationship_interfaces.py | 582 +------------- .../node_types/test_node_type_requirements.py | 125 ++- .../simple_v1_0/types/test_interface_type.py | 176 +---- 16 files changed, 2078 insertions(+), 2651 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1d8ac549/.travis.yml ---------------------------------------------------------------------- diff --git a/.travis.yml b/.travis.yml index ce0d462..f046af8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,7 +18,7 @@ sudo: true language: python -# We need this only for "sudo: false" +# We need this only if "sudo: false" #addons: # apt: # sources: @@ -55,9 +55,9 @@ env: before_install: # Ubuntu 14.04 (trusty) does not come with Python 2.6, so we will install it from Felix Krull's - # PPA + # PPA (won't work if "sudo: false") - if [[ $TOX_ENV = py26* ]]; then - sudo add-apt-repository ppa:fkrull/deadsnakes -y; + sudo add-apt-repository --yes ppa:fkrull/deadsnakes; sudo apt-get --quiet update; sudo apt-get --yes install python2.6 python2.6-dev; fi http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1d8ac549/tests/extensions/aria_extension_tosca/simple_v1_0/data.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/data.py b/tests/extensions/aria_extension_tosca/simple_v1_0/data.py index 76205eb..7693132 100644 --- a/tests/extensions/aria_extension_tosca/simple_v1_0/data.py +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/data.py @@ -48,29 +48,6 @@ TEMPLATE_PARAMETER_SECTIONS = ( ('relationship', 'attributes'), ('policy', 'properties') ) -PARAMETER_SECTIONS = ( - ('artifact', 'properties'), - ('data', 'properties'), - ('capability', 'properties'), - ('capability', 'attributes'), - ('interface', 'inputs'), - ('relationship', 'properties'), - ('relationship', 'attributes'), - ('node', 'properties'), - ('node', 'attributes'), - ('group', 'properties'), - ('policy', 'properties') -) -PARAMETER_WITH_CONSTRAINTS_SECTIONS = ( - ('artifact', 'properties'), - ('data', 'properties'), - ('capability', 'properties'), - ('interface', 'inputs'), - ('relationship', 'properties'), - ('node', 'properties'), - ('group', 'properties'), - ('policy', 'properties') -) CONSTRAINTS_WITH_VALUE = ('equal', 'greater_than', 'greater_or_equal', 'less_than', 'less_or_equal') CONSTRAINTS_WITH_VALUE_LIST = ('valid_values',) CONSTRAINTS_WITH_VALUE_RANGE = ('in_range',) @@ -78,17 +55,19 @@ CONSTRAINTS_WITH_NON_NEGATIVE_INT = ('length', 'min_length', 'max_length') # Values -NOT_A_DICT = ('null', 'a string', '123', '0.123', '[]') -NOT_A_DICT_OR_STRING = ('null', '123', '0.123', '[]') -NOT_A_LIST = ('null', 'a string', '123', '0.123', '{}') -NOT_A_STRING = ('null', '123', '0.123', '[]', '{}') +NOT_A_DICT = ('null', 'true', 'a string', '123', '0.123', '[]') +NOT_A_DICT_OR_STRING = ('null', 'true', '123', '0.123', '[]') +NOT_A_LIST = ('null', 'true', 'a string', '123', '0.123', '{}') +NOT_A_STRING = ('null', 'true', '123', '0.123', '[]', '{}') +NOT_A_BOOL = ('null', '123', '0.123', '[]', '{}') NOT_A_RANGE = NOT_A_LIST + ( '[]', '[ 1 ]', '[ 1, 2, 3 ]', '[ 1, 1 ]', '[ 2, 1 ]', '[ 1, a string ]', '[ a string, 1 ]', '[ 1.5, 2 ]', '[ 1, 2.5 ]' ) -NOT_OCCURRENCES = NOT_A_RANGE + ('[ -1, 1 ]',) +OCCURRENCES = ('[ 0, 1 ]', '[ 10, UNBOUNDED ]') +BAD_OCCURRENCES = NOT_A_RANGE + ('[ -1, 1 ]', '[ 0, unbounded ]') GOOD_VERSIONS = ("'6.1'", '2.0.1', '3.1.0.beta', "'1.0.0.alpha-10'") BAD_VERSIONS = ('a_string', '1.2.3.4.5', '1.2.beta', '1.0.0.alpha-x') STATUSES = ('supported', 'unsupported', 'experimental', 'deprecated') http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1d8ac549/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/1d8ac549/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..ba55fc8 --- /dev/null +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/templates/common/test_template_interface.py @@ -0,0 +1,598 @@ +# -*- coding: utf-8 -*- +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import itertools + +import pytest + +from ... import data + + +# Syntax + [email protected]('name,value', itertools.product( + data.TEMPLATE_WITH_INTERFACE_NAMES, + data.NOT_A_DICT +)) +def test_template_interfaces_wrong_yaml_type(parser, name, value): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +interface_types: + MyType: {} +{{ name }}_types: + MyType: {} +topology_template: + {{ section }}: + my_template: + type: MyType + interfaces: {{ value }} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], value=value)).assert_failure() + + [email protected]('name', data.TEMPLATE_WITH_INTERFACE_NAMES) +def test_template_interfaces_empty(parser, name): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +interface_types: + MyType: {} +{{ name }}_types: + MyType: {} +topology_template: + {{ section }}: + my_template: + type: MyType + interfaces: {} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name])).assert_success() + + [email protected]('name,value', itertools.product( + data.TEMPLATE_WITH_INTERFACE_NAMES, + data.NOT_A_DICT +)) +def test_template_interface_wrong_yaml_type(parser, name, value): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +interface_types: + MyType: {} +{{ name }}_types: + MyType: + interfaces: + MyInterface: + type: MyType +topology_template: + {{ section }}: + my_template: + type: MyType + interfaces: + MyInterface: {{ value }} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], value=value)).assert_failure() + + [email protected]('name', data.TEMPLATE_WITH_INTERFACE_NAMES) +def test_template_interface_empty(parser, name): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +interface_types: + MyType: {} +{{ name }}_types: + MyType: + interfaces: + MyInterface: + type: MyType +topology_template: + {{ section }}: + my_template: + type: MyType + interfaces: + MyInterface: {} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name])).assert_success() + + [email protected]('name,value', itertools.product( + data.TEMPLATE_WITH_INTERFACE_NAMES, + data.NOT_A_DICT +)) +def test_template_interface_inputs_wrong_yaml_type(parser, name, value): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +interface_types: + MyType: {} +{{ name }}_types: + MyType: + interfaces: + MyInterface: + type: MyType +topology_template: + {{ section }}: + my_template: + type: MyType + interfaces: + MyInterface: + inputs: {{ value }} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], value=value)).assert_failure() + + [email protected]('name', data.TEMPLATE_WITH_INTERFACE_NAMES) +def test_template_interface_inputs_empty(parser, name): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +interface_types: + MyType: {} +{{ name }}_types: + MyType: + interfaces: + MyInterface: + type: MyType +topology_template: + {{ section }}: + my_template: + type: MyType + interfaces: + MyInterface: + inputs: {} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name])).assert_success() + + [email protected]('name,value', itertools.product( + data.TEMPLATE_WITH_INTERFACE_NAMES, + data.NOT_A_DICT_OR_STRING +)) +def test_template_interface_operation_wrong_yaml_type(parser, name, value): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +interface_types: + MyType: {} +{{ name }}_types: + MyType: + interfaces: + MyInterface: + type: MyType + my_operation: {} +topology_template: + {{ section }}: + my_template: + type: MyType + interfaces: + MyInterface: + my_operation: {{ value }} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], value=value)).assert_failure() + + [email protected]('name', data.TEMPLATE_WITH_INTERFACE_NAMES) +def test_template_interface_operation_empty(parser, name): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +interface_types: + MyType: {} +{{ name }}_types: + MyType: + interfaces: + MyInterface: + type: MyType + my_operation: {} +topology_template: + {{ section }}: + my_template: + type: MyType + interfaces: + MyInterface: + my_operation: {} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name])).assert_success() + + [email protected]('name,value', itertools.product( + data.TEMPLATE_WITH_INTERFACE_NAMES, + data.NOT_A_DICT_OR_STRING +)) +def test_template_interface_operation_implementation_wrong_yaml_type(parser, name, value): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +interface_types: + MyType: {} +{{ name }}_types: + MyType: + interfaces: + MyInterface: + type: MyType + my_operation: {} +topology_template: + {{ section }}: + my_template: + type: MyType + interfaces: + MyInterface: + my_operation: + implementation: {{ value }} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], value=value)).assert_failure() + + [email protected]('name', data.TEMPLATE_WITH_INTERFACE_NAMES) +def test_template_interface_operation_implementation_unsupported_field(parser, name): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +interface_types: + MyType: {} +{{ name }}_types: + MyType: + interfaces: + MyInterface: + type: MyType + my_operation: {} +topology_template: + {{ section }}: + my_template: + type: MyType + interfaces: + MyInterface: + my_operation: + implementation: + unsupported: {} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name])).assert_failure() + + [email protected]('name,value', itertools.product( + data.TEMPLATE_WITH_INTERFACE_NAMES, + data.NOT_A_STRING +)) +def test_template_interface_operation_implementation_primary_wrong_yaml_type(parser, name, value): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +interface_types: + MyType: {} +{{ name }}_types: + MyType: + interfaces: + MyInterface: + type: MyType + my_operation: {} +topology_template: + {{ section }}: + my_template: + type: MyType + interfaces: + MyInterface: + my_operation: + implementation: + primary: {{ value }} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], value=value)).assert_failure() + + [email protected]('name,value', itertools.product( + data.TEMPLATE_WITH_INTERFACE_NAMES, + data.NOT_A_STRING +)) +def test_template_interface_operation_implementation_dependencies_wrong_yaml_type(parser, name, + value): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +interface_types: + MyType: {} +{{ name }}_types: + MyType: + interfaces: + MyInterface: + type: MyType + my_operation: {} +topology_template: + {{ section }}: + my_template: + type: MyType + interfaces: + MyInterface: + my_operation: + implementation: + dependencies: + - {{ value }} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], value=value)).assert_failure() + + +# Operations + [email protected]('name', data.TEMPLATE_WITH_INTERFACE_NAMES) +def test_template_interface_operation_from_type(parser, name): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +interface_types: + MyType: {} +{{ name }}_types: + MyType: + interfaces: + MyInterface: + type: MyType + my_operation: {} +topology_template: + {{ section }}: + my_template: + type: MyType + interfaces: + MyInterface: + my_operation: {} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name])).assert_success() + + [email protected]('name', data.TEMPLATE_WITH_INTERFACE_NAMES) +def test_template_interface_operation_from_interface_type(parser, name): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +interface_types: + MyType: + my_operation: {} +{{ name }}_types: + MyType: + interfaces: + MyInterface: + type: MyType +topology_template: + {{ section }}: + my_template: + type: MyType + interfaces: + MyInterface: + my_operation: {} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name])).assert_success() + + [email protected]('name', data.TEMPLATE_WITH_INTERFACE_NAMES) +def test_template_interface_operation_missing(parser, name): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +interface_types: + MyType: {} +{{ name }}_types: + MyType: + interfaces: + MyInterface: + type: MyType +topology_template: + {{ section }}: + my_template: + type: MyType + interfaces: + MyInterface: + my_operation: {} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name])).assert_failure() + + +# Interface inputs + [email protected]( + 'name,type_name,value', + ((s, v[0], v[1]) + for s, v in itertools.product( + data.TEMPLATE_WITH_INTERFACE_NAMES, + data.PARAMETER_VALUES)) +) +def test_template_interface_input_from_type(parser, name, type_name, value): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +data_types: + MyType: + properties: + my_field: + type: string +interface_types: + MyType: {} +{{ name }}_types: + MyType: + interfaces: + MyInterface: + type: MyType + inputs: + my_input: + type: {{ type_name }} +topology_template: + {{ section }}: + my_template: + type: MyType + interfaces: + MyInterface: + inputs: + my_input: {{ value }} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], type_name=type_name, + value=value)).assert_success() + + [email protected]( + 'name,type_name,value', + ((s, v[0], v[1]) + for s, v in itertools.product( + data.TEMPLATE_WITH_INTERFACE_NAMES, + data.PARAMETER_VALUES)) +) +def test_template_interface_input_from_interface_type(parser, name, type_name, value): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +data_types: + MyType: + properties: + my_field: + type: string +interface_types: + MyType: + inputs: + my_input: + type: {{ type_name }} +{{ name }}_types: + MyType: + interfaces: + MyInterface: + type: MyType +topology_template: + {{ section }}: + my_template: + type: MyType + interfaces: + MyInterface: + inputs: + my_input: {{ value }} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], type_name=type_name, + value=value)).assert_success() + + [email protected]('name', data.TEMPLATE_WITH_INTERFACE_NAMES) +def test_template_interface_input_missing(parser, name): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +interface_types: + MyType: {} +{{ name }}_types: + MyType: + interfaces: + MyInterface: + type: MyType +topology_template: + {{ section }}: + my_template: + type: MyType + interfaces: + MyInterface: + inputs: + my_input: a value +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name])).assert_failure() + + +# Operation inputs + [email protected]( + 'name,type_name,value', + ((s, v[0], v[1]) + for s, v in itertools.product( + data.TEMPLATE_WITH_INTERFACE_NAMES, + data.PARAMETER_VALUES)) +) +def test_template_interface_operation_input_from_type(parser, name, type_name, value): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +data_types: + MyType: + properties: + my_field: + type: string +interface_types: + MyType: {} +{{ name }}_types: + MyType: + interfaces: + MyInterface: + type: MyType + my_operation: + inputs: + my_input: + type: {{ type_name }} +topology_template: + {{ section }}: + my_template: + type: MyType + interfaces: + MyInterface: + my_operation: + inputs: + my_input: {{ value }} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], type_name=type_name, + value=value)).assert_success() + + [email protected]( + 'name,type_name,value', + ((s, v[0], v[1]) + for s, v in itertools.product( + data.TEMPLATE_WITH_INTERFACE_NAMES, + data.PARAMETER_VALUES)) +) +def test_template_interface_operation_input_from_interface_type(parser, name, type_name, value): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +data_types: + MyType: + properties: + my_field: + type: string +interface_types: + MyType: + my_operation: + inputs: + my_input: + type: {{ type_name }} +{{ name }}_types: + MyType: + interfaces: + MyInterface: + type: MyType +topology_template: + {{ section }}: + my_template: + type: MyType + interfaces: + MyInterface: + my_operation: + inputs: + my_input: {{ value }} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], type_name=type_name, + value=value)).assert_success() + + [email protected](reason='fix') [email protected]('name', data.TEMPLATE_WITH_INTERFACE_NAMES) +def test_template_interface_operation_input_missing(parser, name): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +interface_types: + MyType: {} +{{ name }}_types: + MyType: + interfaces: + MyInterface: + type: MyType + my_operation: {} +topology_template: + {{ section }}: + my_template: + type: MyType + interfaces: + MyInterface: + my_operation: + inputs: + my_input: a value +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name])).assert_failure() + + +# Unicode + [email protected]('name', data.TEMPLATE_WITH_INTERFACE_NAMES) +def test_template_interface_unicode(parser, name): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +interface_types: + é¡å: {} +{{ name }}_types: + é¡å: + interfaces: + æ¥å£: + type: é¡å + æè¡: + inputs: + è¼¸å ¥: + type: string +topology_template: + {{ section }}: + 模æ¿: + type: é¡å + interfaces: + æ¥å£: + æè¡: + inputs: + è¼¸å ¥: å¼ +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name])).assert_success() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1d8ac549/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..009c608 --- /dev/null +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/templates/common/test_template_parameters.py @@ -0,0 +1,440 @@ +# -*- coding: utf-8 -*- +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import itertools + +import pytest + +from ... import data + + +# Syntax + [email protected]( + 'name,parameter_section,value', + ((s[0], s[1], v) + for s, v in itertools.product( + data.TEMPLATE_PARAMETER_SECTIONS, + data.NOT_A_DICT)) +) +def test_template_parameter_section_wrong_yaml_type(parser, name, parameter_section, value): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +{{ name }}_types: + MyType: {} +topology_template: + {{ section }}: + my_template: + type: MyType + {{ parameter_section }}: {{ value }} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], + parameter_section=parameter_section, value=value)).assert_failure() + + [email protected]('name,parameter_section', data.TEMPLATE_PARAMETER_SECTIONS) +def test_template_parameter_section_empty(parser, name, parameter_section): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +{{ name }}_types: + MyType: {} +topology_template: + {{ section }}: + my_template: + type: MyType + {{ parameter_section }}: {} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], + parameter_section=parameter_section)).assert_success() + + [email protected]('name,parameter_section', data.TEMPLATE_PARAMETER_SECTIONS) +def test_template_parameter_unsupported_field(parser, name, parameter_section): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +{{ name }}_types: + MyType: {} +topology_template: + {{ section }}: + my_template: + type: MyType + {{ parameter_section }}: + my_parameter: + unsupported +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], + parameter_section=parameter_section)).assert_failure() + + +# Type conformance + [email protected]('name,parameter_section', data.TEMPLATE_PARAMETER_SECTIONS) +def test_template_parameter_missing(parser, name, parameter_section): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +{{ name }}_types: + MyType: + {{ parameter_section }}: + my_parameter1: + type: string +topology_template: + {{ section }}: + my_template: + type: MyType + {{ parameter_section }}: + my_parameter2: a value +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], + parameter_section=parameter_section)).assert_failure() + + [email protected]('name,type_name', itertools.product( + data.TEMPLATE_NAMES, + data.PARAMETER_TYPE_NAMES +)) +def test_template_property_required(parser, name, type_name): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +data_types: + MyType: + properties: + my_field: + type: string +{{ name }}_types: + MyType: + properties: + my_property: + type: {{ type_name }} +topology_template: + {{ section }}: + my_template: + type: MyType +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], + type_name=type_name)).assert_failure() + + [email protected]('name,type_name', itertools.product( + data.TEMPLATE_NAMES, + data.PARAMETER_TYPE_NAMES +)) +def test_template_property_not_required(parser, name, type_name): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +data_types: + MyType: + properties: + my_field: + type: string +{{ name }}_types: + MyType: + properties: + my_property: + type: {{ type_name }} + required: false +topology_template: + {{ section }}: + my_template: + type: MyType +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], + type_name=type_name)).assert_success() + + [email protected]( + 'name,type_name,value', + ((s, v[0], v[1]) + for s, v in itertools.product( + data.TEMPLATE_NAMES, + data.PARAMETER_VALUES)) +) +def test_template_property_required_with_default(parser, name, type_name, value): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +data_types: + MyType: + properties: + my_field: + type: string +{{ name }}_types: + MyType: + properties: + my_property: + type: {{ type_name }} + default: {{ value }} +topology_template: + {{ section }}: + my_template: + type: MyType +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], type_name=type_name, + value=value)).assert_success() + + +# Entry schema + [email protected]( + 'name,parameter_section,values', + ((s[0], s[1], v) + for s, v in itertools.product( + data.TEMPLATE_PARAMETER_SECTIONS, + data.ENTRY_SCHEMA_VALUES)) +) +def test_template_parameter_map(parser, name, parameter_section, values): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +data_types: + MyType: + properties: + my_field: + type: string + default: default value +{{ name }}_types: + MyType: + {{ parameter_section }}: + my_parameter: + type: map + entry_schema: {{ values[0] }} +topology_template: + {{ section }}: + my_template: + type: MyType + {{ parameter_section }}: + my_parameter: + key1: {{ values[1] }} + key2: {{ values[2] }} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], parameter_section=parameter_section, + values=values)).assert_success() + + [email protected]( + 'name,parameter_section,values', + ((s[0], s[1], v) + for s, v in itertools.product( + data.TEMPLATE_PARAMETER_SECTIONS, + data.ENTRY_SCHEMA_VALUES_BAD)) +) +def test_template_parameter_map_bad(parser, name, parameter_section, values): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +data_types: + MyType: + properties: + my_field: + type: string + default: default value +{{ name }}_types: + MyType: + {{ parameter_section }}: + my_parameter: + type: map + entry_schema: {{ values[0] }} +topology_template: + {{ section }}: + my_template: + type: MyType + {{ parameter_section }}: + my_parameter: + key1: {{ values[1] }} + key2: {{ values[2] }} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], parameter_section=parameter_section, + values=values)).assert_failure() + + [email protected]('name,parameter_section', data.TEMPLATE_PARAMETER_SECTIONS) +def test_template_parameter_map_required_field(parser, name, parameter_section): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +data_types: + MyType: + properties: + my_field: + type: string +{{ name }}_types: + MyType: + {{ parameter_section }}: + my_parameter: + type: map + entry_schema: MyType +topology_template: + {{ section }}: + my_template: + type: MyType + {{ parameter_section }}: + my_parameter: + key: {my_field: a value} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], + parameter_section=parameter_section)).assert_success() + + [email protected]('name,parameter_section', data.TEMPLATE_PARAMETER_SECTIONS) +def test_template_parameter_map_required_field_bad(parser, name, parameter_section): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +data_types: + MyType: + properties: + my_field: + type: string +{{ name }}_types: + MyType: + {{ parameter_section }}: + my_parameter: + type: map + entry_schema: MyType +topology_template: + {{ section }}: + my_template: + type: MyType + {{ parameter_section }}: + my_parameter: + key: {} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], + parameter_section=parameter_section)).assert_failure() + + [email protected]( + 'name,parameter_section,values', + ((s[0], s[1], v) + for s, v in itertools.product( + data.TEMPLATE_PARAMETER_SECTIONS, + data.ENTRY_SCHEMA_VALUES)) +) +def test_template_parameter_list(parser, name, parameter_section, values): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +data_types: + MyType: + properties: + my_field: + type: string + default: default value +{{ name }}_types: + MyType: + {{ parameter_section }}: + my_parameter: + type: list + entry_schema: {{ values[0] }} +topology_template: + {{ section }}: + my_template: + type: MyType + {{ parameter_section }}: + my_parameter: + - {{ values[1] }} + - {{ values[2] }} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], parameter_section=parameter_section, + values=values)).assert_success() + + [email protected]( + 'name,parameter_section,values', + ((s[0], s[1], v) + for s, v in itertools.product( + data.TEMPLATE_PARAMETER_SECTIONS, + data.ENTRY_SCHEMA_VALUES_BAD)) +) +def test_template_parameter_list_bad(parser, name, parameter_section, values): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +data_types: + MyType: + properties: + my_field: + type: string + default: default value +{{ name }}_types: + MyType: + {{ parameter_section }}: + my_parameter: + type: list + entry_schema: {{ values[0] }} +topology_template: + {{ section }}: + my_template: + type: MyType + {{ parameter_section }}: + my_parameter: + - {{ values[1] }} + - {{ values[2] }} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], parameter_section=parameter_section, + values=values)).assert_failure() + + [email protected]('name,parameter_section', data.TEMPLATE_PARAMETER_SECTIONS) +def test_template_parameter_list_required_field(parser, name, parameter_section): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +data_types: + MyType: + properties: + my_field: + type: string +{{ name }}_types: + MyType: + {{ parameter_section }}: + my_parameter: + type: list + entry_schema: MyType +topology_template: + {{ section }}: + my_template: + type: MyType + {{ parameter_section }}: + my_parameter: + - {my_field: a value} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], + parameter_section=parameter_section)).assert_success() + + [email protected]('name,parameter_section', data.TEMPLATE_PARAMETER_SECTIONS) +def test_template_parameter_list_required_field_bad(parser, name, parameter_section): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +data_types: + MyType: + properties: + my_field: + type: string +{{ name }}_types: + MyType: + {{ parameter_section }}: + my_parameter: + type: list + entry_schema: MyType +topology_template: + {{ section }}: + my_template: + type: MyType + {{ parameter_section }}: + my_parameter: + - {} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], + parameter_section=parameter_section)).assert_failure() + + +# Unicode + [email protected]('name,parameter_section', data.TEMPLATE_PARAMETER_SECTIONS) +def test_template_parameter_unicode(parser, name, parameter_section): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +{{ name }}_types: + é¡å: + {{ parameter_section }}: + 忏: + type: string +topology_template: + {{ section }}: + 模æ¿: + type: é¡å + {{ parameter_section }}: + 忏: å¼ +""", 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/1d8ac549/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..ef2ffcf --- /dev/null +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/templates/common/test_templates.py @@ -0,0 +1,92 @@ +# -*- coding: utf-8 -*- +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import itertools + +import pytest + +from ... import data + + +# Syntax + [email protected]('name', data.TEMPLATE_NAMES) +def test_template_unsupported_field(parser, name): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +topology_template: + {{ section }}: + my_template: + unsupported: {} +""", dict(section=data.TEMPLATE_NAME_SECTIONS[name])).assert_failure() + + +# Description + [email protected]('name,value', itertools.product( + data.TEMPLATE_NAMES, + data.NOT_A_STRING +)) +def test_template_description_wrong_yaml_type(parser, name, value): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +topology_template: + {{ section }}: + my_template: + description: {{ value }} +""", dict(section=data.TEMPLATE_NAME_SECTIONS[name], value=value)).assert_failure() + + +# Type + [email protected]('name,value', itertools.product( + data.TEMPLATE_NAMES, + data.NOT_A_STRING +)) +def test_template_type_wrong_yaml_type(parser, name, value): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +topology_template: + {{ section }}: + my_template: + type: {{ value }} +""", dict(section=data.TEMPLATE_NAME_SECTIONS[name], value=value)).assert_failure() + [email protected]('name', data.TEMPLATE_NAMES) +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 + [email protected]('name', data.TEMPLATE_NAMES) +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/1d8ac549/tests/extensions/aria_extension_tosca/simple_v1_0/templates/test_template_interface.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/templates/test_template_interface.py b/tests/extensions/aria_extension_tosca/simple_v1_0/templates/test_template_interface.py deleted file mode 100644 index 710d802..0000000 --- a/tests/extensions/aria_extension_tosca/simple_v1_0/templates/test_template_interface.py +++ /dev/null @@ -1,598 +0,0 @@ -# -*- coding: utf-8 -*- -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import itertools - -import pytest - -from .. import data - - -# Syntax - [email protected]('name,value', itertools.product( - data.TEMPLATE_WITH_INTERFACE_NAMES, - data.NOT_A_DICT -)) -def test_template_interfaces_wrong_yaml_type(parser, name, value): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -interface_types: - MyType: {} -{{ name }}_types: - MyType: {} -topology_template: - {{ section }}: - my_template: - type: MyType - interfaces: {{ value }} -""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], value=value)).assert_failure() - - [email protected]('name', data.TEMPLATE_WITH_INTERFACE_NAMES) -def test_template_interfaces_empty(parser, name): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -interface_types: - MyType: {} -{{ name }}_types: - MyType: {} -topology_template: - {{ section }}: - my_template: - type: MyType - interfaces: {} -""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name])).assert_success() - - [email protected]('name,value', itertools.product( - data.TEMPLATE_WITH_INTERFACE_NAMES, - data.NOT_A_DICT -)) -def test_template_interface_wrong_yaml_type(parser, name, value): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -interface_types: - MyType: {} -{{ name }}_types: - MyType: - interfaces: - MyInterface: - type: MyType -topology_template: - {{ section }}: - my_template: - type: MyType - interfaces: - MyInterface: {{ value }} -""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], value=value)).assert_failure() - - [email protected]('name', data.TEMPLATE_WITH_INTERFACE_NAMES) -def test_template_interface_empty(parser, name): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -interface_types: - MyType: {} -{{ name }}_types: - MyType: - interfaces: - MyInterface: - type: MyType -topology_template: - {{ section }}: - my_template: - type: MyType - interfaces: - MyInterface: {} -""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name])).assert_success() - - [email protected]('name,value', itertools.product( - data.TEMPLATE_WITH_INTERFACE_NAMES, - data.NOT_A_DICT -)) -def test_template_interface_inputs_wrong_yaml_type(parser, name, value): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -interface_types: - MyType: {} -{{ name }}_types: - MyType: - interfaces: - MyInterface: - type: MyType -topology_template: - {{ section }}: - my_template: - type: MyType - interfaces: - MyInterface: - inputs: {{ value }} -""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], value=value)).assert_failure() - - [email protected]('name', data.TEMPLATE_WITH_INTERFACE_NAMES) -def test_template_interface_inputs_empty(parser, name): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -interface_types: - MyType: {} -{{ name }}_types: - MyType: - interfaces: - MyInterface: - type: MyType -topology_template: - {{ section }}: - my_template: - type: MyType - interfaces: - MyInterface: - inputs: {} -""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name])).assert_success() - - [email protected]('name,value', itertools.product( - data.TEMPLATE_WITH_INTERFACE_NAMES, - data.NOT_A_DICT_OR_STRING -)) -def test_template_interface_operation_wrong_yaml_type(parser, name, value): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -interface_types: - MyType: {} -{{ name }}_types: - MyType: - interfaces: - MyInterface: - type: MyType - my_operation: {} -topology_template: - {{ section }}: - my_template: - type: MyType - interfaces: - MyInterface: - my_operation: {{ value }} -""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], value=value)).assert_failure() - - [email protected]('name', data.TEMPLATE_WITH_INTERFACE_NAMES) -def test_template_interface_operation_empty(parser, name): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -interface_types: - MyType: {} -{{ name }}_types: - MyType: - interfaces: - MyInterface: - type: MyType - my_operation: {} -topology_template: - {{ section }}: - my_template: - type: MyType - interfaces: - MyInterface: - my_operation: {} -""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name])).assert_success() - - [email protected]('name,value', itertools.product( - data.TEMPLATE_WITH_INTERFACE_NAMES, - data.NOT_A_DICT_OR_STRING -)) -def test_template_interface_operation_implementation_wrong_yaml_type(parser, name, value): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -interface_types: - MyType: {} -{{ name }}_types: - MyType: - interfaces: - MyInterface: - type: MyType - my_operation: {} -topology_template: - {{ section }}: - my_template: - type: MyType - interfaces: - MyInterface: - my_operation: - implementation: {{ value }} -""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], value=value)).assert_failure() - - [email protected]('name', data.TEMPLATE_WITH_INTERFACE_NAMES) -def test_template_interface_operation_implementation_unsupported_field(parser, name): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -interface_types: - MyType: {} -{{ name }}_types: - MyType: - interfaces: - MyInterface: - type: MyType - my_operation: {} -topology_template: - {{ section }}: - my_template: - type: MyType - interfaces: - MyInterface: - my_operation: - implementation: - unsupported: {} -""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name])).assert_failure() - - [email protected]('name,value', itertools.product( - data.TEMPLATE_WITH_INTERFACE_NAMES, - data.NOT_A_STRING -)) -def test_template_interface_operation_implementation_primary_wrong_yaml_type(parser, name, value): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -interface_types: - MyType: {} -{{ name }}_types: - MyType: - interfaces: - MyInterface: - type: MyType - my_operation: {} -topology_template: - {{ section }}: - my_template: - type: MyType - interfaces: - MyInterface: - my_operation: - implementation: - primary: {{ value }} -""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], value=value)).assert_failure() - - [email protected]('name,value', itertools.product( - data.TEMPLATE_WITH_INTERFACE_NAMES, - data.NOT_A_STRING -)) -def test_template_interface_operation_implementation_dependencies_wrong_yaml_type(parser, name, - value): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -interface_types: - MyType: {} -{{ name }}_types: - MyType: - interfaces: - MyInterface: - type: MyType - my_operation: {} -topology_template: - {{ section }}: - my_template: - type: MyType - interfaces: - MyInterface: - my_operation: - implementation: - dependencies: - - {{ value }} -""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], value=value)).assert_failure() - - -# Operations - [email protected]('name', data.TEMPLATE_WITH_INTERFACE_NAMES) -def test_template_interface_operation_from_type(parser, name): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -interface_types: - MyType: {} -{{ name }}_types: - MyType: - interfaces: - MyInterface: - type: MyType - my_operation: {} -topology_template: - {{ section }}: - my_template: - type: MyType - interfaces: - MyInterface: - my_operation: {} -""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name])).assert_success() - - [email protected]('name', data.TEMPLATE_WITH_INTERFACE_NAMES) -def test_template_interface_operation_from_interface_type(parser, name): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -interface_types: - MyType: - my_operation: {} -{{ name }}_types: - MyType: - interfaces: - MyInterface: - type: MyType -topology_template: - {{ section }}: - my_template: - type: MyType - interfaces: - MyInterface: - my_operation: {} -""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name])).assert_success() - - [email protected]('name', data.TEMPLATE_WITH_INTERFACE_NAMES) -def test_template_interface_operation_missing(parser, name): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -interface_types: - MyType: {} -{{ name }}_types: - MyType: - interfaces: - MyInterface: - type: MyType -topology_template: - {{ section }}: - my_template: - type: MyType - interfaces: - MyInterface: - my_operation: {} -""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name])).assert_failure() - - -# Interface inputs - [email protected]( - 'name,type_name,value', - ((s, v[0], v[1]) - for s, v in itertools.product( - data.TEMPLATE_WITH_INTERFACE_NAMES, - data.PARAMETER_VALUES)) -) -def test_template_interface_input_from_type(parser, name, type_name, value): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -data_types: - MyType: - properties: - my_field: - type: string -interface_types: - MyType: {} -{{ name }}_types: - MyType: - interfaces: - MyInterface: - type: MyType - inputs: - my_input: - type: {{ type_name }} -topology_template: - {{ section }}: - my_template: - type: MyType - interfaces: - MyInterface: - inputs: - my_input: {{ value }} -""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], type_name=type_name, - value=value)).assert_success() - - [email protected]( - 'name,type_name,value', - ((s, v[0], v[1]) - for s, v in itertools.product( - data.TEMPLATE_WITH_INTERFACE_NAMES, - data.PARAMETER_VALUES)) -) -def test_template_interface_input_from_interface_type(parser, name, type_name, value): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -data_types: - MyType: - properties: - my_field: - type: string -interface_types: - MyType: - inputs: - my_input: - type: {{ type_name }} -{{ name }}_types: - MyType: - interfaces: - MyInterface: - type: MyType -topology_template: - {{ section }}: - my_template: - type: MyType - interfaces: - MyInterface: - inputs: - my_input: {{ value }} -""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], type_name=type_name, - value=value)).assert_success() - - [email protected]('name', data.TEMPLATE_WITH_INTERFACE_NAMES) -def test_template_interface_input_missing(parser, name): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -interface_types: - MyType: {} -{{ name }}_types: - MyType: - interfaces: - MyInterface: - type: MyType -topology_template: - {{ section }}: - my_template: - type: MyType - interfaces: - MyInterface: - inputs: - my_input: a value -""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name])).assert_failure() - - -# Operation inputs - [email protected]( - 'name,type_name,value', - ((s, v[0], v[1]) - for s, v in itertools.product( - data.TEMPLATE_WITH_INTERFACE_NAMES, - data.PARAMETER_VALUES)) -) -def test_template_interface_operation_input_from_type(parser, name, type_name, value): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -data_types: - MyType: - properties: - my_field: - type: string -interface_types: - MyType: {} -{{ name }}_types: - MyType: - interfaces: - MyInterface: - type: MyType - my_operation: - inputs: - my_input: - type: {{ type_name }} -topology_template: - {{ section }}: - my_template: - type: MyType - interfaces: - MyInterface: - my_operation: - inputs: - my_input: {{ value }} -""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], type_name=type_name, - value=value)).assert_success() - - [email protected]( - 'name,type_name,value', - ((s, v[0], v[1]) - for s, v in itertools.product( - data.TEMPLATE_WITH_INTERFACE_NAMES, - data.PARAMETER_VALUES)) -) -def test_template_interface_operation_input_from_interface_type(parser, name, type_name, value): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -data_types: - MyType: - properties: - my_field: - type: string -interface_types: - MyType: - my_operation: - inputs: - my_input: - type: {{ type_name }} -{{ name }}_types: - MyType: - interfaces: - MyInterface: - type: MyType -topology_template: - {{ section }}: - my_template: - type: MyType - interfaces: - MyInterface: - my_operation: - inputs: - my_input: {{ value }} -""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], type_name=type_name, - value=value)).assert_success() - - [email protected](reason='fix') [email protected]('name', data.TEMPLATE_WITH_INTERFACE_NAMES) -def test_template_interface_operation_input_missing(parser, name): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -interface_types: - MyType: {} -{{ name }}_types: - MyType: - interfaces: - MyInterface: - type: MyType - my_operation: {} -topology_template: - {{ section }}: - my_template: - type: MyType - interfaces: - MyInterface: - my_operation: - inputs: - my_input: a value -""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name])).assert_failure() - - -# Unicode - [email protected]('name', data.TEMPLATE_WITH_INTERFACE_NAMES) -def test_template_interface_unicode(parser, name): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -interface_types: - é¡å: {} -{{ name }}_types: - é¡å: - interfaces: - æ¥å£: - type: é¡å - æè¡: - inputs: - è¼¸å ¥: - type: string -topology_template: - {{ section }}: - 模æ¿: - type: é¡å - interfaces: - æ¥å£: - æè¡: - inputs: - è¼¸å ¥: å¼ -""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name])).assert_success() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1d8ac549/tests/extensions/aria_extension_tosca/simple_v1_0/templates/test_template_parameters.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/templates/test_template_parameters.py b/tests/extensions/aria_extension_tosca/simple_v1_0/templates/test_template_parameters.py deleted file mode 100644 index 913000f..0000000 --- a/tests/extensions/aria_extension_tosca/simple_v1_0/templates/test_template_parameters.py +++ /dev/null @@ -1,423 +0,0 @@ -# -*- coding: utf-8 -*- -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import itertools - -import pytest - -from .. import data - - -# Syntax - [email protected]( - 'name,parameter_section,value', - ((s[0], s[1], v) - for s, v in itertools.product( - data.TEMPLATE_PARAMETER_SECTIONS, - data.NOT_A_DICT)) -) -def test_template_parameters_wrong_yaml_type(parser, name, parameter_section, value): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -{{ name }}_types: - MyType: {} -topology_template: - {{ section }}: - my_template: - type: MyType - {{ parameter_section }}: {{ value }} -""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], - parameter_section=parameter_section, value=value)).assert_failure() - - [email protected]('name,parameter_section', data.TEMPLATE_PARAMETER_SECTIONS) -def test_template_parameters_empty(parser, name, parameter_section): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -{{ name }}_types: - MyType: {} -topology_template: - {{ section }}: - my_template: - type: MyType - {{ parameter_section }}: {} -""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], - parameter_section=parameter_section)).assert_success() - - -# Type conformance - [email protected]('name,parameter_section', data.TEMPLATE_PARAMETER_SECTIONS) -def test_template_parameter_missing(parser, name, parameter_section): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -{{ name }}_types: - MyType: - {{ parameter_section }}: - my_parameter1: - type: string -topology_template: - {{ section }}: - my_template: - type: MyType - {{ parameter_section }}: - my_parameter2: a value -""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], - parameter_section=parameter_section)).assert_failure() - - [email protected]('name,type_name', itertools.product( - data.TEMPLATE_NAMES, - data.PARAMETER_TYPE_NAMES -)) -def test_template_property_required(parser, name, type_name): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -data_types: - MyType: - properties: - my_field: - type: string -{{ name }}_types: - MyType: - properties: - my_property: - type: {{ type_name }} -topology_template: - {{ section }}: - my_template: - type: MyType -""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], - type_name=type_name)).assert_failure() - - [email protected]('name,type_name', itertools.product( - data.TEMPLATE_NAMES, - data.PARAMETER_TYPE_NAMES -)) -def test_template_property_not_required(parser, name, type_name): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -data_types: - MyType: - properties: - my_field: - type: string -{{ name }}_types: - MyType: - properties: - my_property: - type: {{ type_name }} - required: false -topology_template: - {{ section }}: - my_template: - type: MyType -""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], - type_name=type_name)).assert_success() - - [email protected]( - 'name,type_name,value', - ((s, v[0], v[1]) - for s, v in itertools.product( - data.TEMPLATE_NAMES, - data.PARAMETER_VALUES)) -) -def test_template_property_required_with_default(parser, name, type_name, value): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -data_types: - MyType: - properties: - my_field: - type: string -{{ name }}_types: - MyType: - properties: - my_property: - type: {{ type_name }} - default: {{ value }} -topology_template: - {{ section }}: - my_template: - type: MyType -""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], type_name=type_name, - value=value)).assert_success() - - -# Entry schema - [email protected]( - 'name,parameter_section,values', - ((s[0], s[1], v) - for s, v in itertools.product( - data.TEMPLATE_PARAMETER_SECTIONS, - data.ENTRY_SCHEMA_VALUES)) -) -def test_template_parameter_map(parser, name, parameter_section, values): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -data_types: - MyType: - properties: - my_field: - type: string - default: default value -{{ name }}_types: - MyType: - {{ parameter_section }}: - my_parameter: - type: map - entry_schema: {{ values[0] }} -topology_template: - {{ section }}: - my_template: - type: MyType - {{ parameter_section }}: - my_parameter: - key1: {{ values[1] }} - key2: {{ values[2] }} -""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], parameter_section=parameter_section, - values=values)).assert_success() - - [email protected]( - 'name,parameter_section,values', - ((s[0], s[1], v) - for s, v in itertools.product( - data.TEMPLATE_PARAMETER_SECTIONS, - data.ENTRY_SCHEMA_VALUES_BAD)) -) -def test_template_parameter_map_bad(parser, name, parameter_section, values): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -data_types: - MyType: - properties: - my_field: - type: string - default: default value -{{ name }}_types: - MyType: - {{ parameter_section }}: - my_parameter: - type: map - entry_schema: {{ values[0] }} -topology_template: - {{ section }}: - my_template: - type: MyType - {{ parameter_section }}: - my_parameter: - key1: {{ values[1] }} - key2: {{ values[2] }} -""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], parameter_section=parameter_section, - values=values)).assert_failure() - - [email protected]('name,parameter_section', data.TEMPLATE_PARAMETER_SECTIONS) -def test_template_parameter_map_required_field(parser, name, parameter_section): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -data_types: - MyType: - properties: - my_field: - type: string -{{ name }}_types: - MyType: - {{ parameter_section }}: - my_parameter: - type: map - entry_schema: MyType -topology_template: - {{ section }}: - my_template: - type: MyType - {{ parameter_section }}: - my_parameter: - key: {my_field: a value} -""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], - parameter_section=parameter_section)).assert_success() - - [email protected]('name,parameter_section', data.TEMPLATE_PARAMETER_SECTIONS) -def test_template_parameter_map_required_field_bad(parser, name, parameter_section): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -data_types: - MyType: - properties: - my_field: - type: string -{{ name }}_types: - MyType: - {{ parameter_section }}: - my_parameter: - type: map - entry_schema: MyType -topology_template: - {{ section }}: - my_template: - type: MyType - {{ parameter_section }}: - my_parameter: - key: {} -""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], - parameter_section=parameter_section)).assert_failure() - - [email protected]( - 'name,parameter_section,values', - ((s[0], s[1], v) - for s, v in itertools.product( - data.TEMPLATE_PARAMETER_SECTIONS, - data.ENTRY_SCHEMA_VALUES)) -) -def test_template_parameter_list(parser, name, parameter_section, values): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -data_types: - MyType: - properties: - my_field: - type: string - default: default value -{{ name }}_types: - MyType: - {{ parameter_section }}: - my_parameter: - type: list - entry_schema: {{ values[0] }} -topology_template: - {{ section }}: - my_template: - type: MyType - {{ parameter_section }}: - my_parameter: - - {{ values[1] }} - - {{ values[2] }} -""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], parameter_section=parameter_section, - values=values)).assert_success() - - [email protected]( - 'name,parameter_section,values', - ((s[0], s[1], v) - for s, v in itertools.product( - data.TEMPLATE_PARAMETER_SECTIONS, - data.ENTRY_SCHEMA_VALUES_BAD)) -) -def test_template_parameter_list_bad(parser, name, parameter_section, values): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -data_types: - MyType: - properties: - my_field: - type: string - default: default value -{{ name }}_types: - MyType: - {{ parameter_section }}: - my_parameter: - type: list - entry_schema: {{ values[0] }} -topology_template: - {{ section }}: - my_template: - type: MyType - {{ parameter_section }}: - my_parameter: - - {{ values[1] }} - - {{ values[2] }} -""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], parameter_section=parameter_section, - values=values)).assert_failure() - - [email protected]('name,parameter_section', data.TEMPLATE_PARAMETER_SECTIONS) -def test_template_parameter_list_required_field(parser, name, parameter_section): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -data_types: - MyType: - properties: - my_field: - type: string -{{ name }}_types: - MyType: - {{ parameter_section }}: - my_parameter: - type: list - entry_schema: MyType -topology_template: - {{ section }}: - my_template: - type: MyType - {{ parameter_section }}: - my_parameter: - - {my_field: a value} -""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], - parameter_section=parameter_section)).assert_success() - - [email protected]('name,parameter_section', data.TEMPLATE_PARAMETER_SECTIONS) -def test_template_parameter_list_required_field_bad(parser, name, parameter_section): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -data_types: - MyType: - properties: - my_field: - type: string -{{ name }}_types: - MyType: - {{ parameter_section }}: - my_parameter: - type: list - entry_schema: MyType -topology_template: - {{ section }}: - my_template: - type: MyType - {{ parameter_section }}: - my_parameter: - - {} -""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], - parameter_section=parameter_section)).assert_failure() - - -# Unicode - [email protected]('name,parameter_section', data.TEMPLATE_PARAMETER_SECTIONS) -def test_template_parameter_unicode(parser, name, parameter_section): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -{{ name }}_types: - é¡å: - {{ parameter_section }}: - 忏: - type: string -topology_template: - {{ section }}: - 模æ¿: - type: é¡å - {{ parameter_section }}: - 忏: å¼ -""", 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/1d8ac549/tests/extensions/aria_extension_tosca/simple_v1_0/templates/test_templates.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/templates/test_templates.py b/tests/extensions/aria_extension_tosca/simple_v1_0/templates/test_templates.py deleted file mode 100644 index 1878990..0000000 --- a/tests/extensions/aria_extension_tosca/simple_v1_0/templates/test_templates.py +++ /dev/null @@ -1,102 +0,0 @@ -# -*- coding: utf-8 -*- -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import itertools - -import pytest - -from .. import data - - -# Syntax - [email protected]('name,value', itertools.product( - data.TEMPLATE_NAMES, - data.NOT_A_STRING -)) -def test_template_type_wrong_yaml_type(parser, name, value): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -topology_template: - {{ section }}: - my_template: - type: {{ value }} -""", dict(section=data.TEMPLATE_NAME_SECTIONS[name], value=value)).assert_failure() - - [email protected]('name', data.TEMPLATE_NAMES) -def test_template_unsupported_field(parser, name): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -topology_template: - {{ section }}: - my_template: - unsupported: {} -""", dict(section=data.TEMPLATE_NAME_SECTIONS[name])).assert_failure() - - -# Common fields - [email protected]('name', data.TEMPLATE_NAMES) -def test_template_fields(parser, name): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -{{ name }}_types: - MyType: {} -topology_template: - {{ section }}: - my_template: - type: MyType - description: a description -""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name])).assert_success() - - [email protected]('name', data.TEMPLATE_NAMES) -def test_template_of_unknown_type(parser, name): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -topology_template: - {{ section }}: - my_template: - type: UnknownType -""", dict(section=data.TEMPLATE_NAME_SECTIONS[name])).assert_failure() - - [email protected]('name', data.TEMPLATE_NAMES) -def test_template_of_null_type(parser, name): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -topology_template: - {{ section }}: - my_template: - type: null -""", dict(section=data.TEMPLATE_NAME_SECTIONS[name])).assert_failure() - - -# Unicode - [email protected]('name', data.TEMPLATE_NAMES) -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()
