You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ariatosca.apache.org by av...@apache.org on 2017/04/06 12:57:08 UTC

[1/8] incubator-ariatosca git commit: fixed pylint in tests [Forced Update!]

Repository: incubator-ariatosca
Updated Branches:
  refs/heads/cli-tests 5dbf61e7a -> e5443f2c1 (forced update)


fixed pylint in tests


Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/94c8d722
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/94c8d722
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/94c8d722

Branch: refs/heads/cli-tests
Commit: 94c8d7221e54679a4e60cd0873f271c73b4908b6
Parents: 45f61a0
Author: Ran Ziv <ra...@gigaspaces.com>
Authored: Thu Apr 6 13:06:24 2017 +0300
Committer: Ran Ziv <ra...@gigaspaces.com>
Committed: Thu Apr 6 13:06:24 2017 +0300

----------------------------------------------------------------------
 tests/orchestrator/context/test_resource_render.py           | 8 ++++----
 tests/orchestrator/context/test_serialize.py                 | 2 --
 tests/orchestrator/execution_plugin/test_local.py            | 7 ++++---
 .../orchestrator/workflows/executor/test_process_executor.py | 6 +++++-
 tests/utils/test_plugin.py                                   | 2 +-
 5 files changed, 14 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/94c8d722/tests/orchestrator/context/test_resource_render.py
----------------------------------------------------------------------
diff --git a/tests/orchestrator/context/test_resource_render.py b/tests/orchestrator/context/test_resource_render.py
index 8113746..8249086 100644
--- a/tests/orchestrator/context/test_resource_render.py
+++ b/tests/orchestrator/context/test_resource_render.py
@@ -65,8 +65,8 @@ def resources(tmpdir, ctx):
     variables_template_path = tmpdir.join(_VARIABLES_TEMPLATE_PATH)
     variables_template_path.write(_VARIABLES_TEMPLATE)
     ctx.resource.service.upload(entry_id='1',
-                                   source=str(implicit_ctx_template_path),
-                                   path=_IMPLICIT_CTX_TEMPLATE_PATH)
+                                source=str(implicit_ctx_template_path),
+                                path=_IMPLICIT_CTX_TEMPLATE_PATH)
     ctx.resource.service.upload(entry_id='1',
-                                   source=str(variables_template_path),
-                                   path=_VARIABLES_TEMPLATE_PATH)
+                                source=str(variables_template_path),
+                                path=_VARIABLES_TEMPLATE_PATH)

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/94c8d722/tests/orchestrator/context/test_serialize.py
----------------------------------------------------------------------
diff --git a/tests/orchestrator/context/test_serialize.py b/tests/orchestrator/context/test_serialize.py
index 420f7f9..ab3a5b6 100644
--- a/tests/orchestrator/context/test_serialize.py
+++ b/tests/orchestrator/context/test_serialize.py
@@ -15,8 +15,6 @@
 
 import pytest
 
-import aria
-from aria.storage import sql_mapi
 from aria.orchestrator.workflows import api
 from aria.orchestrator.workflows.core import engine
 from aria.orchestrator.workflows.executor import process

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/94c8d722/tests/orchestrator/execution_plugin/test_local.py
----------------------------------------------------------------------
diff --git a/tests/orchestrator/execution_plugin/test_local.py b/tests/orchestrator/execution_plugin/test_local.py
index 67d527c..58506ba 100644
--- a/tests/orchestrator/execution_plugin/test_local.py
+++ b/tests/orchestrator/execution_plugin/test_local.py
@@ -482,9 +482,10 @@ if __name__ == '__main__':
                 node.service,
                 'test',
                 'op',
-                operation_kwargs=dict(implementation='{0}.{1}'.format(
-                    operations.__name__,
-                    operations.run_script_locally.__name__),
+                operation_kwargs=dict(
+                    implementation='{0}.{1}'.format(
+                        operations.__name__,
+                        operations.run_script_locally.__name__),
                     inputs=inputs)
             )
             node.interfaces[interface.name] = interface

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/94c8d722/tests/orchestrator/workflows/executor/test_process_executor.py
----------------------------------------------------------------------
diff --git a/tests/orchestrator/workflows/executor/test_process_executor.py b/tests/orchestrator/workflows/executor/test_process_executor.py
index 8f2c8a2..7d627a0 100644
--- a/tests/orchestrator/workflows/executor/test_process_executor.py
+++ b/tests/orchestrator/workflows/executor/test_process_executor.py
@@ -28,7 +28,11 @@ from aria.orchestrator.workflows.executor import process
 
 import tests.storage
 import tests.resources
