Repository: incubator-ariatosca Updated Branches: refs/heads/ARIA-1-parser-test-suite 12e860863 -> 47cd3ba6b
Test topology inputs/outputs and consolidate Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/47cd3ba6 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/47cd3ba6 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/47cd3ba6 Branch: refs/heads/ARIA-1-parser-test-suite Commit: 47cd3ba6b90adeb214f643d53d18a0ca36c915c3 Parents: 12e8608 Author: Tal Liron <[email protected]> Authored: Fri Oct 6 14:36:51 2017 -0500 Committer: Tal Liron <[email protected]> Committed: Fri Oct 6 14:36:51 2017 -0500 ---------------------------------------------------------------------- Makefile | 1 + .../clearwater/clearwater-single-existing.yaml | 12 +- .../simple_v1_0/__init__.py | 12 +- .../simple_v1_0/definitions.py | 27 +- .../simple_v1_0/templates.py | 10 +- requirements.in | 10 +- requirements.txt | 7 +- setup.py | 8 +- .../common/test_template_parameters.py | 12 +- .../test_template_parameters_properties.py | 134 +++++++ .../common/test_template_properties.py | 134 ------- .../templates/test_inputs_and_ouputs.py | 2 - .../types/common/test_type_interfaces.py | 2 +- .../types/common/test_type_parameters.py | 225 ++++------- .../common/test_type_parameters_inheritance.py | 116 ++++++ .../common/test_type_parameters_properties.py | 312 +++++++++++++++ .../types/common/test_type_properties.py | 386 ------------------- 17 files changed, 701 insertions(+), 709 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/47cd3ba6/Makefile ---------------------------------------------------------------------- diff --git a/Makefile b/Makefile index eff2ab1..9d27752 100644 --- a/Makefile +++ b/Makefile @@ -31,6 +31,7 @@ clean: -find . -maxdepth 1 -type f -name '.coverage' -delete -find . -type f -name '*.pyc' -delete -find . -type d -name '__pycache__' -prune -exec rm -rf {} \; 2>/dev/null + -find . -type d -name '*.egg-info' -exec rm -rf {} \; 2>/dev/null install: pip install .[ssh] http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/47cd3ba6/examples/clearwater/clearwater-single-existing.yaml ---------------------------------------------------------------------- diff --git a/examples/clearwater/clearwater-single-existing.yaml b/examples/clearwater/clearwater-single-existing.yaml index 72b882a..4be3c6f 100644 --- a/examples/clearwater/clearwater-single-existing.yaml +++ b/examples/clearwater/clearwater-single-existing.yaml @@ -139,9 +139,9 @@ topology_template: substitution_mappings: node_type: ims.nodes.IMS capabilities: - p-cscf: [ bono, p-cscf ] - i-cscf: [ i-cscf, i-cscf ] - s-cscf: [ s-cscf, s-cscf ] - hss: [ homestead, hss ] - ctf: [ ralf, ctf ] - xdms: [ homer, xdms ] + p-cscf: [ bono, p-cscf ] + i-cscf: [ i-cscf, i-cscf ] + s-cscf: [ s-cscf, s-cscf ] + hss: [ homestead, hss ] + ctf: [ ralf, ctf ] + xdms: [ homer, xdms ] http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/47cd3ba6/extensions/aria_extension_tosca/simple_v1_0/__init__.py ---------------------------------------------------------------------- diff --git a/extensions/aria_extension_tosca/simple_v1_0/__init__.py b/extensions/aria_extension_tosca/simple_v1_0/__init__.py index 61995db..da323ea 100644 --- a/extensions/aria_extension_tosca/simple_v1_0/__init__.py +++ b/extensions/aria_extension_tosca/simple_v1_0/__init__.py @@ -45,7 +45,8 @@ Definitions aria_extension_tosca.simple_v1_0.PropertyDefinition aria_extension_tosca.simple_v1_0.AttributeDefinition - aria_extension_tosca.simple_v1_0.ParameterDefinition + aria_extension_tosca.simple_v1_0.InputDefinition + aria_extension_tosca.simple_v1_0.OutputDefinition aria_extension_tosca.simple_v1_0.OperationDefinition aria_extension_tosca.simple_v1_0.InterfaceDefinition aria_extension_tosca.simple_v1_0.RelationshipDefinition @@ -126,9 +127,9 @@ from .presenter import ToscaSimplePresenter1_0 from .assignments import (PropertyAssignment, OperationAssignment, InterfaceAssignment, RelationshipAssignment, RequirementAssignment, AttributeAssignment, CapabilityAssignment, ArtifactAssignment) -from .definitions import (PropertyDefinition, AttributeDefinition, ParameterDefinition, - OperationDefinition, InterfaceDefinition, RelationshipDefinition, - RequirementDefinition, CapabilityDefinition) +from .definitions import (PropertyDefinition, AttributeDefinition, InputDefinition, + OutputDefinition, OperationDefinition, InterfaceDefinition, + RelationshipDefinition, RequirementDefinition, CapabilityDefinition) from .filters import CapabilityFilter, NodeFilter from .misc import (Description, MetaData, Repository, Import, ConstraintClause, EntrySchema, OperationImplementation, SubstitutionMappingsRequirement, @@ -157,7 +158,8 @@ __all__ = ( 'ArtifactAssignment', 'PropertyDefinition', 'AttributeDefinition', - 'ParameterDefinition', + 'InputDefinition', + 'OutputDefinition', 'OperationDefinition', 'InterfaceDefinition', 'RelationshipDefinition', http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/47cd3ba6/extensions/aria_extension_tosca/simple_v1_0/definitions.py ---------------------------------------------------------------------- diff --git a/extensions/aria_extension_tosca/simple_v1_0/definitions.py b/extensions/aria_extension_tosca/simple_v1_0/definitions.py index 8d0db8e..02794e8 100644 --- a/extensions/aria_extension_tosca/simple_v1_0/definitions.py +++ b/extensions/aria_extension_tosca/simple_v1_0/definitions.py @@ -194,8 +194,8 @@ class AttributeDefinition(ExtensiblePresentation): @has_fields -@implements_specification('3.5.12', 'tosca-simple-1.0') -class ParameterDefinition(PropertyDefinition): +@implements_specification('3.5.12-1', 'tosca-simple-1.0') +class InputDefinition(PropertyDefinition): """ A parameter definition is essentially a TOSCA property definition; however, it also allows a value to be assigned to it (as for a TOSCA property assignment). In addition, in the case of @@ -207,6 +207,18 @@ class ParameterDefinition(PropertyDefinition): #DEFN_ELEMENT_PARAMETER_DEF>`__ """ + @field_validator(data_value_validator) + @primitive_field() + def value(self): + """ + The type-compatible value to assign to the named parameter. Parameter values may be provided + as the result from the evaluation of an expression or a function. + """ + + +@has_fields +@implements_specification('3.5.12-2', 'tosca-simple-1.0') +class OutputDefinition(InputDefinition): @field_validator(data_type_validator()) @primitive_field(str) def type(self): @@ -216,15 +228,10 @@ class ParameterDefinition(PropertyDefinition): Note: This keyname is required for a TOSCA Property definition, but is not for a TOSCA Parameter definition. - :type: :obj:`basestring` - """ + ARIA NOTE: the spec must be mistaken: inputs should have this field requires, only outputs + have it as optional. - @field_validator(data_value_validator) - @primitive_field() - def value(self): - """ - The type-compatible value to assign to the named parameter. Parameter values may be provided - as the result from the evaluation of an expression or a function. + :type: :obj:`basestring` """ http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/47cd3ba6/extensions/aria_extension_tosca/simple_v1_0/templates.py ---------------------------------------------------------------------- diff --git a/extensions/aria_extension_tosca/simple_v1_0/templates.py b/extensions/aria_extension_tosca/simple_v1_0/templates.py index 64fd2d4..d4d012e 100644 --- a/extensions/aria_extension_tosca/simple_v1_0/templates.py +++ b/extensions/aria_extension_tosca/simple_v1_0/templates.py @@ -23,7 +23,7 @@ from aria.parser.presentation import (has_fields, primitive_field, primitive_lis from .assignments import (PropertyAssignment, AttributeAssignment, RequirementAssignment, CapabilityAssignment, InterfaceAssignment, ArtifactAssignment) -from .definitions import ParameterDefinition +from .definitions import (InputDefinition, OutputDefinition) from .filters import NodeFilter from .misc import (Description, MetaData, Repository, Import, SubstitutionMappings) from .modeling.parameters import (get_assigned_and_defined_parameter_values, get_parameter_values) @@ -471,13 +471,13 @@ class TopologyTemplate(ExtensiblePresentation): :type: :class:`Description` """ - @object_dict_field(ParameterDefinition) + @object_dict_field(InputDefinition) def inputs(self): """ An optional list of input parameters (i.e., as parameter definitions) for the Topology Template. - :type: {:obj:`basestring`: :class:`ParameterDefinition`} + :type: {:obj:`basestring`: :class:`InputDefinition`} """ @object_dict_field(NodeTemplate) @@ -513,13 +513,13 @@ class TopologyTemplate(ExtensiblePresentation): :type: {:obj:`basestring`: :class:`PolicyTemplate`} """ - @object_dict_field(ParameterDefinition) + @object_dict_field(OutputDefinition) def outputs(self): """ An optional list of output parameters (i.e., as parameter definitions) for the Topology Template. - :type: {:obj:`basestring`: :class:`ParameterDefinition`} + :type: {:obj:`basestring`: :class:`OutputDefinition`} """ @object_field(SubstitutionMappings) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/47cd3ba6/requirements.in ---------------------------------------------------------------------- diff --git a/requirements.in b/requirements.in index 9f5396a..92aea0d 100644 --- a/requirements.in +++ b/requirements.in @@ -18,13 +18,13 @@ networkx>=1.9, <1.10 # version 1.10 dropped support for Python 2.6 retrying>=1.3.0, <1.4.0 blinker>1.3, <1.5 jsonpickle>0.9.0, <=0.9.4 -ruamel.yaml>=0.11.12, <0.12.0 # version 0.12.0 dropped support for Python 2.6 +ruamel.yaml>=0.11.12, <0.12.0 # version 0.12.0 dropped support for Python 2.6 Jinja2>=2.8, <3.0 shortuuid>=0.5, <0.6 CacheControl[filecache]>=0.11.0, <0.13 -SQLAlchemy>=1.1.0, <1.2 # version 1.2 dropped support for Python 2.6 +SQLAlchemy>=1.1.0, <1.2 # version 1.2 dropped support for Python 2.6 wagon==0.6.0 -wheel==0.29.0 # version 0.30.0 dropped support for Python 2.6 +wheel==0.29.0 # version 0.30.0 dropped support for Python 2.6 bottle>=0.12.0, <0.13 setuptools>=35.0.0, <36.0.0 click>=6.0, < 7.0 @@ -33,7 +33,7 @@ PrettyTable>=0.7,<0.8 click_didyoumean==0.0.3 backports.shutil_get_terminal_size==1.0.0 logutils==0.3.4.1 -psutil>=5.2.2, < 6.0.0 +psutil>=5.2.2, <6.0.0 importlib ; python_version < '2.7' ordereddict ; python_version < '2.7' -total-ordering ; python_version < '2.7' # only one version on PyPI +total-ordering ; python_version < '2.7' # only one version on PyPI http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/47cd3ba6/requirements.txt ---------------------------------------------------------------------- diff --git a/requirements.txt b/requirements.txt index 0983914..853a152 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,7 +4,6 @@ # # pip-compile --output-file ./requirements.txt ./requirements.in # -appdirs==1.4.3 # via setuptools backports.shutil_get_terminal_size==1.0.0 blinker==1.4 bottle==0.12.13 @@ -22,20 +21,18 @@ markupsafe==1.0 # via jinja2 msgpack-python==0.4.8 # via cachecontrol networkx==1.9.1 ordereddict==1.1 ; python_version < "2.7" -packaging==16.8 # via setuptools prettytable==0.7.2 psutil==5.3.1 -pyparsing==2.2.0 # via packaging requests==2.13.0 retrying==1.3.3 ruamel.ordereddict==0.4.13 # via ruamel.yaml ruamel.yaml==0.11.15 shortuuid==0.5.0 -six==1.11.0 # via packaging, retrying, setuptools +six==1.11.0 # via retrying sqlalchemy==1.1.14 total-ordering==0.1.0 ; python_version < "2.7" wagon==0.6.0 wheel==0.29.0 # The following packages are considered to be unsafe in a requirements file: -setuptools==35.0.2 +# setuptools http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/47cd3ba6/setup.py ---------------------------------------------------------------------- diff --git a/setup.py b/setup.py index 8e95c19..df557c6 100644 --- a/setup.py +++ b/setup.py @@ -60,17 +60,17 @@ extras_require = { with open(os.path.join(root_dir, 'requirements.in')) as requirements: for requirement in requirements.readlines(): - requirement = requirement.split('#')[0].strip() # get rid of comments or trailing comments + requirement = requirement.split('#', 1)[0].strip() # Remove comments if not requirement: - continue # skip empty and comment lines + continue # Skip empty and comment lines - # dependencies which use environment markers have to go in as conditional dependencies + # Dependencies which use environment markers have to go in as conditional dependencies # under "extra_require" rather than "install_requires", or otherwise the environment # markers get ignored when installing from wheel. See more here: # https://wheel.readthedocs.io/en/latest/index.html#defining-conditional-dependencies # https://hynek.me/articles/conditional-python-dependencies/ if ';' in requirement: - package, condition = requirement.split(';') + package, condition = requirement.split(';', 1) cond_name = ':{0}'.format(condition.strip()) extras_require.setdefault(cond_name, []) extras_require[cond_name].append(package.strip()) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/47cd3ba6/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 index 545f8dc..6258a92 100644 --- 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 @@ -115,7 +115,7 @@ interface_types: {%- endmacro %} """ -# Assigning to inputs defined (added/overriden) at an interface of the template's type +# Assigning to inputs defined (added/overridden) at an interface of the template's type LOCAL_INTERFACE_MACROS = """ {% macro additions() %} interface_types: @@ -134,7 +134,7 @@ interface_types: {%- endmacro %} """ -# Assigning to inputs defined (added/overriden) at an operation of an interface of the template's +# Assigning to inputs defined (added/overridden) at an operation of an interface of the template's # type LOCAL_OPERATION_MACROS = """ {% macro additions() %} @@ -247,7 +247,7 @@ interface_types: {%- endmacro %} """ -# At a relationship of a node template, assigning to inputs defined (added/overriden) at an +# At a relationship of a node template, assigning to inputs defined (added/overridden) at an # interface of a relationship type RELATIONSHIP_TYPE_INTERFACE_MACROS = """ {% macro additions() %} @@ -279,7 +279,7 @@ relationship_types: {%- endmacro %} """ -# At a relationship of a node template, assigning to inputs defined (added/overriden) at an +# At a relationship of a node template, assigning to inputs defined (added/overridden) at an # operation of an interface of a relationship type RELATIONSHIP_TYPE_OPERATION_MACROS = """ {% macro additions() %} @@ -313,7 +313,7 @@ relationship_types: {%- endmacro %} """ -# At a relationship of a node template, assigning to inputs defined (added/overriden) at an +# At a relationship of a node template, assigning to inputs defined (added/overridden) at an # interface of the relationship of the node type RELATIONSHIP_LOCAL_INTERFACE_MACROS = """ {% macro additions() %} @@ -345,7 +345,7 @@ interface_types: {%- endmacro %} """ -# At a relationship of a node template, assigning to inputs defined (added/overriden) at an +# At a relationship of a node template, assigning to inputs defined (added/overridden) at an # operation of an interface of the relationship of the node type RELATIONSHIP_LOCAL_OPERATION_MACROS = """ {% macro additions() %} http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/47cd3ba6/tests/extensions/aria_extension_tosca/simple_v1_0/templates/common/test_template_parameters_properties.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/templates/common/test_template_parameters_properties.py b/tests/extensions/aria_extension_tosca/simple_v1_0/templates/common/test_template_parameters_properties.py new file mode 100644 index 0000000..55b44c5 --- /dev/null +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/templates/common/test_template_parameters_properties.py @@ -0,0 +1,134 @@ +# -*- coding: utf-8 -*- +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +""" +Unified testing for properties. + +These tests are in addition to the common tests for parameters in test_template_parameters.py. +""" + +import pytest + +from .test_template_parameters import (MACROS, PERMUTATIONS as PARAMETER_PERMUTATIONS) +from ... import data +from ......mechanisms.utils import matrix + + +PERMUTATIONS = tuple( + (macros, name, parameter_section) + for macros, name, parameter_section in PARAMETER_PERMUTATIONS + if parameter_section != 'attributes' +) + + +# Required + [email protected](reason='fix for relationships') [email protected]('macros,name,parameter_section,type_name', matrix( + PERMUTATIONS, + data.PARAMETER_TYPE_NAMES, + counts=(3, 1) +)) +def test_template_parameter_required(parser, macros, name, parameter_section, type_name): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +data_types: + MyType: + properties: + my_field: + type: string +{{ name }}_types: + MyType: +{%- call type_parameters() %} +my_property: + type: {{ type_name }} +{% endcall %} +topology_template: + {{ section }}: + my_template: + type: MyType +{%- call parameters() -%} +{} +{% endcall %} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], parameter_section=parameter_section, + type_name=type_name)).assert_failure() + + [email protected]('macros,name,parameter_section,type_name', matrix( + PERMUTATIONS, + data.PARAMETER_TYPE_NAMES, + counts=(3, 1) +)) +def test_template_parameter_not_required(parser, macros, name, parameter_section, type_name): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +data_types: + MyType: + properties: + my_field: + type: string +{{ name }}_types: + MyType: +{%- call type_parameters() %} +my_property: + type: {{ type_name }} + required: false +{% endcall %} +topology_template: + {{ section }}: + my_template: + type: MyType +{%- call parameters() -%} +{} +{% endcall %} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], parameter_section=parameter_section, + type_name=type_name)).assert_success() + + [email protected](reason='fix for relationship inputs') [email protected]('macros,name,parameter_section,type_name,value', matrix( + PERMUTATIONS, + data.PARAMETER_VALUES, + counts=(3, 2) +)) +def test_template_parameter_required_with_default(parser, macros, name, parameter_section, + type_name, value): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +data_types: + MyType: + properties: + my_field: + type: string +{{ name }}_types: + MyType: +{%- call type_parameters() %} +my_property: + type: {{ type_name }} + default: {{ value }} +{% endcall %} +topology_template: + {{ section }}: + my_template: + type: MyType +{%- call parameters() -%} +{} +{% endcall %} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], parameter_section=parameter_section, + type_name=type_name, value=value)).assert_success() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/47cd3ba6/tests/extensions/aria_extension_tosca/simple_v1_0/templates/common/test_template_properties.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/templates/common/test_template_properties.py b/tests/extensions/aria_extension_tosca/simple_v1_0/templates/common/test_template_properties.py deleted file mode 100644 index 4c947d2..0000000 --- a/tests/extensions/aria_extension_tosca/simple_v1_0/templates/common/test_template_properties.py +++ /dev/null @@ -1,134 +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. - -""" -Unified testing for properties. - -These tests are in addition to the common tests for parameters in test_template_parameters.py. -""" - -import pytest - -from .test_template_parameters import (MACROS, PERMUTATIONS as PARAMETER_CASES) -from ... import data -from ......mechanisms.utils import matrix - - -PERMUTATIONS = tuple( - (macros, name, parameter_section) - for macros, name, parameter_section in PARAMETER_CASES - if parameter_section != 'attributes' -) - - -# Required - [email protected](reason='fix for relationships') [email protected]('macros,name,parameter_section,type_name', matrix( - PERMUTATIONS, - data.PARAMETER_TYPE_NAMES, - counts=(3, 1) -)) -def test_template_property_required(parser, macros, name, parameter_section, type_name): - parser.parse_literal(MACROS[macros] + """ -tosca_definitions_version: tosca_simple_yaml_1_0 -{{- additions() }} -data_types: - MyType: - properties: - my_field: - type: string -{{ name }}_types: - MyType: -{%- call type_parameters() %} -my_property: - type: {{ type_name }} -{% endcall %} -topology_template: - {{ section }}: - my_template: - type: MyType -{%- call parameters() -%} -{} -{% endcall %} -""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], parameter_section=parameter_section, - type_name=type_name)).assert_failure() - - [email protected]('macros,name,parameter_section,type_name', matrix( - PERMUTATIONS, - data.PARAMETER_TYPE_NAMES, - counts=(3, 1) -)) -def test_template_property_not_required(parser, macros, name, parameter_section, type_name): - parser.parse_literal(MACROS[macros] + """ -tosca_definitions_version: tosca_simple_yaml_1_0 -{{- additions() }} -data_types: - MyType: - properties: - my_field: - type: string -{{ name }}_types: - MyType: -{%- call type_parameters() %} -my_property: - type: {{ type_name }} - required: false -{% endcall %} -topology_template: - {{ section }}: - my_template: - type: MyType -{%- call parameters() -%} -{} -{% endcall %} -""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], parameter_section=parameter_section, - type_name=type_name)).assert_success() - - [email protected](reason='fix for relationship inputs') [email protected]('macros,name,parameter_section,type_name,value', matrix( - PERMUTATIONS, - data.PARAMETER_VALUES, - counts=(3, 2) -)) -def test_template_property_required_with_default(parser, macros, name, parameter_section, type_name, - value): - parser.parse_literal(MACROS[macros] + """ -tosca_definitions_version: tosca_simple_yaml_1_0 -{{- additions() }} -data_types: - MyType: - properties: - my_field: - type: string -{{ name }}_types: - MyType: -{%- call type_parameters() %} -my_property: - type: {{ type_name }} - default: {{ value }} -{% endcall %} -topology_template: - {{ section }}: - my_template: - type: MyType -{%- call parameters() -%} -{} -{% endcall %} -""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], parameter_section=parameter_section, - type_name=type_name, value=value)).assert_success() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/47cd3ba6/tests/extensions/aria_extension_tosca/simple_v1_0/templates/test_inputs_and_ouputs.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/templates/test_inputs_and_ouputs.py b/tests/extensions/aria_extension_tosca/simple_v1_0/templates/test_inputs_and_ouputs.py deleted file mode 100644 index b714df1..0000000 --- a/tests/extensions/aria_extension_tosca/simple_v1_0/templates/test_inputs_and_ouputs.py +++ /dev/null @@ -1,2 +0,0 @@ - -# TODO http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/47cd3ba6/tests/extensions/aria_extension_tosca/simple_v1_0/types/common/test_type_interfaces.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/types/common/test_type_interfaces.py b/tests/extensions/aria_extension_tosca/simple_v1_0/types/common/test_type_interfaces.py index e738d0b..3c7dc20 100644 --- a/tests/extensions/aria_extension_tosca/simple_v1_0/types/common/test_type_interfaces.py +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/types/common/test_type_interfaces.py @@ -29,7 +29,7 @@ MAIN_MACROS = """ {%- endmacro %} """ -# Interfaces defined (added/overriden) at a relationship of a requirement within a node type +# Interfaces defined (added/overridden) at a relationship of a requirement within a node type RELATIONSHIP_MACROS = """ {% macro additions() %} capability_types: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/47cd3ba6/tests/extensions/aria_extension_tosca/simple_v1_0/types/common/test_type_parameters.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/types/common/test_type_parameters.py b/tests/extensions/aria_extension_tosca/simple_v1_0/types/common/test_type_parameters.py index c0722ed..ff24c81 100644 --- a/tests/extensions/aria_extension_tosca/simple_v1_0/types/common/test_type_parameters.py +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/types/common/test_type_parameters.py @@ -31,18 +31,32 @@ from ......mechanisms.utils import matrix # Defining parameters at a type MAIN_MACROS = """ -{% macro additions() %} +{% macro additions(section=True) %} +{%- if section %} +{{ name }}_types: +{%- endif %} {%- endmacro %} -{% macro parameters() %} +{% macro parameters(t='MyType', d=None) %} + {{ t }}: +{%- if d %} + derived_from: {{ d }} +{%- endif %} {{ parameter_section }}: {{ caller()|indent(6) }} {%- endmacro %} """ # Defining parameters at a nested type (e.g. inputs of an operation within an interface type) NESTED_MACROS = """ -{% macro additions() %} +{% macro additions(section=True) %} +{%- if section %} +{{ name }}_types: +{%- endif %} {%- endmacro %} -{% macro parameters() %} +{% macro parameters(t='MyType', d=None) %} + {{ t }}: +{%- if d %} + derived_from: {{ d }} +{%- endif %} nested: {{ parameter_section }}: {{ caller()|indent(8) }} {%- endmacro %} @@ -50,11 +64,18 @@ NESTED_MACROS = """ # Defining inputs at an interface of a type INTERFACE_MACROS = """ -{% macro additions() %} +{% macro additions(section=True) %} interface_types: MyType: {} +{%- if section %} +{{ name }}_types: +{%- endif %} {%- endmacro %} -{% macro parameters() %} +{% macro parameters(t='MyType', d=None) %} + {{ t }}: +{%- if d %} + derived_from: {{ d }} +{%- endif %} interfaces: my_interface: type: MyType @@ -64,11 +85,18 @@ interface_types: # Defining inputs at an operation of an interface of a type OPERATION_MACROS = """ -{% macro additions() %} +{% macro additions(section=True) %} interface_types: MyType: {} +{%- if section %} +{{ name }}_types: +{%- endif %} {%- endmacro %} -{% macro parameters() %} +{% macro parameters(t='MyType', d=None) %} + {{ t }}: +{%- if d %} + derived_from: {{ d }} +{%- endif %} interfaces: my_interface: type: MyType @@ -79,15 +107,22 @@ interface_types: # Defining inputs at an interface of a relationship of a requirement of a node type RELATIONSHIP_INTERFACE_MACROS = """ -{% macro additions() %} +{% macro additions(section=True) %} capability_types: MyType: {} relationship_types: MyType: {} interface_types: MyType: {} +{%- if section %} +{{ name }}_types: +{%- endif %} {%- endmacro %} -{% macro parameters() %} +{% macro parameters(t='MyType', d=None) %} + {{ t }}: +{%- if d %} + derived_from: {{ d }} +{%- endif %} requirements: - my_requirement: capability: MyType @@ -102,15 +137,22 @@ interface_types: # Defining inputs at an operation of an interface of a relationship of a requirement of a node type RELATIONSHIP_OPERATION_MACROS = """ -{% macro additions() %} +{% macro additions(section=True) %} capability_types: MyType: {} relationship_types: MyType: {} interface_types: MyType: {} +{%- if section %} +{{ name }}_types: +{%- endif %} {%- endmacro %} -{% macro parameters() %} +{% macro parameters(t='MyType', d=None) %} + {{ t }}: +{%- if d %} + derived_from: {{ d }} +{%- endif %} requirements: - my_requirement: capability: MyType @@ -126,11 +168,18 @@ interface_types: # Defining parameters at a capability of a node type CAPABILITY_MACROS = """ -{% macro additions() %} +{% macro additions(section=True) %} capability_types: MyType: {} +{%- if section %} +{{ name }}_types: +{%- endif %} {%- endmacro %} -{% macro parameters() %} +{% macro parameters(t='MyType', d=None) %} + {{ t }}: +{%- if d %} + derived_from: {{ d }} +{%- endif %} capabilities: my_capability: type: MyType @@ -138,6 +187,17 @@ capability_types: {%- endmacro %} """ +# Defining inputs/outputs at a topology template +TOPOLOGY_MACROS = """ +{% macro additions(section=None) %} +topology_template: +{%- endmacro %} +{% macro parameters(t=None) %} + {{ parameter_section }}: {{ caller()|indent(4) }} +{%- endmacro %} +""" + + MACROS = { 'main': MAIN_MACROS, 'nested': NESTED_MACROS, @@ -145,10 +205,11 @@ MACROS = { 'operation': OPERATION_MACROS, 'relationship-interface': RELATIONSHIP_INTERFACE_MACROS, 'relationship-operation': RELATIONSHIP_OPERATION_MACROS, - 'capability': CAPABILITY_MACROS + 'capability': CAPABILITY_MACROS, + 'topology': TOPOLOGY_MACROS } -PERMUTATIONS = ( +PERMUTATIONS_TYPE_REQUIRED = ( ('main', 'node', 'properties'), ('main', 'node', 'attributes'), ('main', 'group', 'properties'), @@ -170,7 +231,12 @@ PERMUTATIONS = ( ('relationship-interface', 'node', 'inputs'), ('relationship-operation', 'node', 'inputs'), ('capability', 'node', 'properties'), - ('capability', 'node', 'attributes') + ('capability', 'node', 'attributes'), + ('topology', None, 'inputs') +) + +PERMUTATIONS = PERMUTATIONS_TYPE_REQUIRED + ( + ('topology', None, 'outputs'), ) @@ -185,8 +251,6 @@ def test_type_parameters_section_syntax_type(parser, macros, name, parameter_sec parser.parse_literal(MACROS[macros] + """ tosca_definitions_version: tosca_simple_yaml_1_0 {{- additions() }} -{{ name }}_types: - MyType: {%- call parameters() -%} {{ value }} {% endcall %} @@ -198,8 +262,6 @@ def test_type_parameters_section_syntax_empty(parser, macros, name, parameter_se parser.parse_literal(MACROS[macros] + """ tosca_definitions_version: tosca_simple_yaml_1_0 {{- additions() }} -{{ name }}_types: - MyType: {%- call parameters() -%} {} {% endcall %} @@ -217,21 +279,17 @@ def test_type_parameter_syntax_type(parser, macros, name, parameter_section, val parser.parse_literal(MACROS[macros] + """ tosca_definitions_version: tosca_simple_yaml_1_0 {{- additions() }} -{{ name }}_types: - MyType: {%- call parameters() %} my_parameter: {{ value }} {% endcall %} """, dict(name=name, parameter_section=parameter_section, value=value)).assert_failure() [email protected]('macros,name,parameter_section', PERMUTATIONS) [email protected]('macros,name,parameter_section', PERMUTATIONS_TYPE_REQUIRED) def test_type_parameter_syntax_empty(parser, macros, name, parameter_section): parser.parse_literal(MACROS[macros] + """ tosca_definitions_version: tosca_simple_yaml_1_0 {{- additions() }} -{{ name }}_types: - MyType: {%- call parameters() %} my_parameter: {} # type is required {% endcall %} @@ -243,8 +301,6 @@ def test_type_parameter_syntax_unsupported(parser, macros, name, parameter_secti parser.parse_literal(MACROS[macros] + """ tosca_definitions_version: tosca_simple_yaml_1_0 {{- additions() }} -{{ name }}_types: - MyType: {%- call parameters() %} my_parameter: type: string @@ -264,8 +320,6 @@ def test_type_parameter_description_syntax_type(parser, macros, name, parameter_ parser.parse_literal(MACROS[macros] + """ tosca_definitions_version: tosca_simple_yaml_1_0 {{- additions() }} -{{ name }}_types: - MyType: {%- call parameters() %} my_parameter: type: string @@ -279,8 +333,6 @@ def test_type_parameter_description(parser, macros, name, parameter_section): parser.parse_literal(MACROS[macros] + """ tosca_definitions_version: tosca_simple_yaml_1_0 {{- additions() }} -{{ name }}_types: - MyType: {%- call parameters() %} my_parameter: type: string @@ -296,8 +348,6 @@ def test_type_parameter_default(parser, macros, name, parameter_section): parser.parse_literal(MACROS[macros] + """ tosca_definitions_version: tosca_simple_yaml_1_0 {{- additions() }} -{{ name }}_types: - MyType: {%- call parameters() %} my_parameter: type: string @@ -311,8 +361,6 @@ def test_type_parameter_default_bad(parser, macros, name, parameter_section): parser.parse_literal(MACROS[macros] + """ tosca_definitions_version: tosca_simple_yaml_1_0 {{- additions() }} -{{ name }}_types: - MyType: {%- call parameters() %} my_parameter: type: integer @@ -332,8 +380,6 @@ def test_type_parameter_status(parser, macros, name, parameter_section, value): parser.parse_literal(MACROS[macros] + """ tosca_definitions_version: tosca_simple_yaml_1_0 {{- additions() }} -{{ name }}_types: - MyType: {%- call parameters() %} my_parameter: type: string @@ -347,8 +393,6 @@ def test_type_parameter_status_bad(parser, macros, name, parameter_section): parser.parse_literal(MACROS[macros] + """ tosca_definitions_version: tosca_simple_yaml_1_0 {{- additions() }} -{{ name }}_types: - MyType: {%- call parameters() %} my_parameter: type: string @@ -357,103 +401,6 @@ my_parameter: """, dict(name=name, parameter_section=parameter_section)).assert_failure() -# Overriding - [email protected]('macros,name,parameter_section', PERMUTATIONS) -def test_type_parameter_add(parser, macros, name, parameter_section): - parser.parse_literal(MACROS[macros] + """ -tosca_definitions_version: tosca_simple_yaml_1_0 -{{- additions() }} -{{ name }}_types: - MyType1: -{%- call parameters() %} -my_parameter1: - type: string -{% endcall %} - MyType2: - derived_from: MyType1 -{%- call parameters() %} -my_parameter2: - type: string -{% endcall %} -""", dict(name=name, parameter_section=parameter_section)).assert_success() - - [email protected]('macros,name,parameter_section', PERMUTATIONS) -def test_type_parameter_add_default(parser, macros, name, parameter_section): - parser.parse_literal(MACROS[macros] + """ -tosca_definitions_version: tosca_simple_yaml_1_0 -{{- additions() }} -{{ name }}_types: - MyType1: -{%- call parameters() %} -my_parameter: - type: string -{% endcall %} - MyType2: - derived_from: MyType1 -{%- call parameters() %} -my_parameter: - type: string - default: my value -{% endcall %} -""", dict(name=name, parameter_section=parameter_section)).assert_success() - - [email protected](reason='fix for node.capability and node.relationship') [email protected]('macros,name,parameter_section', PERMUTATIONS) -def test_type_parameter_type_override(parser, macros, name, parameter_section): - parser.parse_literal(MACROS[macros] + """ -tosca_definitions_version: tosca_simple_yaml_1_0 -{{- additions() }} -data_types: - MyDataType1: {} - MyDataType2: - derived_from: MyDataType1 -{%- if name != 'data' %} -{{ name }}_types: -{%- endif %} - MyType1: -{%- call parameters() %} -my_parameter: - type: MyDataType1 -{% endcall %} - MyType2: - derived_from: MyType1 -{%- call parameters() %} -my_parameter: - type: MyDataType2 -{% endcall %} -""", dict(name=name, parameter_section=parameter_section)).assert_success() - - [email protected](reason='fix for node.capability and node.relationship') [email protected]('macros,name,parameter_section', PERMUTATIONS) -def test_type_parameter_type_override_bad(parser, macros, name, parameter_section): - parser.parse_literal(MACROS[macros] + """ -tosca_definitions_version: tosca_simple_yaml_1_0 -{{- additions() }} -data_types: - MyDataType1: {} - MyDataType2: - derived_from: MyDataType1 -{%- if name != 'data' %} -{{ name }}_types: -{%- endif %} - MyType1: -{%- call parameters() %} -my_parameter: - type: MyDataType2 -{% endcall %} - MyType2: - derived_from: MyType1 -{%- call parameters() %} -my_parameter: - type: MyDataType1 -{% endcall %} -""", dict(name=name, parameter_section=parameter_section)).assert_failure() - - # Unicode @pytest.mark.parametrize('macros,name,parameter_section', PERMUTATIONS) @@ -461,9 +408,7 @@ def test_type_parameter_unicode(parser, macros, name, parameter_section): parser.parse_literal(MACROS[macros] + """ tosca_definitions_version: tosca_simple_yaml_1_0 {{- additions() }} -{{ name }}_types: - MyType: -{%- call parameters() %} +{%- call parameters('é¡å') %} 忏: type: string description: æè¿° http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/47cd3ba6/tests/extensions/aria_extension_tosca/simple_v1_0/types/common/test_type_parameters_inheritance.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/types/common/test_type_parameters_inheritance.py b/tests/extensions/aria_extension_tosca/simple_v1_0/types/common/test_type_parameters_inheritance.py new file mode 100644 index 0000000..e8a72f4 --- /dev/null +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/types/common/test_type_parameters_inheritance.py @@ -0,0 +1,116 @@ +# -*- coding: utf-8 -*- +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +""" +Unified testing for properties and inputs. + +These tests are in addition to the common tests for parameters in test_type_parameters.py. + +Compare with test_node_template_node_filter_constraints.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 .test_type_parameters import (MACROS, PERMUTATIONS as PARAMETER_PERMUTATIONS) + + +PERMUTATIONS = tuple( + (macros, name, parameter_section) + for macros, name, parameter_section in PARAMETER_PERMUTATIONS + if name is not None +) + + [email protected]('macros,name,parameter_section', PERMUTATIONS) +def test_type_parameter_add(parser, macros, name, parameter_section): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +{%- call parameters('MyType1') %} +my_parameter1: + type: string +{% endcall %} +{%- call parameters('MyType2', 'MyType1') %} +my_parameter2: + type: string +{% endcall %} +""", dict(name=name, parameter_section=parameter_section)).assert_success() + + [email protected]('macros,name,parameter_section', PERMUTATIONS) +def test_type_parameter_add_default(parser, macros, name, parameter_section): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +{%- call parameters('MyType1') %} +my_parameter: + type: string +{% endcall %} +{%- call parameters('MyType2', 'MyType1') %} +my_parameter: + type: string + default: my value +{% endcall %} +""", dict(name=name, parameter_section=parameter_section)).assert_success() + + [email protected](reason='fix for node.capability and node.relationship') [email protected]('macros,name,parameter_section', PERMUTATIONS) +def test_type_parameter_type_override(parser, macros, name, parameter_section): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +data_types: + MyDataType1: {} + MyDataType2: + derived_from: MyDataType1 +{%- if name != 'data' %} +{{ name }}_types: +{%- endif %} +{%- call parameters('MyType1') %} +my_parameter: + type: MyDataType1 +{% endcall %} +{%- call parameters('MyType2', 'MyType1') %} +my_parameter: + type: MyDataType2 +{% endcall %} +""", dict(name=name, parameter_section=parameter_section)).assert_success() + + [email protected](reason='fix for node.capability and node.relationship') [email protected]('macros,name,parameter_section', PERMUTATIONS) +def test_type_parameter_type_override_bad(parser, macros, name, parameter_section): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +data_types: + MyDataType1: {} + MyDataType2: + derived_from: MyDataType1 +{%- if name != 'data' %} +{{ name }}_types: +{%- endif %} +{%- call parameters('MyType1') %} +my_parameter: + type: MyDataType2 +{% endcall %} +{%- call parameters('MyType2', 'MyType1') %} +my_parameter: + type: MyDataType1 +{% endcall %} +""", dict(name=name, parameter_section=parameter_section)).assert_failure() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/47cd3ba6/tests/extensions/aria_extension_tosca/simple_v1_0/types/common/test_type_parameters_properties.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/types/common/test_type_parameters_properties.py b/tests/extensions/aria_extension_tosca/simple_v1_0/types/common/test_type_parameters_properties.py new file mode 100644 index 0000000..16fc875 --- /dev/null +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/types/common/test_type_parameters_properties.py @@ -0,0 +1,312 @@ +# -*- coding: utf-8 -*- +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +""" +Unified testing for properties and inputs. + +These tests are in addition to the common tests for parameters in test_type_parameters.py. + +Compare with test_node_template_node_filter_constraints.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 .test_type_parameters import (MACROS, PERMUTATIONS as PARAMETER_PERMUTATIONS) +from ... import data +from ......mechanisms.utils import matrix + + +PERMUTATIONS = tuple( + (macros, name, parameter_section) + for macros, name, parameter_section in PARAMETER_PERMUTATIONS + if parameter_section != 'attributes' +) + + +# Required + [email protected]('macros,name,parameter_section,value', matrix( + PERMUTATIONS, + data.NOT_A_BOOL, + counts=(3, 1) +)) +def test_type_parameter_required_syntax_type(parser, macros, name, parameter_section, value): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +{%- call parameters() %} +my_parameter: + type: string + required: {{ value }} +{% endcall %} +""", dict(name=name, parameter_section=parameter_section, value=value)).assert_failure() + + [email protected]('macros,name,parameter_section', PERMUTATIONS) +def test_type_parameter_required(parser, macros, name, parameter_section): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +{%- call parameters() %} +my_parameter: + type: string + required: true +{% endcall %} +""", dict(name=name, parameter_section=parameter_section)).assert_success() + + +# Constraints + [email protected]('macros,name,parameter_section,value', matrix( + PERMUTATIONS, + data.NOT_A_LIST, + counts=(3, 1) +)) +def test_type_parameter_constraints_syntax_type(parser, macros, name, parameter_section, value): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +{%- call parameters() %} +my_parameter: + type: string + constraints: {{ value }} +{% endcall %} +""", dict(name=name, parameter_section=parameter_section, value=value)).assert_failure() + + [email protected]('macros,name,parameter_section', PERMUTATIONS) +def test_type_parameter_constraints_syntax_empty(parser, macros, name, parameter_section): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +{%- call parameters() %} +my_parameter: + type: string + constraints: [] +{% endcall %} +""", dict(name=name, parameter_section=parameter_section)).assert_success() + + [email protected]('macros,name,parameter_section,constraint', matrix( + PERMUTATIONS, + data.CONSTRAINTS_WITH_VALUE, + counts=(3, 1) +)) +def test_type_parameter_constraints_with_value(parser, macros, name, parameter_section, constraint): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +data_types: + MyDataType: + properties: + my_field: + type: string +{{- additions(name != 'data') }} +{%- call parameters() %} +my_parameter: + type: MyDataType + constraints: + - {{ constraint }}: {my_field: a string} +{% endcall %} +""", dict(name=name, parameter_section=parameter_section, constraint=constraint)).assert_success() + + [email protected]('macros,name,parameter_section,constraint', matrix( + PERMUTATIONS, + data.CONSTRAINTS_WITH_VALUE_LIST, + counts=(3, 1) +)) +def test_type_parameter_constraints_with_value_list(parser, macros, name, parameter_section, + constraint): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +data_types: + MyDataType: + properties: + my_field: + type: string +{{- additions(name != 'data') }} +{%- call parameters() %} +my_parameter: + type: MyDataType + constraints: + - {{ constraint }}: + - {my_field: string one} + - {my_field: string two} + - {my_field: string three} +{% endcall %} +""", dict(name=name, parameter_section=parameter_section, constraint=constraint)).assert_success() + + [email protected]('macros,name,parameter_section,constraint', matrix( + PERMUTATIONS, + data.CONSTRAINTS_WITH_VALUE_RANGE, + counts=(3, 1) +)) +def test_type_parameter_constraints_with_value_range(parser, macros, name, parameter_section, + constraint): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +data_types: + MyDataType: + properties: + my_field: + type: string +{{- additions(name != 'data') }} +{%- call parameters() %} +my_parameter: + type: MyDataType + constraints: + - {{ constraint }}: + - {my_field: string a} + - {my_field: string b} +{% endcall %} +""", dict(name=name, parameter_section=parameter_section, constraint=constraint)).assert_success() + + [email protected]('macros,name,parameter_section,constraint', matrix( + PERMUTATIONS, + data.CONSTRAINTS_WITH_VALUE_RANGE, + counts=(3, 1) +)) +def test_type_parameter_constraints_with_value_range_too_many(parser, macros, name, + parameter_section, constraint): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +data_types: + MyDataType: + properties: + my_field: + type: string +{{- additions(name != 'data') }} +{%- call parameters() %} +my_parameter: + type: MyDataType + constraints: + - {{ constraint }}: + - {my_field: string a} + - {my_field: string b} + - {my_field: string c} +{% endcall %} +""", dict(name=name, parameter_section=parameter_section, constraint=constraint)).assert_failure() + + [email protected]('macros,name,parameter_section,constraint', matrix( + PERMUTATIONS, + data.CONSTRAINTS_WITH_VALUE_RANGE, + counts=(3, 1) +)) +def test_type_parameter_constraints_with_value_range_bad(macros, parser, name, parameter_section, + constraint): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +data_types: + MyDataType: + properties: + my_field: + type: string +{{- additions(name != 'data') }} +{%- call parameters() %} +my_parameter: + type: MyDataType + constraints: + - {{ constraint }}: + - {my_field: string b} + - {my_field: string a} +{% endcall %} +""", dict(name=name, parameter_section=parameter_section, constraint=constraint)).assert_failure() + + [email protected]('macros,name,parameter_section', PERMUTATIONS) +def test_type_parameter_constraints_pattern(parser, macros, name, parameter_section): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +{%- call parameters() %} +my_parameter: + type: string + constraints: + - pattern: ^pattern$ +{% endcall %} +""", dict(name=name, parameter_section=parameter_section)).assert_success() + + [email protected]('macros,name,parameter_section', PERMUTATIONS) +def test_type_parameter_constraints_pattern_bad(parser, macros, name, parameter_section): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +{%- call parameters() %} +my_parameter: + type: string + constraints: + - pattern: ( +{% endcall %} +""", dict(name=name, parameter_section=parameter_section)).assert_failure() + + [email protected]('macros,name,parameter_section,constraint', matrix( + PERMUTATIONS, + data.CONSTRAINTS_WITH_VALUE_NON_NEGATIVE_INT, + counts=(3, 1) +)) +def test_type_parameter_constraints_with_value_integer(parser, macros, name, parameter_section, + constraint): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +{%- call parameters() %} +my_parameter: + type: string + constraints: + - {{ constraint }}: 1 +{% endcall %} +""", dict(name=name, parameter_section=parameter_section, constraint=constraint)).assert_success() + + [email protected]('macros,name,parameter_section,constraint', matrix( + PERMUTATIONS, + data.CONSTRAINTS_WITH_VALUE_NON_NEGATIVE_INT, + counts=(3, 1) +)) +def test_type_parameter_constraints_with_value_integer_bad(parser, macros, name, parameter_section, + constraint): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +{%- call parameters() %} +my_parameter: + type: string + constraints: + - {{ constraint }}: -1 +{% endcall %} +""", dict(name=name, parameter_section=parameter_section, constraint=constraint)).assert_failure() + + +# Unicode + [email protected]('macros,name,parameter_section', PERMUTATIONS) +def test_type_parameter_constraints_pattern_unicode(parser, macros, name, parameter_section): + parser.parse_literal(MACROS[macros] + """ +tosca_definitions_version: tosca_simple_yaml_1_0 +{{- additions() }} +{%- call parameters('é¡å') %} +忏: + type: string + constraints: + - pattern: ^模å¼$ +{% endcall %} +""", dict(name=name, parameter_section=parameter_section)).assert_success() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/47cd3ba6/tests/extensions/aria_extension_tosca/simple_v1_0/types/common/test_type_properties.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/types/common/test_type_properties.py b/tests/extensions/aria_extension_tosca/simple_v1_0/types/common/test_type_properties.py deleted file mode 100644 index e04462f..0000000 --- a/tests/extensions/aria_extension_tosca/simple_v1_0/types/common/test_type_properties.py +++ /dev/null @@ -1,386 +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. - -""" -Unified testing for properties and inputs. - -These tests are in addition to the common tests for parameters in test_type_parameters.py. - -Compare with test_node_template_node_filter_constraints.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 .test_type_parameters import (MACROS, PERMUTATIONS as PARAMETER_CASES) -from ... import data -from ......mechanisms.utils import matrix - - -PERMUTATIONS = tuple( - (macros, name, parameter_section) - for macros, name, parameter_section in PARAMETER_CASES - if parameter_section != 'attributes' -) - - -# Required - [email protected]('macros,name,parameter_section,value', matrix( - PERMUTATIONS, - data.NOT_A_BOOL, - counts=(3, 1) -)) -def test_type_parameter_required_syntax_type(parser, macros, name, parameter_section, value): - parser.parse_literal(MACROS[macros] + """ -tosca_definitions_version: tosca_simple_yaml_1_0 -{{- additions() }} -{{ name }}_types: - MyType: -{%- call parameters() %} -my_parameter: - type: string - required: {{ value }} -{% endcall %} -""", dict(name=name, parameter_section=parameter_section, value=value)).assert_failure() - - [email protected]('macros,name,parameter_section', PERMUTATIONS) -def test_type_parameter_required(parser, macros, name, parameter_section): - parser.parse_literal(MACROS[macros] + """ -tosca_definitions_version: tosca_simple_yaml_1_0 -{{- additions() }} -{{ name }}_types: - MyType: -{%- call parameters() %} -my_parameter: - type: string - required: true -{% endcall %} -""", dict(name=name, parameter_section=parameter_section)).assert_success() - - -# Status - [email protected]('macros,name,parameter_section,value', matrix( - PERMUTATIONS, - data.STATUSES, - counts=(3, 1) -)) -def test_type_parameter_status(parser, macros, name, parameter_section, value): - parser.parse_literal(MACROS[macros] + """ -tosca_definitions_version: tosca_simple_yaml_1_0 -{{- additions() }} -{{ name }}_types: - MyType: -{%- call parameters() %} -my_parameter: - type: string - status: {{ value }} -{% endcall %} -""", dict(name=name, parameter_section=parameter_section, value=value)).assert_success() - - [email protected]('macros,name,parameter_section', PERMUTATIONS) -def test_type_parameter_status_bad(parser, macros, name, parameter_section): - parser.parse_literal(MACROS[macros] + """ -tosca_definitions_version: tosca_simple_yaml_1_0 -{{- additions() }} -{{ name }}_types: - MyType: -{%- call parameters() %} -my_parameter: - type: string - status: not a status -{% endcall %} -""", dict(name=name, parameter_section=parameter_section)).assert_failure() - - -# Constraints - [email protected]('macros,name,parameter_section,value', matrix( - PERMUTATIONS, - data.NOT_A_LIST, - counts=(3, 1) -)) -def test_type_parameter_constraints_syntax_type(parser, macros, name, parameter_section, value): - parser.parse_literal(MACROS[macros] + """ -tosca_definitions_version: tosca_simple_yaml_1_0 -{{- additions() }} -{{ name }}_types: - MyType: -{%- call parameters() %} -my_parameter: - type: string - constraints: {{ value }} -{% endcall %} -""", dict(name=name, parameter_section=parameter_section, value=value)).assert_failure() - - [email protected]('macros,name,parameter_section', PERMUTATIONS) -def test_type_parameter_constraints_syntax_empty(parser, macros, name, parameter_section): - parser.parse_literal(MACROS[macros] + """ -tosca_definitions_version: tosca_simple_yaml_1_0 -{{- additions() }} -{{ name }}_types: - MyType: -{%- call parameters() %} -my_parameter: - type: string - constraints: [] -{% endcall %} -""", dict(name=name, parameter_section=parameter_section)).assert_success() - - [email protected]('macros,name,parameter_section,constraint', matrix( - PERMUTATIONS, - data.CONSTRAINTS_WITH_VALUE, - counts=(3, 1) -)) -def test_type_parameter_constraints_with_value(parser, macros, name, parameter_section, constraint): - parser.parse_literal(MACROS[macros] + """ -tosca_definitions_version: tosca_simple_yaml_1_0 -{{- additions() }} -data_types: - MyDataType: - properties: - my_field: - type: string -{%- if name != 'data' %} -{{ name }}_types: -{%- endif %} - MyType: -{%- call parameters() %} -my_parameter: - type: MyDataType - constraints: - - {{ constraint }}: {my_field: a string} -{% endcall %} -""", dict(name=name, parameter_section=parameter_section, constraint=constraint)).assert_success() - - [email protected]('macros,name,parameter_section,constraint', matrix( - PERMUTATIONS, - data.CONSTRAINTS_WITH_VALUE_LIST, - counts=(3, 1) -)) -def test_type_parameter_constraints_with_value_list(parser, macros, name, parameter_section, - constraint): - parser.parse_literal(MACROS[macros] + """ -tosca_definitions_version: tosca_simple_yaml_1_0 -{{- additions() }} -data_types: - MyDataType: - properties: - my_field: - type: string -{%- if name != 'data' %} -{{ name }}_types: -{%- endif %} - MyType: -{%- call parameters() %} -my_parameter: - type: MyDataType - constraints: - - {{ constraint }}: - - {my_field: string one} - - {my_field: string two} - - {my_field: string three} -{% endcall %} -""", dict(name=name, parameter_section=parameter_section, constraint=constraint)).assert_success() - - [email protected]('macros,name,parameter_section,constraint', matrix( - PERMUTATIONS, - data.CONSTRAINTS_WITH_VALUE_RANGE, - counts=(3, 1) -)) -def test_type_parameter_constraints_with_value_range(parser, macros, name, parameter_section, - constraint): - parser.parse_literal(MACROS[macros] + """ -tosca_definitions_version: tosca_simple_yaml_1_0 -{{- additions() }} -data_types: - MyDataType: - properties: - my_field: - type: string -{%- if name != 'data' %} -{{ name }}_types: -{%- endif %} - MyType: -{%- call parameters() %} -my_parameter: - type: MyDataType - constraints: - - {{ constraint }}: - - {my_field: string a} - - {my_field: string b} -{% endcall %} -""", dict(name=name, parameter_section=parameter_section, constraint=constraint)).assert_success() - - [email protected]('macros,name,parameter_section,constraint', matrix( - PERMUTATIONS, - data.CONSTRAINTS_WITH_VALUE_RANGE, - counts=(3, 1) -)) -def test_type_parameter_constraints_with_value_range_too_many(parser, macros, name, - parameter_section, constraint): - parser.parse_literal(MACROS[macros] + """ -tosca_definitions_version: tosca_simple_yaml_1_0 -{{- additions() }} -data_types: - MyDataType: - properties: - my_field: - type: string -{%- if name != 'data' %} -{{ name }}_types: -{%- endif %} - MyType: -{%- call parameters() %} -my_parameter: - type: MyDataType - constraints: - - {{ constraint }}: - - {my_field: string a} - - {my_field: string b} - - {my_field: string c} -{% endcall %} -""", dict(name=name, parameter_section=parameter_section, constraint=constraint)).assert_failure() - - [email protected]('macros,name,parameter_section,constraint', matrix( - PERMUTATIONS, - data.CONSTRAINTS_WITH_VALUE_RANGE, - counts=(3, 1) -)) -def test_type_parameter_constraints_with_value_range_bad(macros, parser, name, parameter_section, - constraint): - parser.parse_literal(MACROS[macros] + """ -tosca_definitions_version: tosca_simple_yaml_1_0 -{{- additions() }} -data_types: - MyDataType: - properties: - my_field: - type: string -{%- if name != 'data' %} -{{ name }}_types: -{%- endif %} - MyType: -{%- call parameters() %} -my_parameter: - type: MyDataType - constraints: - - {{ constraint }}: - - {my_field: string b} - - {my_field: string a} -{% endcall %} -""", dict(name=name, parameter_section=parameter_section, constraint=constraint)).assert_failure() - - [email protected]('macros,name,parameter_section', PERMUTATIONS) -def test_type_parameter_constraints_pattern(parser, macros, name, parameter_section): - parser.parse_literal(MACROS[macros] + """ -tosca_definitions_version: tosca_simple_yaml_1_0 -{{- additions() }} -{{ name }}_types: - MyType: -{%- call parameters() %} -my_parameter: - type: string - constraints: - - pattern: ^pattern$ -{% endcall %} -""", dict(name=name, parameter_section=parameter_section)).assert_success() - - [email protected]('macros,name,parameter_section', PERMUTATIONS) -def test_type_parameter_constraints_pattern_bad(parser, macros, name, parameter_section): - parser.parse_literal(MACROS[macros] + """ -tosca_definitions_version: tosca_simple_yaml_1_0 -{{- additions() }} -{{ name }}_types: - MyType: -{%- call parameters() %} -my_parameter: - type: string - constraints: - - pattern: ( -{% endcall %} -""", dict(name=name, parameter_section=parameter_section)).assert_failure() - - [email protected]('macros,name,parameter_section,constraint', matrix( - PERMUTATIONS, - data.CONSTRAINTS_WITH_VALUE_NON_NEGATIVE_INT, - counts=(3, 1) -)) -def test_type_parameter_constraints_with_value_integer(parser, macros, name, parameter_section, - constraint): - parser.parse_literal(MACROS[macros] + """ -tosca_definitions_version: tosca_simple_yaml_1_0 -{{- additions() }} -{{ name }}_types: - MyType: -{%- call parameters() %} -my_parameter: - type: string - constraints: - - {{ constraint }}: 1 -{% endcall %} -""", dict(name=name, parameter_section=parameter_section, constraint=constraint)).assert_success() - - [email protected]('macros,name,parameter_section,constraint', matrix( - PERMUTATIONS, - data.CONSTRAINTS_WITH_VALUE_NON_NEGATIVE_INT, - counts=(3, 1) -)) -def test_type_parameter_constraints_with_value_integer_bad(parser, macros, name, parameter_section, - constraint): - parser.parse_literal(MACROS[macros] + """ -tosca_definitions_version: tosca_simple_yaml_1_0 -{{- additions() }} -{{ name }}_types: - MyType: -{%- call parameters() %} -my_parameter: - type: string - constraints: - - {{ constraint }}: -1 -{% endcall %} -""", dict(name=name, parameter_section=parameter_section, constraint=constraint)).assert_failure() - - -# Unicode - [email protected]('macros,name,parameter_section', PERMUTATIONS) -def test_type_parameter_constraints_pattern_unicode(parser, macros, name, parameter_section): - parser.parse_literal(MACROS[macros] + """ -tosca_definitions_version: tosca_simple_yaml_1_0 -{{- additions() }} -{{ name }}_types: - é¡å: -{%- call parameters() %} -忏: - type: string - constraints: - - pattern: ^模å¼$ -{% endcall %} -""", dict(name=name, parameter_section=parameter_section)).assert_success()
