Repository: incubator-ariatosca Updated Branches: refs/heads/ARIA-1-parser-test-suite 0377542a3 -> 7c1123ff2
More template tests * Ensure that primitive fields will not allow "null" value Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/7c1123ff Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/7c1123ff Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/7c1123ff Branch: refs/heads/ARIA-1-parser-test-suite Commit: 7c1123ff233d56a5b72de8fff05058f175236b2a Parents: 0377542 Author: Tal Liron <[email protected]> Authored: Mon Sep 18 16:15:24 2017 -0500 Committer: Tal Liron <[email protected]> Committed: Mon Sep 18 16:15:24 2017 -0500 ---------------------------------------------------------------------- aria/parser/consumption/presentation.py | 1 + aria/parser/presentation/fields.py | 13 +- aria/parser/presentation/utils.py | 4 +- aria/parser/reading/yaml.py | 30 +- .../aria_extension_tosca/simple_v1_0/data.py | 9 +- .../simple_v1_0/templates/test_group.py | 30 +- .../templates/test_policy_template.py | 30 +- .../templates/test_template_interface.py | 598 +++++++++++++++++++ .../templates/test_template_parameters.py | 80 ++- .../simple_v1_0/templates/test_templates.py | 47 +- .../templates/test_topology_template.py | 35 +- .../simple_v1_0/test_imports.py | 45 +- .../simple_v1_0/test_metadata.py | 52 +- .../simple_v1_0/test_service_template.py | 31 + .../types/common/test_type_interfaces.py | 34 +- .../types/common/test_type_parameters.py | 116 +++- .../simple_v1_0/types/common/test_types.py | 38 +- .../node_types/test_node_type_capabilities.py | 58 +- .../test_node_type_relationship_interfaces.py | 64 +- .../node_types/test_node_type_requirements.py | 40 +- .../simple_v1_0/types/test_capability_type.py | 22 +- .../simple_v1_0/types/test_group_type.py | 22 +- .../simple_v1_0/types/test_interface_type.py | 44 +- .../simple_v1_0/types/test_policy_type.py | 22 +- .../simple_v1_0/types/test_relationship_type.py | 22 +- tests/requirements.txt | 3 +- 26 files changed, 1177 insertions(+), 313 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7c1123ff/aria/parser/consumption/presentation.py ---------------------------------------------------------------------- diff --git a/aria/parser/consumption/presentation.py b/aria/parser/consumption/presentation.py index 6d34ee1..8f99065 100644 --- a/aria/parser/consumption/presentation.py +++ b/aria/parser/consumption/presentation.py @@ -48,6 +48,7 @@ class Read(Consumer): imported_presentations = None if self.context.presentation.threads == 1: + # BlockingExecutor is much faster for the single-threaded case executor = BlockingExecutor(print_exceptions=self.context.presentation.print_exceptions) else: executor = FixedThreadPoolExecutor(size=self.context.presentation.threads, http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7c1123ff/aria/parser/presentation/fields.py ---------------------------------------------------------------------- diff --git a/aria/parser/presentation/fields.py b/aria/parser/presentation/fields.py index f9ecbbc..835c9ba 100644 --- a/aria/parser/presentation/fields.py +++ b/aria/parser/presentation/fields.py @@ -488,6 +488,9 @@ class Field(object): if is_short_form_field and not is_dict: # Handle short form value = raw + if value is None: + # An explicit null + value = NULL elif is_dict: if self.name in raw: value = raw[self.name] @@ -558,8 +561,8 @@ class Field(object): # primitive def _get_primitive(self, presentation, raw, value, context): - if (self.cls is not None and not isinstance(value, self.cls) - and value is not None and value is not NULL): + if (self.cls is not None) and (not isinstance(value, self.cls)) \ + and (value is not None): try: return self._coerce_primitive(value, context) except ValueError as e: @@ -588,6 +591,8 @@ class Field(object): primitive_list = [] for i, _ in enumerate(value): primitive = value[i] + if primitive is None: + primitive = NULL try: primitive = self._coerce_primitive(primitive, context) except ValueError as e: @@ -627,6 +632,8 @@ class Field(object): context = Field._get_context() primitive_dict = OrderedDict() for k, v in value.iteritems(): + if v is None: + v = NULL try: primitive_dict[k] = self._coerce_primitive(v, context) except ValueError as e: @@ -736,6 +743,8 @@ class Field(object): primitive_dict = OrderedDict() for k, v in raw.iteritems(): if k not in presentation.FIELDS: + if v is None: + v = NULL try: primitive_dict[k] = self._coerce_primitive(v, context) except ValueError as e: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7c1123ff/aria/parser/presentation/utils.py ---------------------------------------------------------------------- diff --git a/aria/parser/presentation/utils.py b/aria/parser/presentation/utils.py index 5041aa6..b805299 100644 --- a/aria/parser/presentation/utils.py +++ b/aria/parser/presentation/utils.py @@ -56,7 +56,7 @@ def validate_primitive(value, cls, coerce=False): :raises ValueError: if not a primitive type or if coercion failed. """ - if (cls is not None) and (value is not None) and (value is not NULL): + if (cls is not None) and (value is not None): if (cls is unicode) or (cls is str): # These two types are interchangeable valid = isinstance(value, basestring) elif cls is int: @@ -66,6 +66,8 @@ def validate_primitive(value, cls, coerce=False): valid = isinstance(value, cls) if not valid: if coerce: + if value is NULL: + value = None value = cls(value) else: raise ValueError(u'not a "{0}": {1}'.format(full_type_name(cls), safe_repr(value))) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7c1123ff/aria/parser/reading/yaml.py ---------------------------------------------------------------------- diff --git a/aria/parser/reading/yaml.py b/aria/parser/reading/yaml.py index f5a9d6f..7302373 100644 --- a/aria/parser/reading/yaml.py +++ b/aria/parser/reading/yaml.py @@ -16,9 +16,14 @@ from ...utils.collections import OrderedDict from .reader import Reader from .locator import Locator from .exceptions import ReaderSyntaxError -from .locator import LocatableString, LocatableInt, LocatableFloat +from .locator import (LocatableString, LocatableInt, LocatableFloat) -# Add our types to ruamel.yaml + +MERGE_TAG = u'tag:yaml.org,2002:merge' +MAP_TAG = u'tag:yaml.org,2002:map' + + +# Add our types to RoundTripRepresenter yaml.representer.RoundTripRepresenter.add_representer( LocatableString, yaml.representer.RoundTripRepresenter.represent_unicode) yaml.representer.RoundTripRepresenter.add_representer( @@ -26,8 +31,15 @@ yaml.representer.RoundTripRepresenter.add_representer( yaml.representer.RoundTripRepresenter.add_representer( LocatableFloat, yaml.representer.RoundTripRepresenter.represent_float) -MERGE_TAG = u'tag:yaml.org,2002:merge' -MAP_TAG = u'tag:yaml.org,2002:map' + +def construct_yaml_map(self, node): + data = OrderedDict() + yield data + value = self.construct_mapping(node) + data.update(value) + + +yaml.constructor.SafeConstructor.add_constructor(MAP_TAG, construct_yaml_map) class YamlLocator(Locator): @@ -60,16 +72,6 @@ class YamlLocator(Locator): locator.add_children(node) -def construct_yaml_map(self, node): - data = OrderedDict() - yield data - value = self.construct_mapping(node) - data.update(value) - - -yaml.constructor.SafeConstructor.add_constructor(MAP_TAG, construct_yaml_map) - - class YamlReader(Reader): """ ARIA YAML reader. http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7c1123ff/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 1fc808c..76205eb 100644 --- a/tests/extensions/aria_extension_tosca/simple_v1_0/data.py +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/data.py @@ -17,8 +17,9 @@ # Keywords -TYPE_NAMES = ('artifact', 'data', 'capability', 'interface', 'relationship', 'node', 'group', - 'policy') +TYPE_NAMES_NO_UNSUPPORTED_FIELDS = ('artifact', 'data', 'capability', 'relationship', 'node', + 'group', 'policy') +TYPE_NAMES = TYPE_NAMES_NO_UNSUPPORTED_FIELDS + ('interface',) TYPE_NAME_PLURAL = { 'artifact': 'artifacts', 'data': 'datatypes', @@ -32,6 +33,7 @@ TYPE_NAME_PLURAL = { PRIMITIVE_TYPE_NAMES = ('string', 'integer', 'float', 'boolean') PARAMETER_SECTION_NAMES = ('properties', 'attributes') TEMPLATE_NAMES = ('node', 'group', 'relationship', 'policy') +TEMPLATE_WITH_INTERFACE_NAMES = ('node', 'group', 'relationship') TEMPLATE_NAME_SECTIONS = { 'node': 'node_templates', 'group': 'groups', @@ -77,8 +79,9 @@ 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 = ('123', '0.123', '[]', '{}') +NOT_A_STRING = ('null', '123', '0.123', '[]', '{}') NOT_A_RANGE = NOT_A_LIST + ( '[]', '[ 1 ]', '[ 1, 2, 3 ]', '[ 1, 1 ]', '[ 2, 1 ]', http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7c1123ff/tests/extensions/aria_extension_tosca/simple_v1_0/templates/test_group.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/templates/test_group.py b/tests/extensions/aria_extension_tosca/simple_v1_0/templates/test_group.py index 56eb35c..5a784c3 100644 --- a/tests/extensions/aria_extension_tosca/simple_v1_0/templates/test_group.py +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/templates/test_group.py @@ -126,7 +126,22 @@ topology_template: """).assert_failure() -def test_group_members_unicode(parser): +def test_group_members_unknown(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +group_types: + MyType: {} +topology_template: + groups: + my_policy: + type: MyType + members: [ unknown ] +""").assert_failure() + + +# Unicode + +def test_group_unicode(parser): parser.parse_literal(""" tosca_definitions_version: tosca_simple_yaml_1_0 node_types: @@ -143,16 +158,3 @@ topology_template: type: é¡å members: [ ç¯é» ] """).assert_success() - - -def test_group_members_unknown(parser): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -group_types: - MyType: {} -topology_template: - groups: - my_policy: - type: MyType - members: [ unknown ] -""").assert_failure() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7c1123ff/tests/extensions/aria_extension_tosca/simple_v1_0/templates/test_policy_template.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/templates/test_policy_template.py b/tests/extensions/aria_extension_tosca/simple_v1_0/templates/test_policy_template.py index 598deaf..6ad6317 100644 --- a/tests/extensions/aria_extension_tosca/simple_v1_0/templates/test_policy_template.py +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/templates/test_policy_template.py @@ -238,7 +238,22 @@ topology_template: """).assert_success() -def test_policy_template_targets_unicode(parser): +def test_policy_template_targets_unknown(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +policy_types: + MyType: {} +topology_template: + policies: + my_policy: + type: MyType + targets: [ unknown ] +""").assert_failure() + + +# Unicode + +def test_policy_template_unicode(parser): parser.parse_literal(""" tosca_definitions_version: tosca_simple_yaml_1_0 node_types: @@ -255,16 +270,3 @@ topology_template: type: é¡å targets: [ ç¯é» ] """).assert_success() - - -def test_policy_template_targets_unknown(parser): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -policy_types: - MyType: {} -topology_template: - policies: - my_policy: - type: MyType - targets: [ unknown ] -""").assert_failure() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7c1123ff/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 new file mode 100644 index 0000000..710d802 --- /dev/null +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/templates/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/7c1123ff/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 index b503710..913000f 100644 --- 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 @@ -21,7 +21,64 @@ import pytest from .. import data -# Required properties +# 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() + @pytest.mark.parametrize('name,type_name', itertools.product( data.TEMPLATE_NAMES, @@ -343,3 +400,24 @@ topology_template: - {} """, 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/7c1123ff/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 index abbc6a4..1878990 100644 --- 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 @@ -25,28 +25,27 @@ from .. import data @pytest.mark.parametrize('name,value', itertools.product( data.TEMPLATE_NAMES, - data.NOT_A_DICT + data.NOT_A_STRING )) -def test_template_section_wrong_yaml_type(parser, name, value): +def test_template_type_wrong_yaml_type(parser, name, value): parser.parse_literal(""" tosca_definitions_version: tosca_simple_yaml_1_0 topology_template: - {{ section }}: {{ value }} + {{ section }}: + my_template: + type: {{ value }} """, dict(section=data.TEMPLATE_NAME_SECTIONS[name], value=value)).assert_failure() [email protected]('name,value', itertools.product( - data.TEMPLATE_NAMES, - data.NOT_A_STRING -)) -def test_template_type_wrong_yaml_type(parser, name, value): [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: - type: {{ value }} -""", dict(section=data.TEMPLATE_NAME_SECTIONS[name], value=value)).assert_failure() + unsupported: {} +""", dict(section=data.TEMPLATE_NAME_SECTIONS[name])).assert_failure() # Common fields @@ -66,36 +65,38 @@ topology_template: @pytest.mark.parametrize('name', data.TEMPLATE_NAMES) -def test_template_fields_unicode(parser, name): +def test_template_of_unknown_type(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() + my_template: + type: UnknownType +""", dict(section=data.TEMPLATE_NAME_SECTIONS[name])).assert_failure() @pytest.mark.parametrize('name', data.TEMPLATE_NAMES) -def test_template_of_unknown_type(parser, name): +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: UnknownType + type: null """, dict(section=data.TEMPLATE_NAME_SECTIONS[name])).assert_failure() +# Unicode + @pytest.mark.parametrize('name', data.TEMPLATE_NAMES) -def test_template_of_null_type(parser, name): +def test_template_unicode(parser, name): parser.parse_literal(""" tosca_definitions_version: tosca_simple_yaml_1_0 +{{ name }}_types: + é¡å: {} topology_template: {{ section }}: - my_template: - type: null -""", dict(section=data.TEMPLATE_NAME_SECTIONS[name])).assert_failure() + 模æ¿: + type: é¡å + description: æè¿° +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name])).assert_success() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7c1123ff/tests/extensions/aria_extension_tosca/simple_v1_0/templates/test_topology_template.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/templates/test_topology_template.py b/tests/extensions/aria_extension_tosca/simple_v1_0/templates/test_topology_template.py index d2fcaf4..0beed88 100644 --- a/tests/extensions/aria_extension_tosca/simple_v1_0/templates/test_topology_template.py +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/templates/test_topology_template.py @@ -14,6 +14,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +import itertools + import pytest from .. import data @@ -29,6 +31,14 @@ topology_template: {{ value }} """, dict(value=value)).assert_failure() +def test_topology_template_unsupported_field(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +topology_template: + unsupported: {} +""").assert_failure() + + def test_topology_template_empty(parser): parser.parse_literal(""" tosca_definitions_version: tosca_simple_yaml_1_0 @@ -36,6 +46,27 @@ topology_template: {} """).assert_success() [email protected]('name,value', itertools.product( + data.TEMPLATE_NAMES, + data.NOT_A_DICT +)) +def test_topology_template_template_section_wrong_yaml_type(parser, name, value): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +topology_template: + {{ section }}: {{ value }} +""", dict(section=data.TEMPLATE_NAME_SECTIONS[name], value=value)).assert_failure() + + [email protected]('name', data.TEMPLATE_NAMES) +def test_topology_template_template_section_empty(parser, name): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +topology_template: + {{ section }}: {} +""", dict(section=data.TEMPLATE_NAME_SECTIONS[name])).assert_success() + + def test_topology_template_fields(parser): parser.parse_literal(""" tosca_definitions_version: tosca_simple_yaml_1_0 @@ -48,7 +79,9 @@ topology_template: """).assert_success() -def test_topology_template_fields_unicode(parser): +# Unicode + +def test_topology_template_unicode(parser): parser.parse_literal(""" tosca_definitions_version: tosca_simple_yaml_1_0 node_types: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7c1123ff/tests/extensions/aria_extension_tosca/simple_v1_0/test_imports.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/test_imports.py b/tests/extensions/aria_extension_tosca/simple_v1_0/test_imports.py index 0087f96..c098c8f 100644 --- a/tests/extensions/aria_extension_tosca/simple_v1_0/test_imports.py +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/test_imports.py @@ -60,6 +60,13 @@ tosca_definitions_version: tosca_simple_yaml_1_0 imports: {{ value }} """, dict(value=value)).assert_failure() +def test_imports_unsupported_field(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +imports: + unsupported: {} +""").assert_failure() + def test_imports_empty(parser): parser.parse_literal(""" @@ -70,7 +77,7 @@ imports: [] # Variants -def test_import_single_short_form(parser, repository): +def test_imports_short_form(parser, repository): parser.parse_literal(""" tosca_definitions_version: tosca_simple_yaml_1_0 imports: @@ -82,19 +89,7 @@ topology_template: """, dict(repository=repository)).assert_success() -def test_import_single_short_form_unicode(parser, repository): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -imports: - - {{ repository }}/imports/ç¯é»é¡å.yaml -topology_template: - node_templates: - my_node: - type: é¡å -""", dict(repository=repository)).assert_success() - - -def test_import_single_long_form(parser, repository): +def test_imports_long_form(parser, repository): parser.parse_literal(""" tosca_definitions_version: tosca_simple_yaml_1_0 imports: @@ -107,7 +102,7 @@ topology_template: @pytest.mark.skip(reason='not yet supported') -def test_import_single_repository(parser, repository): +def test_imports_repository(parser, repository): parser.parse_literal(""" tosca_definitions_version: tosca_simple_yaml_1_0 repositories: @@ -124,7 +119,7 @@ topology_template: @pytest.mark.skip(reason='not yet supported') -def test_import_single_namespace(parser, repository): +def test_imports_namespace(parser, repository): parser.parse_literal(""" tosca_definitions_version: tosca_simple_yaml_1_0 imports: @@ -140,7 +135,7 @@ topology_template: # Bad imports -def test_import_not_found(parser): +def test_imports_not_found(parser): parser.parse_literal(""" tosca_definitions_version: tosca_simple_yaml_1_0 imports: @@ -148,7 +143,7 @@ imports: """).assert_failure() -def test_import_bad(parser, repository): +def test_imports_bad(parser, repository): parser.parse_literal(""" tosca_definitions_version: tosca_simple_yaml_1_0 imports: @@ -158,3 +153,17 @@ topology_template: my_node: type: MyNode """, dict(repository=repository)).assert_failure() + + +# Unicode + +def test_imports_unicode(parser, repository): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +imports: + - {{ repository }}/imports/ç¯é»é¡å.yaml +topology_template: + node_templates: + my_node: + type: é¡å +""", dict(repository=repository)).assert_success() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7c1123ff/tests/extensions/aria_extension_tosca/simple_v1_0/test_metadata.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/test_metadata.py b/tests/extensions/aria_extension_tosca/simple_v1_0/test_metadata.py index 1a109c1..74e550b 100644 --- a/tests/extensions/aria_extension_tosca/simple_v1_0/test_metadata.py +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/test_metadata.py @@ -21,6 +21,8 @@ import pytest from . import data +NORMATIVE_FIELD_NAMES = ('template_name', 'template_author', 'template_version') + # Syntax @pytest.mark.parametrize('value', data.NOT_A_DICT) @@ -31,8 +33,17 @@ metadata: {{ value }} """, dict(value=value)).assert_failure() +def test_metadata_empty(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +metadata: {} +""").assert_success() + + +# Fields + @pytest.mark.parametrize('field,value', itertools.product( - ('template_name', 'template_author', 'template_version'), + NORMATIVE_FIELD_NAMES, data.NOT_A_STRING )) def test_metadata_normative_fields_wrong_yaml_type(parser, field, value): @@ -52,15 +63,6 @@ metadata: """, dict(value=value)).assert_failure() -def test_metadata_empty(parser): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -metadata: {} -""").assert_success() - - -# Normative fields - @pytest.mark.parametrize('value', data.GOOD_VERSIONS) def test_metadata_normative_template_version(parser, value): parser.parse_literal(""" @@ -79,35 +81,9 @@ metadata: """, dict(value=value)).assert_failure() -# Non-normative fields - -def test_metadata_with_non_normative_fields(parser): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -metadata: - template_name: name - template_author: author - template_version: 1.0.0.alpha-10 - non_normative1: non_normative1 - non_normative2: non_normative2 - non_normative3: non_normative3 -""").assert_success() - - -def test_metadata_with_non_normative_fields_nulls(parser): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -metadata: - template_name: null - template_author: null - template_version: null - non_normative1: null - non_normative2: null - non_normative3: null -""").assert_success() - +# Unicode -def test_metadata_with_non_normative_fields_unicode(parser): +def test_metadata_unicode(parser): parser.parse_literal(""" tosca_definitions_version: tosca_simple_yaml_1_0 metadata: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7c1123ff/tests/extensions/aria_extension_tosca/simple_v1_0/test_service_template.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/test_service_template.py b/tests/extensions/aria_extension_tosca/simple_v1_0/test_service_template.py new file mode 100644 index 0000000..736c7fe --- /dev/null +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/test_service_template.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +# Syntax + +def test_service_template_unsupported_field(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +unsupported: {} +""").assert_failure() + + +def test_service_template_dsl_definitions(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +dsl_definitions: {} +""").assert_success() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7c1123ff/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 077958b..307b40c 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 @@ -77,22 +77,6 @@ interface_types: """, dict(name=name)).assert_success() [email protected]('name', TYPE_NAMES) -def test_type_interface_fields_unicode(parser, name): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -interface_types: - é¡å: {} -{{ name }}_types: - é¡å: - interfaces: - æ¥å£: - type: é¡å - æè¡: - implementation: å±¥è¡ -""", dict(name=name)).assert_success() - - # Type @pytest.mark.parametrize('name', TYPE_NAMES) @@ -436,3 +420,21 @@ interface_types: my_input: type: MyType1 """, dict(name=name)).assert_failure() + + +# Unicode + [email protected]('name', TYPE_NAMES) +def test_type_interface_unicode(parser, name): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +interface_types: + é¡å: {} +{{ name }}_types: + é¡å: + interfaces: + æ¥å£: + type: é¡å + æè¡: + implementation: å±¥è¡ +""", dict(name=name)).assert_success() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7c1123ff/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 6449b87..aa2eda6 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 @@ -21,34 +21,83 @@ import pytest from ... import data -# Fields +# Syntax + [email protected]( + 'name,parameter_section,value', + ((s[0], s[1], v) + for s, v in itertools.product(data.PARAMETER_SECTIONS, data.NOT_A_DICT)) +) +def test_type_parameter_section_wrong_yaml_type(parser, name, parameter_section, value): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +{{ name }}_types: + MyType: + {{ parameter_section }}: {{ value }} +""", dict(name=name, parameter_section=parameter_section, value=value)).assert_failure() + @pytest.mark.parametrize('name,parameter_section', data.PARAMETER_SECTIONS) -def test_type_parameter_fields(parser, name, parameter_section): +def test_type_parameter_section_empty(parser, name, parameter_section): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +{{ name }}_types: + MyType: + {{ parameter_section }}: {} +""", dict(name=name, parameter_section=parameter_section)).assert_success() + + [email protected]( + 'name,parameter_section,value', + ((s[0], s[1], v) + for s, v in itertools.product(data.PARAMETER_SECTIONS, data.NOT_A_DICT)) +) +def test_type_parameter_wrong_yaml_type(parser, name, parameter_section, value): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +{{ name }}_types: + MyType: + {{ parameter_section }}: + my_parameter: {{ value }} +""", dict(name=name, parameter_section=parameter_section, value=value)).assert_failure() + + [email protected]('name,parameter_section', data.PARAMETER_SECTIONS) +def test_type_parameter_empty(parser, name, parameter_section): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +{{ name }}_types: + MyType: + {{ parameter_section }}: + my_parameter: {} # type is required +""", dict(name=name, parameter_section=parameter_section)).assert_failure() + + [email protected]('name,parameter_section', data.PARAMETER_SECTIONS) +def test_type_parameter_unsupported_field(parser, name, parameter_section): parser.parse_literal(""" tosca_definitions_version: tosca_simple_yaml_1_0 {{ name }}_types: MyType: {{ parameter_section }}: my_parameter: - type: string - description: a description - default: a value - status: supported -""", dict(name=name, parameter_section=parameter_section)).assert_success() + unsupported_field: {} +""", dict(name=name, parameter_section=parameter_section)).assert_failure() + +# Fields @pytest.mark.parametrize('name,parameter_section', data.PARAMETER_SECTIONS) -def test_type_parameter_fields_unicode(parser, name, parameter_section): +def test_type_parameter_fields(parser, name, parameter_section): parser.parse_literal(""" tosca_definitions_version: tosca_simple_yaml_1_0 {{ name }}_types: MyType: {{ parameter_section }}: - 忏: + my_parameter: type: string - description: æè¿° - default: å¼ + description: a description + default: a value status: supported """, dict(name=name, parameter_section=parameter_section)).assert_success() @@ -279,20 +328,6 @@ tosca_definitions_version: tosca_simple_yaml_1_0 @pytest.mark.parametrize('name,parameter_section', data.PARAMETER_WITH_CONSTRAINTS_SECTIONS) -def test_type_parameter_constraints_pattern_unicode(parser, name, parameter_section): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -{{ name }}_types: - é¡å: - {{ parameter_section }}: - 忏: - type: string - constraints: - - pattern: ^模å¼$ -""", dict(name=name, parameter_section=parameter_section)).assert_success() - - [email protected]('name,parameter_section', data.PARAMETER_WITH_CONSTRAINTS_SECTIONS) def test_type_parameter_constraints_pattern_bad(parser, name, parameter_section): parser.parse_literal(""" tosca_definitions_version: tosca_simple_yaml_1_0 @@ -427,3 +462,34 @@ data_types: my_parameter: type: MyDataType1 """, dict(name=name, parameter_section=parameter_section)).assert_failure() + + +# Unicode + [email protected]('name,parameter_section', data.PARAMETER_SECTIONS) +def test_type_parameter_unicode(parser, name, parameter_section): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +{{ name }}_types: + MyType: + {{ parameter_section }}: + 忏: + type: string + description: æè¿° + default: å¼ + status: supported +""", dict(name=name, parameter_section=parameter_section)).assert_success() + + [email protected]('name,parameter_section', data.PARAMETER_WITH_CONSTRAINTS_SECTIONS) +def test_type_parameter_constraints_pattern_unicode(parser, name, parameter_section): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +{{ name }}_types: + é¡å: + {{ parameter_section }}: + 忏: + type: string + constraints: + - pattern: ^模å¼$ +""", dict(name=name, parameter_section=parameter_section)).assert_success() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7c1123ff/tests/extensions/aria_extension_tosca/simple_v1_0/types/common/test_types.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/types/common/test_types.py b/tests/extensions/aria_extension_tosca/simple_v1_0/types/common/test_types.py index 9e103ef..d46a322 100644 --- a/tests/extensions/aria_extension_tosca/simple_v1_0/types/common/test_types.py +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/types/common/test_types.py @@ -35,6 +35,16 @@ tosca_definitions_version: tosca_simple_yaml_1_0 """, dict(name=name, value=value)).assert_failure() [email protected]('name', data.TYPE_NAMES_NO_UNSUPPORTED_FIELDS) +def test_type_unsupported_field(parser, name): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +{{ name }}_types: + MyType: + unsupported: {} +""", dict(name=name)).assert_failure() + + @pytest.mark.parametrize('name', data.TYPE_NAMES) def test_type_empty(parser, name): parser.parse_literal(""" @@ -129,19 +139,6 @@ tosca_definitions_version: tosca_simple_yaml_1_0 """, dict(name=name)).assert_success() [email protected]('name', data.TYPE_NAMES) -def test_type_fields_unicode(parser, name): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -{{ name }}_types: - é¡åä¸: {} - é¡åäº: - derived_from: é¡åä¸ - version: 1.0.0.è© å調-10 - description: æè¿° -""", dict(name=name)).assert_success() - - @pytest.mark.parametrize('name,value', itertools.product( data.TYPE_NAMES, data.BAD_VERSIONS @@ -153,3 +150,18 @@ tosca_definitions_version: tosca_simple_yaml_1_0 MyType: version: {{ value }} """, dict(name=name, value=value)).assert_failure() + + +# Unicode + [email protected]('name', data.TYPE_NAMES) +def test_type_unicode(parser, name): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +{{ name }}_types: + é¡åä¸: {} + é¡åäº: + derived_from: é¡åä¸ + version: 1.0.0.è© å調-10 + description: æè¿° +""", dict(name=name)).assert_success() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7c1123ff/tests/extensions/aria_extension_tosca/simple_v1_0/types/node_types/test_node_type_capabilities.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/types/node_types/test_node_type_capabilities.py b/tests/extensions/aria_extension_tosca/simple_v1_0/types/node_types/test_node_type_capabilities.py index a247695..d3de459 100644 --- a/tests/extensions/aria_extension_tosca/simple_v1_0/types/node_types/test_node_type_capabilities.py +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/types/node_types/test_node_type_capabilities.py @@ -26,8 +26,6 @@ from ... import data def test_node_type_capability_wrong_yaml_type(parser, value): parser.parse_literal(""" tosca_definitions_version: tosca_simple_yaml_1_0 -capability_types: - MyType: {} node_types: MyType: capabilities: @@ -35,7 +33,7 @@ node_types: """, dict(value=value)).assert_failure() -def test_node_type_capability_empty(parser): +def test_node_type_capability_unsupported_field(parser): parser.parse_literal(""" tosca_definitions_version: tosca_simple_yaml_1_0 capability_types: @@ -43,6 +41,18 @@ capability_types: node_types: MyType: capabilities: + my_capability: + type: MyType + unsupported: {} +""").assert_failure() + + +def test_node_type_capability_empty(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +node_types: + MyType: + capabilities: my_capability: {} # "type" is required """).assert_failure() @@ -151,26 +161,6 @@ node_types: """, dict(parameter_section=parameter_section)).assert_success() [email protected]('parameter_section', data.PARAMETER_SECTION_NAMES) -def test_node_type_capability_parameter_fields_unicode(parser, parameter_section): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -capability_types: - é¡å: {} -node_types: - é¡å: - capabilities: - è½å: - type: é¡å - {{ parameter_section }}: - 忏: - type: string - description: æè¿° - default: å¼ - status: supported -""", dict(parameter_section=parameter_section)).assert_success() - - @pytest.mark.parametrize('parameter_section,value', itertools.product( data.PARAMETER_SECTION_NAMES, data.STATUSES @@ -392,3 +382,25 @@ node_types: type: MyType occurrences: {{ value }} """, dict(value=value)).assert_failure() + + +# Unicode + [email protected]('parameter_section', data.PARAMETER_SECTION_NAMES) +def test_node_type_capability_unicode(parser, parameter_section): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +capability_types: + é¡å: {} +node_types: + é¡å: + capabilities: + è½å: + type: é¡å + {{ parameter_section }}: + 忏: + type: string + description: æè¿° + default: å¼ + status: supported +""", dict(parameter_section=parameter_section)).assert_success() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7c1123ff/tests/extensions/aria_extension_tosca/simple_v1_0/types/node_types/test_node_type_relationship_interfaces.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/types/node_types/test_node_type_relationship_interfaces.py b/tests/extensions/aria_extension_tosca/simple_v1_0/types/node_types/test_node_type_relationship_interfaces.py index 9db28dc..c369328 100644 --- a/tests/extensions/aria_extension_tosca/simple_v1_0/types/node_types/test_node_type_relationship_interfaces.py +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/types/node_types/test_node_type_relationship_interfaces.py @@ -49,6 +49,20 @@ node_types: """, dict(value=value)).assert_failure() +def test_node_type_relationship_interface_unsupported_field(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +capability_types: + MyType: {} +node_types: + MyType: + requirements: + - my_requirement: + capability: MyType + unsupported: {} +""").assert_failure() + + def test_node_type_relationship_interface_empty(parser): parser.parse_literal(""" tosca_definitions_version: tosca_simple_yaml_1_0 @@ -93,30 +107,6 @@ node_types: """).assert_success() -def test_node_type_relationship_interface_fields_unicode(parser): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -capability_types: - é¡å: {} -relationship_types: - é¡å: {} -interface_types: - é¡å: {} -node_types: - é¡å: - requirements: - - éæ±: - capability: é¡å - relationship: - type: é¡å - interfaces: - æ¥å£: - type: é¡å - æè¡: - implementation: å±¥è¡ -""").assert_success() - - # Type def test_node_type_relationship_interface_type_override1(parser): @@ -650,3 +640,29 @@ node_types: my_input: type: MyType1 """).assert_failure() + + +# Unicode + +def test_node_type_relationship_interface_unicode(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +capability_types: + é¡å: {} +relationship_types: + é¡å: {} +interface_types: + é¡å: {} +node_types: + é¡å: + requirements: + - éæ±: + capability: é¡å + relationship: + type: é¡å + interfaces: + æ¥å£: + type: é¡å + æè¡: + implementation: å±¥è¡ +""").assert_success() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7c1123ff/tests/extensions/aria_extension_tosca/simple_v1_0/types/node_types/test_node_type_requirements.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/types/node_types/test_node_type_requirements.py b/tests/extensions/aria_extension_tosca/simple_v1_0/types/node_types/test_node_type_requirements.py index a43a994..2f3e6a5 100644 --- a/tests/extensions/aria_extension_tosca/simple_v1_0/types/node_types/test_node_type_requirements.py +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/types/node_types/test_node_type_requirements.py @@ -61,25 +61,6 @@ node_types: """).assert_success() -def test_node_type_requirement_fields_unicode(parser): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -capability_types: - é¡å: {} -relationship_types: - é¡å: {} -node_types: - é¡å: - requirements: - - éæ±: - capability: é¡å - node: é¡å - relationship: - type: é¡å - occurrences: [ 0, UNBOUNDED ] -""").assert_success() - - # Capability def test_node_type_requirement_capability_short_form(parser): @@ -259,3 +240,24 @@ node_types: type: MyType occurrences: {{ value }} """, dict(value=value)).assert_failure() + + +# Unicode + +def test_node_type_requirement_unicode(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +capability_types: + é¡å: {} +relationship_types: + é¡å: {} +node_types: + é¡å: + requirements: + - éæ±: + capability: é¡å + node: é¡å + relationship: + type: é¡å + occurrences: [ 0, UNBOUNDED ] +""").assert_success() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7c1123ff/tests/extensions/aria_extension_tosca/simple_v1_0/types/test_capability_type.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/types/test_capability_type.py b/tests/extensions/aria_extension_tosca/simple_v1_0/types/test_capability_type.py index b35ea28..134bbce 100644 --- a/tests/extensions/aria_extension_tosca/simple_v1_0/types/test_capability_type.py +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/types/test_capability_type.py @@ -62,7 +62,18 @@ capability_types: """).assert_success() -def test_capability_type_valid_source_types_unicode(parser): +def test_capability_type_valid_source_types_unknown(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +capability_types: + MyType: + valid_source_types: [ UnknownType ] +""").assert_failure() + + +# Unicode + +def test_capability_type_unicode(parser): parser.parse_literal(""" tosca_definitions_version: tosca_simple_yaml_1_0 node_types: @@ -72,12 +83,3 @@ capability_types: é¡å: valid_source_types: [ é¡åä¸, é¡åäº ] """).assert_success() - - -def test_capability_type_valid_source_types_unknown(parser): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -capability_types: - MyType: - valid_source_types: [ UnknownType ] -""").assert_failure() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7c1123ff/tests/extensions/aria_extension_tosca/simple_v1_0/types/test_group_type.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/types/test_group_type.py b/tests/extensions/aria_extension_tosca/simple_v1_0/types/test_group_type.py index b48e2dd..9d11d68 100644 --- a/tests/extensions/aria_extension_tosca/simple_v1_0/types/test_group_type.py +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/types/test_group_type.py @@ -62,7 +62,18 @@ group_types: """).assert_success() -def test_group_type_members_unicode(parser): +def test_group_type_members_unknown(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +group_types: + MyType: + members: [ UnknownType ] +""").assert_failure() + + +# Unicode + +def test_group_type_unicode(parser): parser.parse_literal(""" tosca_definitions_version: tosca_simple_yaml_1_0 node_types: @@ -72,12 +83,3 @@ group_types: é¡å: members: [ é¡åä¸, é¡åäº ] """).assert_success() - - -def test_group_type_members_unknown(parser): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -group_types: - MyType: - members: [ UnknownType ] -""").assert_failure() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7c1123ff/tests/extensions/aria_extension_tosca/simple_v1_0/types/test_interface_type.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/types/test_interface_type.py b/tests/extensions/aria_extension_tosca/simple_v1_0/types/test_interface_type.py index 18e93d3..38669c0 100644 --- a/tests/extensions/aria_extension_tosca/simple_v1_0/types/test_interface_type.py +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/types/test_interface_type.py @@ -26,28 +26,6 @@ import pytest from .. import data -# Fields - -def test_interface_type_fields_unicode(parser): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -interface_types: - é¡å: - inputs: - è¼¸å ¥: - type: string - æè¡: - description: æè¿° - implementation: - primary: å±¥è¡ - dependencies: - - ä¾è³´ - inputs: - è¼¸å ¥: - type: string -""").assert_success() - - # Interface inputs def test_interface_type_inputs_add(parser): @@ -279,3 +257,25 @@ interface_types: my_input: type: MyType1 """).assert_failure() + + +# Unicode + +def test_interface_type_unicode(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +interface_types: + é¡å: + inputs: + è¼¸å ¥: + type: string + æè¡: + description: æè¿° + implementation: + primary: å±¥è¡ + dependencies: + - ä¾è³´ + inputs: + è¼¸å ¥: + type: string +""").assert_success() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7c1123ff/tests/extensions/aria_extension_tosca/simple_v1_0/types/test_policy_type.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/types/test_policy_type.py b/tests/extensions/aria_extension_tosca/simple_v1_0/types/test_policy_type.py index 97bf101..0f73a19 100644 --- a/tests/extensions/aria_extension_tosca/simple_v1_0/types/test_policy_type.py +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/types/test_policy_type.py @@ -100,7 +100,18 @@ policy_types: """).assert_success() -def test_policy_type_targets_unicode(parser): +def test_policy_type_targets_unknown(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +policy_types: + MyType: + targets: [ UnknownType ] +""").assert_failure() + + +# Unicode + +def test_policy_type_unicode(parser): parser.parse_literal(""" tosca_definitions_version: tosca_simple_yaml_1_0 node_types: @@ -110,12 +121,3 @@ policy_types: é¡å: targets: [ é¡åä¸, é¡åäº ] """).assert_success() - - -def test_policy_type_targets_unknown(parser): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -policy_types: - MyType: - targets: [ UnknownType ] -""").assert_failure() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7c1123ff/tests/extensions/aria_extension_tosca/simple_v1_0/types/test_relationship_type.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/types/test_relationship_type.py b/tests/extensions/aria_extension_tosca/simple_v1_0/types/test_relationship_type.py index b0d8ab0..b35406d 100644 --- a/tests/extensions/aria_extension_tosca/simple_v1_0/types/test_relationship_type.py +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/types/test_relationship_type.py @@ -62,7 +62,18 @@ relationship_types: """).assert_success() -def test_relationship_type_valid_target_types_unicode(parser): +def test_relationship_type_valid_target_types_unknown(parser): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +relationship_types: + MyType: + valid_target_types: [ UnknownType ] +""").assert_failure() + + +# Unicode + +def test_relationship_type_unicode(parser): parser.parse_literal(""" tosca_definitions_version: tosca_simple_yaml_1_0 capability_types: @@ -72,12 +83,3 @@ relationship_types: é¡å: valid_target_types: [ é¡åä¸, é¡åäº ] """).assert_success() - - -def test_relationship_type_valid_target_types_unknown(parser): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 -relationship_types: - MyType: - valid_target_types: [ UnknownType ] -""").assert_failure() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7c1123ff/tests/requirements.txt ---------------------------------------------------------------------- diff --git a/tests/requirements.txt b/tests/requirements.txt index f98ea97..fbc7124 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -14,10 +14,9 @@ testtools==2.3.0 fasteners==0.14.1 sh==1.12.14 tornado==4.3 # last release to support Python 2.6 -psutil==5.2.2 mock==2.0.0 pylint==1.6.5 # see ARIA-314 about upgrading to 1.7 -pytest==3.2.1 +pytest==3.2.2 pytest-cov==2.5.1 pytest-mock==1.6.2 pytest-xdist==1.20.0