-from tests.fixtures import plugins_dir, plugin_manager, fs_model as model
+from tests.fixtures import (  # pylint: disable=unused-import
+    plugins_dir,
+    plugin_manager,
+    fs_model as model
+)
 
 
 class TestProcessExecutor(object):

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/94c8d722/tests/utils/test_plugin.py
----------------------------------------------------------------------
diff --git a/tests/utils/test_plugin.py b/tests/utils/test_plugin.py
index df82515..3350247 100644
--- a/tests/utils/test_plugin.py
+++ b/tests/utils/test_plugin.py
@@ -20,7 +20,7 @@ import pytest
 from aria.orchestrator import exceptions
 from aria.utils.plugin import create as create_plugin
 
-from ..fixtures import (
+from ..fixtures import (  # pylint: disable=unused-import
     plugins_dir,
     plugin_manager,
     inmemory_model as model


[7/8] incubator-ariatosca git commit: Add test for non `unique name` exception from service-templates store

Posted by av...@apache.org.
Add test for non `unique name` exception from service-templates store


Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/7ed0f899
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/7ed0f899
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/7ed0f899

Branch: refs/heads/cli-tests
Commit: 7ed0f8995090d15fa51441a3735f08f8eb208100
Parents: 6e30d8a
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Thu Apr 6 15:02:18 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Thu Apr 6 15:56:55 2017 +0300

----------------------------------------------------------------------
 aria/cli/utils.py                   |  2 +-
 tests/cli/base_test.py              |  2 +-
 tests/cli/test_service_templates.py | 14 +++++++++++++-
 3 files changed, 15 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7ed0f899/aria/cli/utils.py
----------------------------------------------------------------------
diff --git a/aria/cli/utils.py b/aria/cli/utils.py
index 99315c4..44358ec 100644
--- a/aria/cli/utils.py
+++ b/aria/cli/utils.py
@@ -158,4 +158,4 @@ def handle_storage_exception(e, model_class, name):
               'There already a exists a {model_class} with the same name' \
               .format(model_class=model_class, name=name)
         raise AriaCliError(msg)
-    raise
+    raise AriaCliError()

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7ed0f899/tests/cli/base_test.py
----------------------------------------------------------------------
diff --git a/tests/cli/base_test.py b/tests/cli/base_test.py
index d5db9c2..1dae957 100644
--- a/tests/cli/base_test.py
+++ b/tests/cli/base_test.py
@@ -18,7 +18,7 @@ class TestCliBase(object):
         return self._logger_output.getvalue()
 
 
-def assert_exception_raised(outcome, expected_exception, expected_msg):
+def assert_exception_raised(outcome, expected_exception, expected_msg=''):
     assert isinstance(outcome.exception, expected_exception)
     assert expected_msg == str(outcome.exception)
 

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7ed0f899/tests/cli/test_service_templates.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_service_templates.py b/tests/cli/test_service_templates.py
index 9d210c1..c98bc7e 100644
--- a/tests/cli/test_service_templates.py
+++ b/tests/cli/test_service_templates.py
@@ -127,7 +127,7 @@ class TestServiceTemplatesStore(TestCliBase):
         self.invoke('service_templates store stubpath test_st')
         assert 'Service template test_st stored' in self.logger_output_string
 
-    def test_store_raises_exception(self, monkeypatch, mock_object):
+    def test_store_raises_exception_resulting_from_name_uniqueness(self, monkeypatch, mock_object):
 
         monkeypatch.setattr(service_template_utils, 'get', mock_object)
         monkeypatch.setattr(Core,
@@ -142,6 +142,18 @@ class TestServiceTemplatesStore(TestCliBase):
             expected_msg='Could not store service template `test_st`\n'
                          'There already a exists a service template with the same name')
 
+    def test_store_raises_exception(self, monkeypatch, mock_object):
+
+        monkeypatch.setattr(service_template_utils, 'get', mock_object)
+        monkeypatch.setattr(Core,
+                            'create_service_template',
+                            raise_exception(storage_exceptions.NotFoundError))
+
+        outcome = self.invoke('service_templates store stubpath test_st')
+        assert_exception_raised(
+            outcome,
+            expected_exception=AriaCliError)
+
 
 class TestServiceTemplatesDelete(TestCliBase):
 


[8/8] incubator-ariatosca git commit: Add tests for service-templates inputs

Posted by av...@apache.org.
Add tests for service-templates inputs


Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/e5443f2c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/e5443f2c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/e5443f2c

Branch: refs/heads/cli-tests
Commit: e5443f2c1451fa049a983ae41a736982d91661a4
Parents: 7ed0f89
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Thu Apr 6 15:54:26 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Thu Apr 6 15:56:55 2017 +0300

----------------------------------------------------------------------
 tests/cli/test_service_templates.py | 23 +++++++++++++++++++++++
 tests/mock/models.py                |  5 +++++
 2 files changed, 28 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/e5443f2c/tests/cli/test_service_templates.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_service_templates.py b/tests/cli/test_service_templates.py
index c98bc7e..3d5a8fb 100644
--- a/tests/cli/test_service_templates.py
+++ b/tests/cli/test_service_templates.py
@@ -44,6 +44,16 @@ class MockServiceTemplateStorage(object):
             st.services = [service]
         return st
 
+    @staticmethod
+    def get_by_name(name):
+        st = models.create_service_template('test_st')
+        if name == 'with_inputs':
+            input = models.create_input(name='input1', value='value1')
+            st.inputs = {'input1': input}
+        if name == 'without_inputs':
+            st.inputs = {}
+        return st
+
 
 class TestServiceTemplatesShow(TestCliBase):
 
@@ -175,3 +185,16 @@ class TestServiceTemplatesDelete(TestCliBase):
             self.invoke('service_templates delete test_st'),
             expected_exception=AriaCliError,
             expected_msg='')
+
+
+class TestServiceTemplatesInputs(TestCliBase):
+
+    def test_inputs_existing_inputs(self, monkeypatch):
+        monkeypatch.setattr(Environment, 'model_storage', MockStorage())
+        self.invoke('service_templates inputs with_inputs')
+        assert 'input1' in self.logger_output_string and 'value1' in self.logger_output_string
+
+    def test_inputs_no_inputs(self, monkeypatch):
+        monkeypatch.setattr(Environment, 'model_storage', MockStorage())
+        self.invoke('service_templates inputs without_inputs')
+        assert 'No inputs' in self.logger_output_string

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/e5443f2c/tests/mock/models.py
----------------------------------------------------------------------
diff --git a/tests/mock/models.py b/tests/mock/models.py
index 6b7f810..9771fe2 100644
--- a/tests/mock/models.py
+++ b/tests/mock/models.py
@@ -221,6 +221,11 @@ def create_plugin_specification(name='test_plugin', version='0.1'):
     )
 
 
