Repository: incubator-ariatosca Updated Branches: refs/heads/ARIA-180-convert-parameter-to-one-to-many 7ca7d0f48 -> b6d3c43ba (forced update)
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/b6d3c43b/tests/cli/test_service_templates.py ---------------------------------------------------------------------- diff --git a/tests/cli/test_service_templates.py b/tests/cli/test_service_templates.py index 7e86896..cc0150e 100644 --- a/tests/cli/test_service_templates.py +++ b/tests/cli/test_service_templates.py @@ -215,7 +215,7 @@ class TestServiceTemplatesInputs(TestCliBase): def test_inputs_existing_inputs(self, monkeypatch, mock_storage): monkeypatch.setattr(_Environment, 'model_storage', mock_storage) - input = mock_models.create_parameter(name='input1', value='value1') + input = mock_models.create_input(name='input1', value='value1') st = mock_models.create_service_template(inputs={'input1': input}) monkeypatch.setattr(mock_storage.service_template, 'get_by_name', mock.MagicMock(return_value=st)) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/b6d3c43b/tests/mock/models.py ---------------------------------------------------------------------- diff --git a/tests/mock/models.py b/tests/mock/models.py index 50aa340..56a6e3e 100644 --- a/tests/mock/models.py +++ b/tests/mock/models.py @@ -94,7 +94,7 @@ def create_service_with_dependencies(include_execution=False, service.executions = [execution] execution.id = '1' if include_input: - input = create_parameter(name='input1', value='value1') + input = create_input(name='input1', value='value1') service.inputs = {'input1': input} if include_node: node_template = create_node_template(service_template=service_template) @@ -110,7 +110,7 @@ def create_node_template_with_dependencies(include_node=False, include_property= service = create_service(service_template=service_template) create_node(dependency_node_template=node_template, service=service) if include_property: - node_template.properties = {'prop1': create_parameter(name='prop1', value='value1')} + node_template.properties = {'prop1': create_property(name='prop1', value='value1')} return node_template @@ -120,7 +120,7 @@ def create_node_with_dependencies(include_attribute=False): node_template.service_template.services[0] = create_service(node_template.service_template) node = create_node(node_template, node_template.service_template.services[0]) if include_attribute: - node.attributes['attribute1'] = models.Parameter.wrap('attribute1', 'value1') # pylint: disable=unsubscriptable-object + node.attributes['attribute1'] = models.Attribute.wrap('attribute1', 'value1') # pylint: disable=unsubscriptable-object return node @@ -227,7 +227,7 @@ def create_interface(service, interface_name, operation_name, operation_kwargs=N if operation_kwargs and operation_kwargs.get('arguments'): operation_kwargs['arguments'] = dict( - (argument_name, models.Parameter.wrap(argument_name, argument_value)) + (argument_name, models.Argument.wrap(argument_name, argument_value)) for argument_name, argument_value in operation_kwargs['arguments'].iteritems() if argument_value is not None) @@ -278,9 +278,16 @@ def create_plugin_specification(name='test_plugin', version='0.1'): ) -def create_parameter(name, value): - p = models.Parameter() - return p.wrap(name, value) +def _create_parameter(name, value, model_cls): + return model_cls.wrap(name, value) + + +def create_property(name, value): + return _create_parameter(name, value, model_cls=models.Property) + + +def create_input(name, value): + return _create_parameter(name, value, model_cls=models.Input) def _dictify(item): http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/b6d3c43b/tests/mock/topology.py ---------------------------------------------------------------------- diff --git a/tests/mock/topology.py b/tests/mock/topology.py index ab08dbd..9f0521f 100644 --- a/tests/mock/topology.py +++ b/tests/mock/topology.py @@ -28,8 +28,8 @@ def create_simple_topology_single_node(model_storage, create_operation): 'Standard', 'create', operation_kwargs=dict( function=create_operation, - arguments={'key': aria_models.Parameter.wrap('key', 'create'), - 'value': aria_models.Parameter.wrap('value', True)}) + arguments={'key': aria_models.Argument.wrap('key', 'create'), + 'value': aria_models.Argument.wrap('value', True)}) ) node_template.interface_templates[interface_template.name] = interface_template # pylint: disable=unsubscriptable-object @@ -39,8 +39,8 @@ def create_simple_topology_single_node(model_storage, create_operation): 'Standard', 'create', operation_kwargs=dict( function=create_operation, - arguments={'key': aria_models.Parameter.wrap('key', 'create'), - 'value': aria_models.Parameter.wrap('value', True)}) + arguments={'key': aria_models.Argument.wrap('key', 'create'), + 'value': aria_models.Argument.wrap('value', True)}) ) node.interfaces[interface.name] = interface # pylint: disable=unsubscriptable-object http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/b6d3c43b/tests/modeling/test_models.py ---------------------------------------------------------------------- diff --git a/tests/modeling/test_models.py b/tests/modeling/test_models.py index df3aebd..464f432 100644 --- a/tests/modeling/test_models.py +++ b/tests/modeling/test_models.py @@ -36,7 +36,12 @@ from aria.modeling.models import ( Relationship, NodeTemplate, Node, - Parameter, + Input, + Output, + Property, + Attribute, + Configuration, + Argument, Type ) @@ -622,7 +627,7 @@ class TestNodeHostAddress(object): service_template=storage.service_template.list()[0] ) if host_address: - kwargs['properties'] = {'host_address': Parameter.wrap('host_address', host_address)} + kwargs['properties'] = {'host_address': Property.wrap('host_address', host_address)} node = NodeTemplate(**kwargs) storage.node_template.put(node) return node @@ -640,7 +645,7 @@ class TestNodeHostAddress(object): if host_address is not None: host_address = host_address.value if host_address: - kwargs.setdefault('attributes', {})['ip'] = Parameter.wrap('ip', host_address) + kwargs.setdefault('attributes', {})['ip'] = Attribute.wrap('ip', host_address) if is_host: kwargs['host_fk'] = 1 elif host_fk: @@ -839,3 +844,41 @@ class TestType(object): assert super_type.hierarchy == [super_type, additional_type] assert sub_type.hierarchy == [sub_type, super_type, additional_type] + + +class TestParameter(object): + + MODELS_DERIVED_FROM_PARAMETER = (Input, Output, Property, Attribute, Configuration, Argument) + + @pytest.mark.parametrize( + 'is_valid, name, type_name, description', + [ + (False, 'name', 'int', []), + (False, 'name', [], 'desc'), + (False, [], 'type_name', 'desc'), + (True, 'name', 'type_name', 'desc'), + ] + ) + def test_derived_from_parameter_model_creation(self, empty_storage, is_valid, name, type_name, + description): + + for model_cls in self.MODELS_DERIVED_FROM_PARAMETER: + _test_model(is_valid=is_valid, + storage=empty_storage, + model_cls=model_cls, + model_kwargs=dict( + name=name, + type_name=type_name, + description=description, + _value={}) + ) + + def test_as_argument(self): + + for model_cls in self.MODELS_DERIVED_FROM_PARAMETER: + model = model_cls(name='name', + type_name='type_name', + description='description', + _value={}) + argument = model.as_argument() + assert isinstance(argument, Argument) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/b6d3c43b/tests/orchestrator/context/test_collection_instrumentation.py ---------------------------------------------------------------------- diff --git a/tests/orchestrator/context/test_collection_instrumentation.py b/tests/orchestrator/context/test_collection_instrumentation.py index 3ee5a44..1e6214a 100644 --- a/tests/orchestrator/context/test_collection_instrumentation.py +++ b/tests/orchestrator/context/test_collection_instrumentation.py @@ -15,7 +15,7 @@ import pytest -from aria.modeling.models import Parameter +from aria.modeling.models import Attribute from aria.orchestrator.context import collection_instrumentation @@ -28,7 +28,7 @@ class MockActor(object): class MockModel(object): def __init__(self): - self.parameter = type('MockModel', (object, ), {'model_cls': Parameter, + self.attribute = type('MockModel', (object, ), {'model_cls': Attribute, 'put': lambda *args, **kwargs: None, 'update': lambda *args, **kwargs: None})() @@ -57,16 +57,16 @@ class TestDict(CollectionInstrumentation): def test_keys(self, actor, dict_): dict_.update( { - 'key1': Parameter.wrap('key1', 'value1'), - 'key2': Parameter.wrap('key2', 'value2') + 'key1': Attribute.wrap('key1', 'value1'), + 'key2': Attribute.wrap('key2', 'value2') } ) assert sorted(dict_.keys()) == sorted(['key1', 'key2']) == sorted(actor.dict_.keys()) def test_values(self, actor, dict_): dict_.update({ - 'key1': Parameter.wrap('key1', 'value1'), - 'key2': Parameter.wrap('key1', 'value2') + 'key1': Attribute.wrap('key1', 'value1'), + 'key2': Attribute.wrap('key1', 'value2') }) assert (sorted(dict_.values()) == sorted(['value1', 'value2']) == @@ -74,34 +74,34 @@ class TestDict(CollectionInstrumentation): def test_items(self, dict_): dict_.update({ - 'key1': Parameter.wrap('key1', 'value1'), - 'key2': Parameter.wrap('key1', 'value2') + 'key1': Attribute.wrap('key1', 'value1'), + 'key2': Attribute.wrap('key1', 'value2') }) assert sorted(dict_.items()) == sorted([('key1', 'value1'), ('key2', 'value2')]) def test_iter(self, actor, dict_): dict_.update({ - 'key1': Parameter.wrap('key1', 'value1'), - 'key2': Parameter.wrap('key1', 'value2') + 'key1': Attribute.wrap('key1', 'value1'), + 'key2': Attribute.wrap('key1', 'value2') }) assert sorted(list(dict_)) == sorted(['key1', 'key2']) == sorted(actor.dict_.keys()) def test_bool(self, dict_): assert not dict_ dict_.update({ - 'key1': Parameter.wrap('key1', 'value1'), - 'key2': Parameter.wrap('key1', 'value2') + 'key1': Attribute.wrap('key1', 'value1'), + 'key2': Attribute.wrap('key1', 'value2') }) assert dict_ def test_set_item(self, actor, dict_): - dict_['key1'] = Parameter.wrap('key1', 'value1') + dict_['key1'] = Attribute.wrap('key1', 'value1') assert dict_['key1'] == 'value1' == actor.dict_['key1'].value - assert isinstance(actor.dict_['key1'], Parameter) + assert isinstance(actor.dict_['key1'], Attribute) def test_nested(self, actor, dict_): dict_['key'] = {} - assert isinstance(actor.dict_['key'], Parameter) + assert isinstance(actor.dict_['key'], Attribute) assert dict_['key'] == actor.dict_['key'].value == {} dict_['key']['inner_key'] = 'value' @@ -112,7 +112,7 @@ class TestDict(CollectionInstrumentation): assert dict_['key'].keys() == ['inner_key'] assert dict_['key'].values() == ['value'] assert dict_['key'].items() == [('inner_key', 'value')] - assert isinstance(actor.dict_['key'], Parameter) + assert isinstance(actor.dict_['key'], Attribute) assert isinstance(dict_['key'], collection_instrumentation._InstrumentedDict) dict_['key'].update({'updated_key': 'updated_value'}) @@ -123,7 +123,7 @@ class TestDict(CollectionInstrumentation): assert sorted(dict_['key'].values()) == sorted(['value', 'updated_value']) assert sorted(dict_['key'].items()) == sorted([('inner_key', 'value'), ('updated_key', 'updated_value')]) - assert isinstance(actor.dict_['key'], Parameter) + assert isinstance(actor.dict_['key'], Attribute) assert isinstance(dict_['key'], collection_instrumentation._InstrumentedDict) dict_.update({'key': 'override_value'}) @@ -131,12 +131,12 @@ class TestDict(CollectionInstrumentation): assert 'key' in dict_ assert dict_['key'] == 'override_value' assert len(actor.dict_) == 1 - assert isinstance(actor.dict_['key'], Parameter) + assert isinstance(actor.dict_['key'], Attribute) assert actor.dict_['key'].value == 'override_value' def test_get_item(self, actor, dict_): - dict_['key1'] = Parameter.wrap('key1', 'value1') - assert isinstance(actor.dict_['key1'], Parameter) + dict_['key1'] = Attribute.wrap('key1', 'value1') + assert isinstance(actor.dict_['key1'], Attribute) def test_update(self, actor, dict_): dict_['key1'] = 'value1' @@ -145,7 +145,7 @@ class TestDict(CollectionInstrumentation): dict_.update(new_dict) assert len(dict_) == 2 assert dict_['key2'] == 'value2' - assert isinstance(actor.dict_['key2'], Parameter) + assert isinstance(actor.dict_['key2'], Attribute) new_dict = {} new_dict.update(dict_) @@ -172,20 +172,20 @@ class TestDict(CollectionInstrumentation): class TestList(CollectionInstrumentation): def test_append(self, actor, list_): - list_.append(Parameter.wrap('name', 'value1')) + list_.append(Attribute.wrap('name', 'value1')) list_.append('value2') assert len(actor.list_) == 2 assert len(list_) == 2 - assert isinstance(actor.list_[0], Parameter) + assert isinstance(actor.list_[0], Attribute) assert list_[0] == 'value1' - assert isinstance(actor.list_[1], Parameter) + assert isinstance(actor.list_[1], Attribute) assert list_[1] == 'value2' list_[0] = 'new_value1' list_[1] = 'new_value2' - assert isinstance(actor.list_[1], Parameter) - assert isinstance(actor.list_[1], Parameter) + assert isinstance(actor.list_[1], Attribute) + assert isinstance(actor.list_[1], Attribute) assert list_[0] == 'new_value1' assert list_[1] == 'new_value2' @@ -214,12 +214,12 @@ class TestList(CollectionInstrumentation): list_.append([]) list_[0].append('inner_item') - assert isinstance(actor.list_[0], Parameter) + assert isinstance(actor.list_[0], Attribute) assert len(list_) == 1 assert list_[0][0] == 'inner_item' list_[0].append('new_item') - assert isinstance(actor.list_[0], Parameter) + assert isinstance(actor.list_[0], Attribute) assert len(list_) == 1 assert list_[0][1] == 'new_item' @@ -231,23 +231,23 @@ class TestDictList(CollectionInstrumentation): def test_dict_in_list(self, actor, list_): list_.append({}) assert len(list_) == 1 - assert isinstance(actor.list_[0], Parameter) + assert isinstance(actor.list_[0], Attribute) assert actor.list_[0].value == {} list_[0]['key'] = 'value' assert list_[0]['key'] == 'value' assert len(actor.list_) == 1 - assert isinstance(actor.list_[0], Parameter) + assert isinstance(actor.list_[0], Attribute) assert actor.list_[0].value['key'] == 'value' def test_list_in_dict(self, actor, dict_): dict_['key'] = [] assert len(dict_) == 1 - assert isinstance(actor.dict_['key'], Parameter) + assert isinstance(actor.dict_['key'], Attribute) assert actor.dict_['key'].value == [] dict_['key'].append('value') assert dict_['key'][0] == 'value' assert len(actor.dict_) == 1 - assert isinstance(actor.dict_['key'], Parameter) + assert isinstance(actor.dict_['key'], Attribute) assert actor.dict_['key'].value[0] == 'value' http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/b6d3c43b/tests/orchestrator/context/test_toolbelt.py ---------------------------------------------------------------------- diff --git a/tests/orchestrator/context/test_toolbelt.py b/tests/orchestrator/context/test_toolbelt.py index 326ce83..4de9e55 100644 --- a/tests/orchestrator/context/test_toolbelt.py +++ b/tests/orchestrator/context/test_toolbelt.py @@ -94,7 +94,7 @@ def test_host_ip(workflow_context, executor, dataholder): operation_kwargs=dict(function=op_path(host_ip, module_path=__name__), arguments=arguments) ) dependency_node.interfaces[interface.name] = interface - dependency_node.attributes['ip'] = models.Parameter.wrap('ip', '1.1.1.1') + dependency_node.attributes['ip'] = models.Attribute.wrap('ip', '1.1.1.1') workflow_context.model.node.update(dependency_node) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/b6d3c43b/tests/orchestrator/test_workflow_runner.py ---------------------------------------------------------------------- diff --git a/tests/orchestrator/test_workflow_runner.py b/tests/orchestrator/test_workflow_runner.py index 3646339..c5a62ae 100644 --- a/tests/orchestrator/test_workflow_runner.py +++ b/tests/orchestrator/test_workflow_runner.py @@ -170,7 +170,7 @@ def test_execution_inputs_override_workflow_inputs(request): wf_inputs = {'input1': 'value1', 'input2': 'value2', 'input3': 5} mock_workflow = _setup_mock_workflow_in_service( request, - inputs=dict((name, models.Parameter.wrap(name, val)) for name, val + inputs=dict((name, models.Input.wrap(name, val)) for name, val in wf_inputs.iteritems())) with mock.patch('aria.orchestrator.workflow_runner.Engine'): @@ -195,7 +195,7 @@ def test_execution_inputs_undeclared_inputs(request): def test_execution_inputs_missing_required_inputs(request): mock_workflow = _setup_mock_workflow_in_service( - request, inputs={'required_input': models.Parameter.wrap('required_input', value=None)}) + request, inputs={'required_input': models.Input.wrap('required_input', value=None)}) with pytest.raises(modeling_exceptions.MissingRequiredParametersException): _create_workflow_runner(request, mock_workflow, inputs={}) @@ -203,7 +203,7 @@ def test_execution_inputs_missing_required_inputs(request): def test_execution_inputs_wrong_type_inputs(request): mock_workflow = _setup_mock_workflow_in_service( - request, inputs={'input': models.Parameter.wrap('input', 'value')}) + request, inputs={'input': models.Input.wrap('input', 'value')}) with pytest.raises(modeling_exceptions.ParametersOfWrongTypeException): _create_workflow_runner(request, mock_workflow, inputs={'input': 5}) @@ -224,7 +224,7 @@ def test_workflow_function_parameters(request, tmpdir): wf_inputs = {'output_path': output_path, 'input1': 'value1', 'input2': 'value2', 'input3': 5} mock_workflow = _setup_mock_workflow_in_service( - request, inputs=dict((name, models.Parameter.wrap(name, val)) for name, val + request, inputs=dict((name, models.Input.wrap(name, val)) for name, val in wf_inputs.iteritems())) _create_workflow_runner(request, mock_workflow, @@ -255,12 +255,16 @@ def _setup_mock_workflow_in_service(request, inputs=None): source = workflow_mocks.__file__ resource.service_template.upload(str(service.service_template.id), source) mock_workflow_name = 'test_workflow' + arguments = {} + if inputs: + for input in inputs.itervalues(): + arguments[input.name] = input.as_argument() workflow = models.Operation( name=mock_workflow_name, service=service, function='workflow.mock_workflow', inputs=inputs or {}, - arguments=inputs or {}) + arguments=arguments) service.workflows[mock_workflow_name] = workflow return mock_workflow_name http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/b6d3c43b/tests/orchestrator/workflows/executor/test_executor.py ---------------------------------------------------------------------- diff --git a/tests/orchestrator/workflows/executor/test_executor.py b/tests/orchestrator/workflows/executor/test_executor.py index 9ddaef4..3079c60 100644 --- a/tests/orchestrator/workflows/executor/test_executor.py +++ b/tests/orchestrator/workflows/executor/test_executor.py @@ -47,7 +47,7 @@ def execute_and_assert(executor, storage=None): successful_task = MockTask(_get_function(mock_successful_task), storage=storage) failing_task = MockTask(_get_function(mock_failing_task), storage=storage) task_with_inputs = MockTask(_get_function(mock_task_with_input), - arguments={'input': models.Parameter.wrap('input', 'value')}, + arguments={'input': models.Argument.wrap('input', 'value')}, storage=storage) for task in [successful_task, failing_task, task_with_inputs]: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/b6d3c43b/tests/storage/test_model_storage.py ---------------------------------------------------------------------- diff --git a/tests/storage/test_model_storage.py b/tests/storage/test_model_storage.py index 4dabfaf..518d624 100644 --- a/tests/storage/test_model_storage.py +++ b/tests/storage/test_model_storage.py @@ -107,7 +107,11 @@ def test_application_storage_factory(): assert storage.plugin assert storage.task - assert storage.parameter + assert storage.input + assert storage.output + assert storage.property + assert storage.attribute + assert storage.type assert storage.metadata http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/b6d3c43b/tox.ini ---------------------------------------------------------------------- diff --git a/tox.ini b/tox.ini index 6ab97cb..58e62c3 100644 --- a/tox.ini +++ b/tox.ini @@ -19,8 +19,6 @@ passenv = PYTHON PYTHON_VERSION PYTHON_ARCH -setenv = - INSTALL_CTX=1 deps = -rrequirements.txt -rtests/requirements.txt