+def create_input(name, value):
+    p = models.Parameter()
+    return p.wrap(name, value)
+
+
 def _dictify(item):
     return dict(((item.name, item),))
 


[4/8] incubator-ariatosca git commit: improved type check

Posted by av...@apache.org.
improved type check


Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/e04ba1fb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/e04ba1fb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/e04ba1fb

Branch: refs/heads/cli-tests
Commit: e04ba1fb127484a011f6e6829800b9dcc27ec3b2
Parents: ef3f6a0
Author: Ran Ziv <ra...@gigaspaces.com>
Authored: Thu Apr 6 13:50:46 2017 +0300
Committer: Ran Ziv <ra...@gigaspaces.com>
Committed: Thu Apr 6 13:50:46 2017 +0300

----------------------------------------------------------------------
 aria/modeling/utils.py |  9 +++++----
 aria/utils/type.py     | 16 +++++++++-------
 2 files changed, 14 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/e04ba1fb/aria/modeling/utils.py
----------------------------------------------------------------------
diff --git a/aria/modeling/utils.py b/aria/modeling/utils.py
index 35ce991..34c2ac7 100644
--- a/aria/modeling/utils.py
+++ b/aria/modeling/utils.py
@@ -78,12 +78,13 @@ def _merge_and_validate_inputs(inputs, template_inputs):
         else:
             # Validate input type
             try:
-                # TODO: improve type validation; Needs to consider custom data_types as well
-                if input_template.type_name in ('list', 'dict', 'tuple', 'string', 'integer',
-                                                'boolean', 'float'):
-                    validate_value_type(inputs[input_name], input_template.type_name)
+                validate_value_type(inputs[input_name], input_template.type_name)
             except ValueError:
                 wrong_type_inputs[input_name] = input_template.type_name
+            except RuntimeError:
+                # TODO: This error shouldn't be raised (or caught), but right now we lack support
+                # for custom data_types, which will raise this error. Skipping their validation.
+                pass
 
     if missing_inputs:
         raise exceptions.MissingRequiredInputsException(

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/e04ba1fb/aria/utils/type.py
----------------------------------------------------------------------
diff --git a/aria/utils/type.py b/aria/utils/type.py
index 292225a..abcf422 100644
--- a/aria/utils/type.py
+++ b/aria/utils/type.py
@@ -15,9 +15,13 @@
 
 
 def validate_value_type(value, type_name):
-    """Supports both python and yaml type names"""
-    #TODO add timestamp type?
+    """
+    Validate a value is of a specific type.
+    A ValueError will be raised on type mismatch.
+    Supports both python and yaml type names.
+    """
 
+    #TODO add timestamp type?
     name_to_type = {
         'list': list,
         'dict': dict,
@@ -34,11 +38,9 @@ def validate_value_type(value, type_name):
 
     type = name_to_type.get(type_name.lower())
     if type is None:
-        raise ValueError('No supported type_name was provided')
-    try:
-        type(value)
-    except ValueError:
-        raise
+        raise RuntimeError('No supported type_name was provided')
+    # validating value type - ValueError will be raised on type mismatch
+    type(value)
 
 
 def convert_value_to_type(str_value, type_name):


[5/8] incubator-ariatosca git commit: Add tests for service-templates delete

Posted by av...@apache.org.
Add tests for service-templates delete


Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/6e30d8a6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/6e30d8a6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/6e30d8a6

Branch: refs/heads/cli-tests
Commit: 6e30d8a6cf25cee05e5a7af3be9ec5b9bddd63a2
Parents: 8d79b1e
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Thu Apr 6 14:02:56 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Thu Apr 6 15:56:55 2017 +0300

----------------------------------------------------------------------
 tests/cli/test_service_templates.py | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/6e30d8a6/tests/cli/test_service_templates.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_service_templates.py b/tests/cli/test_service_templates.py
index d0daf59..9d210c1 100644
--- a/tests/cli/test_service_templates.py
+++ b/tests/cli/test_service_templates.py
@@ -141,3 +141,25 @@ class TestServiceTemplatesStore(TestCliBase):
             expected_exception=AriaCliError,
             expected_msg='Could not store service template `test_st`\n'
                          'There already a exists a service template with the same name')
+
+
+class TestServiceTemplatesDelete(TestCliBase):
+
+    def test_delete_no_exception(self, monkeypatch, mock_object):
+
+        monkeypatch.setattr(Environment, 'model_storage', mock_object)
+        monkeypatch.setattr(Core, 'delete_service_template', mock_object)
+        self.invoke('service_templates delete test_st')
+        assert 'Service template test_st deleted' in self.logger_output_string
+
+    def test_delete_raises_exception(self, monkeypatch, mock_object):
+
+        monkeypatch.setattr(Environment, 'model_storage', mock_object)
+        monkeypatch.setattr(Core,
+                            'delete_service_template',
+                            raise_exception(storage_exceptions.NotFoundError))
+
+        assert_exception_raised(
+            self.invoke('service_templates delete test_st'),
+            expected_exception=AriaCliError,
+            expected_msg='')


[6/8] incubator-ariatosca git commit: Create testing framework for the CLI, and add some tests

Posted by av...@apache.org.
Create testing framework for the CLI, and add some tests

The tests are of:
service-templates show
service-templates list
service-templates store


Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/8d79b1e4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/8d79b1e4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/8d79b1e4

Branch: refs/heads/cli-tests
Commit: 8d79b1e41ab235f61db5b8a075d174a84770ac01
Parents: e04ba1f
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Wed Apr 5 11:28:11 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Thu Apr 6 15:56:55 2017 +0300

----------------------------------------------------------------------
 aria/cli/commands/__init__.py          |  11 +++
 aria/cli/commands/service_templates.py |   5 +-
 tests/cli/base_test.py                 |  29 +++++-
 tests/cli/runner.py                    |  10 +-
 tests/cli/test_service_templates.py    | 136 ++++++++++++++++++++++++++--
 5 files changed, 171 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/8d79b1e4/aria/cli/commands/__init__.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/__init__.py b/aria/cli/commands/__init__.py
index ae1e83e..7777791 100644
--- a/aria/cli/commands/__init__.py
+++ b/aria/cli/commands/__init__.py
@@ -12,3 +12,14 @@
 # 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.
+
+from . import (
+    executions,
+    logs,
+    node_templates,
+    nodes,
+    plugins,
+    service_templates,
+    services,
+    workflows
+)

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/8d79b1e4/aria/cli/commands/service_templates.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/service_templates.py b/aria/cli/commands/service_templates.py
index a0e651f..5fcc973 100644
--- a/aria/cli/commands/service_templates.py
+++ b/aria/cli/commands/service_templates.py
@@ -15,7 +15,6 @@
 
 
 import os
-import json
 
 from .. import utils
 from .. import csar
@@ -66,7 +65,7 @@ def show(service_template_id, model_storage, logger):
         logger.info('{0}\n'.format(service_template_dict['description'].encode('UTF-8') or ''))
 
     logger.info('Existing services:')
-    logger.info('{0}\n'.format(json.dumps([d['name'] for d in services])))
+    logger.info('{0}\n'.format([s['name'] for s in services]))
 
 
 @service_templates.command(name='list',
@@ -122,7 +121,7 @@ def store(service_template_path, service_template_name, model_storage, resource_
                                      service_template_name)
     except storage_exceptions.StorageError as e:
         handle_storage_exception(e, 'service template', service_template_name)
-    logger.info('Service template stored')
+    logger.info('Service template {0} stored'.format(service_template_name))
 
 
 @service_templates.command(name='delete',

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/8d79b1e4/tests/cli/base_test.py
----------------------------------------------------------------------
diff --git a/tests/cli/base_test.py b/tests/cli/base_test.py
index c8c574b..d5db9c2 100644
--- a/tests/cli/base_test.py
+++ b/tests/cli/base_test.py
@@ -6,8 +6,33 @@ from utils import setup_logger
 
 class TestCliBase(object):
 
-    logger_output = StringIO()
-    setup_logger(logger_name='aria.cli.main', output_stream=logger_output)
+    _logger_output = StringIO()
+    setup_logger(logger_name='aria.cli.main', output_stream=_logger_output)
 
     def invoke(self, command):
+        self._logger_output.truncate(0)
         return runner.invoke(command)
+
+    @property
+    def logger_output_string(self):
+        return self._logger_output.getvalue()
+
+
+def assert_exception_raised(outcome, expected_exception, expected_msg):
+    assert isinstance(outcome.exception, expected_exception)
+    assert expected_msg == str(outcome.exception)
+
+
+# This exists as I wanted to mocked a function using monkeypatch to return a function that raises an
+# exception. I tried doing that using a lambda in-place, but this can't be accomplished in a trivial
+# way it seems. So I wrote this silly function instead
+def raise_exception(exception, msg=''):
+
+    def inner(*args, **kwargs):
+        raise exception(msg)
+
+    return inner
+
+
+
+

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/8d79b1e4/tests/cli/runner.py
----------------------------------------------------------------------
diff --git a/tests/cli/runner.py b/tests/cli/runner.py
index 26af20a..8b4294a 100644
--- a/tests/cli/runner.py
+++ b/tests/cli/runner.py
@@ -2,11 +2,11 @@ import aria.cli.commands as commands
 import click.testing
 
 
-def invoke(command):
-    # TODO handle verbosity later
-    command_string = ['service_templates', 'show', '1']
-    command, sub, args = command_string[0], command_string[1], command_string[2:]
+def invoke(command_string):
+    # TODO handle verbosity and co. later
+    command_list = command_string.split()
+    command, sub, args = command_list[0], command_list[1], command_list[2:]
     runner = click.testing.CliRunner()
     outcome = runner.invoke(getattr(
         getattr(commands, command), sub), args)
-    return outcome
\ No newline at end of file
+    return outcome

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/8d79b1e4/tests/cli/test_service_templates.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_service_templates.py b/tests/cli/test_service_templates.py
index 8e1fa65..d0daf59 100644
--- a/tests/cli/test_service_templates.py
+++ b/tests/cli/test_service_templates.py
@@ -1,27 +1,143 @@
+from aria.cli import service_template_utils
 from aria.cli.env import Environment
-from base_test import TestCliBase
-from aria.modeling.models import ServiceTemplate
+from aria.cli.exceptions import AriaCliError
+from aria.core import Core
+from aria.storage import exceptions as storage_exceptions
+from tests.cli.base_test import TestCliBase, assert_exception_raised, raise_exception
+from tests.mock import models
+
+import pytest
+
+
+@pytest.fixture
+def mock_object(mocker):
+    return mocker.MagicMock()
 
 
 class MockStorage(object):
 
     def __init__(self):
-        self.service_template = MockServiceTemplateStorage()
+        self.service_template = MockServiceTemplateStorage
 
 
 class MockServiceTemplateStorage(object):
 
-    def get(self, id_):
-        if id_ == '1':  # a service-template with no description and no services.
-            st = ServiceTemplate()
-            st.name = 'test_st'
+    @staticmethod
+    def list(**_):
+        return [models.create_service_template('test_st'),
+                models.create_service_template('test_st2')]
+
+    @staticmethod
+    def get(id):
+        st = models.create_service_template('test_st')
+        if id == '1':  # no services and no description.
+            st.services = []
+        if id == '2':  # no services, but an description
+            st.description = 'test_description'
             st.services = []
-            return st
+        if id == '3':  # one service, and a description
+            service = models.create_service(st, 'test_s')
+            st.description = 'test_description'
+            st.services = [service]
+        if id == '4':  # one service, and a description
+            service = models.create_service(st, 'test_s')
+            st.services = [service]
+        return st
 
 
 class TestServiceTemplatesShow(TestCliBase):
 
     def test_show_no_services_no_description(self, monkeypatch):
-        # reroute the logger to a special location, and check it's content.
+
+        monkeypatch.setattr(Environment, 'model_storage', MockStorage())
+        self.invoke('service_templates show 1')
+
+        assert 'Description:' not in self.logger_output_string
+        assert 'Existing services:\n[]' in self.logger_output_string
+
+    def test_show_no_services_yes_description(self, monkeypatch):
+
         monkeypatch.setattr(Environment, 'model_storage', MockStorage())
-        outcome = self.invoke('service_templates show 1')
+        self.invoke('service_templates show 2')
+
+        assert 'Description:\ntest_description' in self.logger_output_string
+        assert 'Existing services:\n[]' in self.logger_output_string
+
+    def test_show_one_service_yes_description(self, monkeypatch):
+
+        monkeypatch.setattr(Environment, 'model_storage', MockStorage())
+        self.invoke('service_templates show 3')
+
+        assert 'Description:\ntest_description' in self.logger_output_string
+        assert "Existing services:\n['test_s']" in self.logger_output_string
+
+    def test_show_one_service_no_description(self, monkeypatch):
+
+        monkeypatch.setattr(Environment, 'model_storage', MockStorage())
+        self.invoke('service_templates show 4')
+
+        assert 'Description:' not in self.logger_output_string
+        assert "Existing services:\n['test_s']" in self.logger_output_string
+
+    def test_show_exception_raise_when_no_service_template_with_given_id(self):
+
+        # TODO consider removing as it does not seem to test the cli but rather the message received
+        # from the storage
+        outcome = self.invoke('service_templates show 5')
+        assert_exception_raised(
+            outcome,
+            expected_exception=storage_exceptions.NotFoundError,
+            expected_msg='Requested `ServiceTemplate` with ID `5` was not found')
+
+
+class TestServiceTemplatesList(TestCliBase):
+
+    def test_list_one_service_template(self, monkeypatch):
+
+        monkeypatch.setattr(Environment, 'model_storage', MockStorage())
+        self.invoke('service_templates list')
+        assert 'test_st' in self.logger_output_string
+        assert 'test_st2' in self.logger_output_string
+
+    def test_list_ascending(self, monkeypatch, mock_object):
+
+        monkeypatch.setattr(Environment, 'model_storage', mock_object)
+        self.invoke('service_templates list --sort-by name')
+        mock_object.service_template.list.assert_called_with(sort={'name': 'asc'})
+
+    def test_list_descending(self, monkeypatch, mock_object):
+
+        monkeypatch.setattr(Environment, 'model_storage', mock_object)
+        self.invoke('service_templates list --sort-by name --descending')
+        mock_object.service_template.list.assert_called_with(sort={'name': 'desc'})
+
+    def test_list_default_sorting(self, monkeypatch, mock_object):
+
+        monkeypatch.setattr(Environment, 'model_storage', mock_object)
+        self.invoke('service_templates list')
+        mock_object.service_template.list.assert_called_with(sort={'created_at': 'asc'})
+
+
+class TestServiceTemplatesStore(TestCliBase):
+
+    def test_store_no_exception(self, monkeypatch, mock_object):
+
+        monkeypatch.setattr(Core, 'create_service_template', mock_object)
+        monkeypatch.setattr(service_template_utils, 'get', mock_object)
+        self.invoke('service_templates store stubpath test_st')
+        assert 'Service template test_st stored' in self.logger_output_string
+
+    def test_store_raises_exception(self, monkeypatch, mock_object):
+
+        monkeypatch.setattr(service_template_utils, 'get', mock_object)
+        monkeypatch.setattr(Core,
+                            'create_service_template',
+                            raise_exception(storage_exceptions.NotFoundError,
+                                            msg='UNIQUE constraint failed'))
+
+        outcome = self.invoke('service_templates store stubpath test_st')
+        assert_exception_raised(
+            outcome,
+            expected_exception=AriaCliError,
+            expected_msg='Could not store service template `test_st`\n'
+                         'There already a exists a service template with the same name')


[3/8] incubator-ariatosca git commit: fixed workflows show cli command

Posted by av...@apache.org.
fixed workflows show cli command


Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/ef3f6a07
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/ef3f6a07
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/ef3f6a07

Branch: refs/heads/cli-tests
Commit: ef3f6a070805eaf8d7fc624fbc8f95acb0e3d3f7
Parents: e2dd671
Author: Ran Ziv <ra...@gigaspaces.com>
Authored: Thu Apr 6 13:22:54 2017 +0300
Committer: Ran Ziv <ra...@gigaspaces.com>
Committed: Thu Apr 6 13:22:54 2017 +0300

----------------------------------------------------------------------
 aria/cli/commands/workflows.py | 45 ++++++++++++++++++-------------------
 1 file changed, 22 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/ef3f6a07/aria/cli/commands/workflows.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/workflows.py b/aria/cli/commands/workflows.py
index 2666675..72dea5b 100644
--- a/aria/cli/commands/workflows.py
+++ b/aria/cli/commands/workflows.py
@@ -41,8 +41,8 @@ def show(workflow_name, service_name, model_storage, logger):
     """
     logger.info('Retrieving workflow {0} for service {1}'.format(
         workflow_name, service_name))
-    service = model_storage.service.get(service_name)
-    workflow = next((wf for wf in service.workflows if
+    service = model_storage.service.get_by_name(service_name)
+    workflow = next((wf for wf in service.workflows.values() if
                      wf.name == workflow_name), None)
     if not workflow:
         raise AriaCliError(
@@ -52,33 +52,32 @@ def show(workflow_name, service_name, model_storage, logger):
         'service_template_name': service.service_template_name,
         'service_name': service.name
     }
-    print_data(WORKFLOW_COLUMNS, workflow, 'Workflows:', defaults=defaults)
+    print_data(WORKFLOW_COLUMNS, workflow.to_dict(), 'Workflows:', defaults=defaults)
 
-    # print workflow parameters
-    mandatory_params = dict()
-    optional_params = dict()
-    for param_name, param in workflow.parameters.iteritems():
-        params_group = optional_params if 'default' in param else \
-            mandatory_params
-        params_group[param_name] = param
+    # print workflow inputs
+    required_inputs = dict()
+    optional_inputs = dict()
+    for input_name, input in workflow.inputs.iteritems():
+        inputs_group = optional_inputs if input.value is not None else required_inputs
+        inputs_group[input_name] = input
 
-    logger.info('Workflow Parameters:')
-    logger.info('\tMandatory Parameters:')
-    for param_name, param in mandatory_params.iteritems():
-        if 'description' in param:
-            logger.info('\t\t{0}\t({1})'.format(param_name,
-                                                param['description']))
+    logger.info('Workflow Inputs:')
+    logger.info('\tMandatory Inputs:')
+    for input_name, input in required_inputs.iteritems():
+        if input.description is not None:
+            logger.info('\t\t{0}\t({1})'.format(input_name,
+                                                input.description))
         else:
-            logger.info('\t\t{0}'.format(param_name))
+            logger.info('\t\t{0}'.format(input_name))
 
-    logger.info('\tOptional Parameters:')
-    for param_name, param in optional_params.iteritems():
-        if 'description' in param:
+    logger.info('\tOptional Inputs:')
+    for input_name, input in optional_inputs.iteritems():
+        if input.description is not None:
             logger.info('\t\t{0}: \t{1}\t({2})'.format(
-                param_name, param['default'], param['description']))
+                input_name, input.value, input.description))
         else:
-            logger.info('\t\t{0}: \t{1}'.format(param_name,
-                                                param['default']))
+            logger.info('\t\t{0}: \t{1}'.format(input_name,
+                                                input.value))
     logger.info('')
 
 


[2/8] incubator-ariatosca git commit: created fixtures.py for tests

Posted by av...@apache.org.
created fixtures.py for tests


Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/e2dd671d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/e2dd671d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/e2dd671d

Branch: refs/heads/cli-tests
Commit: e2dd671d1d74a4fa570a251aa265d4902204d40f
Parents: 94c8d72
Author: Ran Ziv <ra...@gigaspaces.com>
Authored: Thu Apr 6 13:09:28 2017 +0300
Committer: Ran Ziv <ra...@gigaspaces.com>
Committed: Thu Apr 6 13:09:28 2017 +0300

----------------------------------------------------------------------
 tests/fixtures.py | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 70 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/e2dd671d/tests/fixtures.py
----------------------------------------------------------------------
diff --git a/tests/fixtures.py b/tests/fixtures.py
new file mode 100644
index 0000000..3b1b9b5
--- /dev/null
+++ b/tests/fixtures.py
@@ -0,0 +1,70 @@
+# 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 shutil
+
+import pytest
+
+from aria import (
+    application_model_storage,
+    application_resource_storage
+)
+from aria.orchestrator import plugin
+from aria.storage import (
+    sql_mapi,
+    filesystem_rapi
+)
+
+from . import storage
+
+
+@pytest.fixture
+def inmemory_model():
+    model = application_model_storage(sql_mapi.SQLAlchemyModelAPI,
+                                      initiator=storage.init_inmemory_model_storage)
+    yield model
+    storage.release_sqlite_storage(model)
+
+
+@pytest.fixture
+def fs_model(tmpdir):
+    result = application_model_storage(sql_mapi.SQLAlchemyModelAPI,
+                                       initiator_kwargs=dict(base_dir=str(tmpdir)),
+                                       initiator=sql_mapi.init_storage)
+    yield result
+    storage.release_sqlite_storage(result)
+
+
+@pytest.fixture
+def resource_storage(tmpdir):
+    result = tmpdir.join('resources')
+    result.mkdir()
+    resource_storage = application_resource_storage(
+        filesystem_rapi.FileSystemResourceAPI,
+        api_kwargs=dict(directory=str(result)))
+    yield resource_storage
+    shutil.rmtree(str(result))
+
+
+@pytest.fixture
+def plugins_dir(tmpdir):
+    result = tmpdir.join('plugins')
+    result.mkdir()
+    return str(result)
+
+
+@pytest.fixture
+def plugin_manager(model, plugins_dir):
+    return plugin.PluginManager(model=model, plugins_dir=plugins_dir)