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/15 12:56:28 UTC

[01/19] incubator-ariatosca git commit: fixed simple review comments [Forced Update!]

Repository: incubator-ariatosca
Updated Branches:
  refs/heads/cli-tests f4a3f5257 -> d2953788e (forced update)


fixed simple review comments


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

Branch: refs/heads/cli-tests
Commit: 5dc3a58b58d2859939676af9861ab2d518de39d7
Parents: d6458c0
Author: Ran Ziv <ra...@gigaspaces.com>
Authored: Thu Apr 13 17:43:29 2017 +0300
Committer: Ran Ziv <ra...@gigaspaces.com>
Committed: Thu Apr 13 17:43:29 2017 +0300

----------------------------------------------------------------------
 aria/cli/cli/aria.py                        |  42 +++----
 aria/cli/cli/helptexts.py                   |   1 -
 aria/cli/colorful_event.py                  | 152 -----------------------
 aria/cli/commands/executions.py             |   4 +-
 aria/cli/commands/service_templates.py      |  18 +--
 aria/cli/constants.py                       |   2 +-
 aria/cli/csar.py                            |   2 +-
 aria/cli/env.py                             |   4 +-
 aria/cli/inputs.py                          |  16 +--
 aria/cli/service_template_utils.py          |  10 +-
 aria/cli/utils.py                           |   6 +-
 aria/core.py                                |  21 ++--
 aria/modeling/service_common.py             |  14 +--
 aria/modeling/service_template.py           |   1 -
 aria/modeling/utils.py                      |   5 +-
 aria/orchestrator/workflows/exceptions.py   |  10 +-
 aria/orchestrator/workflows/executor/dry.py |   8 +-
 aria/storage/instrumentation.py             |   7 +-
 aria/utils/formatting.py                    |  15 ---
 tests/cli/test_service_templates.py         |   2 +-
 tests/mock/models.py                        |   7 +-
 tests/utils/test_threading.py               |  20 ++-
 22 files changed, 94 insertions(+), 273 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/5dc3a58b/aria/cli/cli/aria.py
----------------------------------------------------------------------
diff --git a/aria/cli/cli/aria.py b/aria/cli/cli/aria.py
index 0177134..002846b 100644
--- a/aria/cli/cli/aria.py
+++ b/aria/cli/cli/aria.py
@@ -14,6 +14,7 @@
 # limitations under the License.
 
 
+import os
 import sys
 import difflib
 import StringIO
@@ -22,10 +23,13 @@ from functools import wraps
 
 import click
 
-from ..env import env, logger
+from ..env import (
+    env,
+    logger
+)
 from ..cli import helptexts
 from ..inputs import inputs_to_dict
-from ..constants import SAMPLE_SERVICE_TEMPLATE_FILENAME
+from ..constants import DEFAULT_SERVICE_TEMPLATE_FILENAME
 from ...utils.exceptions import get_exception_as_string
 
 
@@ -238,8 +242,8 @@ class AliasedGroup(click.Group):
                 self.max_suggestions,
                 self.cutoff)
             if matches:
-                error_msg += '\n\nDid you mean one of these?\n    {0}'.format(
-                    '\n    '.join(matches))
+                error_msg += '{1}{1}Did you mean one of these?{1}    {0}'.format(
+                    '{1}    '.join(matches, os.linesep))
             raise click.exceptions.UsageError(error_msg, error.ctx)
 
 
@@ -339,6 +343,12 @@ class Options(object):
             default=False,
             help=helptexts.DESCENDING)
 
+        self.service_template_filename = click.option(
+            '-n',
+            '--service-template-filename',
+            default=DEFAULT_SERVICE_TEMPLATE_FILENAME,
+            help=helptexts.SERVICE_TEMPLATE_FILENAME)
+
     @staticmethod
     def verbose(expose_value=False):
         return click.option(
@@ -359,30 +369,6 @@ class Options(object):
             help=help)
 
     @staticmethod
-    def service_template_filename():
-        return click.option(
-            '-n',
-            '--service-template-filename',
-            default=SAMPLE_SERVICE_TEMPLATE_FILENAME,
-            help=helptexts.SERVICE_TEMPLATE_FILENAME)
-
-    @staticmethod
-    def workflow_id(default):
-        return click.option(
-            '-w',
-            '--workflow-id',
-            default=default,
-            help=helptexts.WORKFLOW_TO_EXECUTE.format(default))
-
-    @staticmethod
-    def task_thread_pool_size(default=1):
-        return click.option(
-            '--task-thread-pool-size',
-            type=int,
-            default=default,
-            help=helptexts.TASK_THREAD_POOL_SIZE.format(default))
-
-    @staticmethod
     def task_max_attempts(default=1):
         return click.option(
             '--task-max-attempts',

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/5dc3a58b/aria/cli/cli/helptexts.py
----------------------------------------------------------------------
diff --git a/aria/cli/cli/helptexts.py b/aria/cli/cli/helptexts.py
index 0d66d6b..c50a172 100644
--- a/aria/cli/cli/helptexts.py
+++ b/aria/cli/cli/helptexts.py
@@ -22,7 +22,6 @@ INPUTS_PARAMS_USAGE = (
     '(*.yaml, /my_inputs/, etc..) to YAML files, a JSON string or as '
     'key1=value1;key2=value2). This argument can be used multiple times'
 )
-WORKFLOW_TO_EXECUTE = "The workflow to execute [default: {0}]"
 
 SERVICE_TEMPLATE_PATH = "The path to the application's service template file"
 SERVICE_TEMPLATE_ID = "The unique identifier for the service template"

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/5dc3a58b/aria/cli/colorful_event.py
----------------------------------------------------------------------
diff --git a/aria/cli/colorful_event.py b/aria/cli/colorful_event.py
deleted file mode 100644
index 53e3d02..0000000
--- a/aria/cli/colorful_event.py
+++ /dev/null
@@ -1,152 +0,0 @@
-# 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.
-
-from contextlib import contextmanager
-
-from colorama import Fore, Style
-
-from cloudify.event import Event
-
-
-def colorful_property(prop):
-    """
-    A decorator for coloring values of the parent event type properties
-    :param prop: the property to color (should be a method returning a color)
-    :return: a property which colors the value of the parent event type's
-             property with the same name
-    """
-    def _decorator(self):
-        # getting value of property from parent event type
-        val = getattr(super(ColorfulEvent, self), prop.__name__)
-        # getting the desired color
-        color = prop(self)
-        # coloring the value
-        return self._color_message(val, color)
-    return property(_decorator)
-
-
-class ColorfulEvent(Event):
-
-    RESET_COLOR = Fore.RESET + Style.RESET_ALL
-
-    TIMESTAMP_COLOR = Fore.RESET
-    LOG_TYPE_COLOR = Fore.YELLOW
-    EVENT_TYPE_COLOR = Fore.MAGENTA
-    DEPLOYMENT_ID_COLOR = Fore.CYAN
-    OPERATION_INFO_COLOR = Fore.RESET
-    NODE_ID_COLOR = Fore.BLUE
-    SOURCE_ID_COLOR = Fore.BLUE
-    TARGET_ID_COLOR = Fore.BLUE
-    OPERATION_COLOR = Fore.YELLOW
-
-    # colors entire message part according to event type
-    _message_color_by_event_type = {
-        'workflow_started': Style.BRIGHT + Fore.GREEN,
-        'workflow_succeeded': Style.BRIGHT + Fore.GREEN,
-        'workflow_failed': Style.BRIGHT + Fore.RED,
-        'workflow_cancelled': Style.BRIGHT + Fore.YELLOW,
-
-        'sending_task': Fore.RESET,
-        'task_started': Fore.RESET,
-        'task_succeeded': Fore.GREEN,
-        'task_rescheduled': Fore.YELLOW,
-        'task_failed': Fore.RED
-    }
-
-    # colors only the log level part
-    _log_level_to_color = {
-        'INFO': Fore.CYAN,
-        'WARN': Fore.YELLOW,
-        'WARNING': Fore.YELLOW,
-        'ERROR': Fore.RED,
-        'FATAL': Fore.RED
-    }
-
-    _color_context = RESET_COLOR
-
-    @property
-    def operation_info(self):
-        color = self.OPERATION_INFO_COLOR
-
-        with self._nest_colors(color):
-            op_info = super(ColorfulEvent, self).operation_info
-
-        return self._color_message(op_info, color)
-
-    @property
-    def text(self):
-        event_type = super(ColorfulEvent, self).event_type  # might be None
-        color = self._message_color_by_event_type.get(event_type)
-
-        with self._nest_colors(color):
-            msg = super(ColorfulEvent, self).text
-
-        return self._color_message(msg, color)
-
-    @property
-    def log_level(self):
-        lvl = super(ColorfulEvent, self).log_level
-        color = self._log_level_to_color.get(lvl)
-        return self._color_message(lvl, color)
-
-    @colorful_property
-    def timestamp(self):
-        return self.TIMESTAMP_COLOR
-
-    @colorful_property
-    def printable_timestamp(self):
-        return self.TIMESTAMP_COLOR
-
-    @colorful_property
-    def event_type_indicator(self):
-        return self.LOG_TYPE_COLOR if self.is_log_message else \
-            self.EVENT_TYPE_COLOR
-
-    @colorful_property
-    def operation(self):
-        return self.OPERATION_COLOR
-
-    @colorful_property
-    def node_id(self):
-        return self.NODE_ID_COLOR
-
-    @colorful_property
-    def source_id(self):
-        return self.SOURCE_ID_COLOR
-
-    @colorful_property
-    def target_id(self):
-        return self.TARGET_ID_COLOR
-
-    @colorful_property
-    def deployment_id(self):
-        return self.DEPLOYMENT_ID_COLOR
-
-    @contextmanager
-    def _nest_colors(self, nesting_color):
-        prev_color_context = self._color_context
-        if nesting_color:
-            self._color_context = nesting_color
-        yield
-        self._color_context = prev_color_context
-
-    def _color_message(self, val, color):
-        if not val or not color:
-            return val
-
-        return "{0}{1}{2}".format(
-            color,
-            val,
-            self._color_context)

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/5dc3a58b/aria/cli/commands/executions.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/executions.py b/aria/cli/commands/executions.py
index 396985a..730fd29 100644
--- a/aria/cli/commands/executions.py
+++ b/aria/cli/commands/executions.py
@@ -13,6 +13,8 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import os
+
 from .. import utils
 from ..table import print_data
 from ..cli import aria
@@ -152,7 +154,7 @@ def start(workflow_name,
     execution = workflow_runner.execution
     logger.info('Execution has ended with "{0}" status'.format(execution.status))
     if execution.status == Execution.FAILED and execution.error:
-        logger.info('Execution error:\n{0}'.format(execution.error))
+        logger.info('Execution error:{0}{1}'.format(os.linesep, execution.error))
 
     if dry:
         # remove traces of the dry execution (including tasks, logs, inputs..)

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/5dc3a58b/aria/cli/commands/service_templates.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/service_templates.py b/aria/cli/commands/service_templates.py
index e2e21c7..79b2104 100644
--- a/aria/cli/commands/service_templates.py
+++ b/aria/cli/commands/service_templates.py
@@ -43,17 +43,17 @@ def service_templates():
 
 @service_templates.command(name='show',
                            short_help='Show service template information')
-@aria.argument('service-template-id')
+@aria.argument('service-template-name')
 @aria.options.verbose()
 @aria.pass_model_storage
 @aria.pass_logger
-def show(service_template_id, model_storage, logger):
+def show(service_template_name, model_storage, logger):
     """Show information for a specific service templates
 
-    `SERVICE_TEMPLATE_ID` is the id of the service template to show information on.
+    `SERVICE_TEMPLATE_NAME` is the name of the service template to show information on.
     """
-    logger.info('Showing service template {0}...'.format(service_template_id))
-    service_template = model_storage.service_template.get(service_template_id)
+    logger.info('Showing service template {0}...'.format(service_template_name))
+    service_template = model_storage.service_template.get_by_name(service_template_name)
     services = [d.to_dict() for d in service_template.services]
     service_template_dict = service_template.to_dict()
     service_template_dict['#services'] = len(services)
@@ -62,10 +62,12 @@ def show(service_template_id, model_storage, logger):
 
     if service_template_dict['description'] is not None:
         logger.info('Description:')
-        logger.info('{0}\n'.format(service_template_dict['description'].encode('UTF-8') or ''))
+        logger.info('{0}{1}'.format(service_template_dict['description'].encode('UTF-8') or '',
+                                    os.linesep))
 
     logger.info('Existing services:')
-    logger.info('{0}\n'.format([s['name'] for s in services]))
+    logger.info('{0}{1}'.format([s['name'] for s in services],
+                                os.linesep))
 
 
 @service_templates.command(name='list',
@@ -97,7 +99,7 @@ def list(sort_by, descending, model_storage, logger):
 @service_templates.command(name='store',
                            short_help='Store a service template')
 @aria.argument('service-template-path')
-@aria.argument('service-template-name')
+@aria.options.service_template_filename
 @aria.options.verbose()
 @aria.pass_model_storage
 @aria.pass_resource_storage

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/5dc3a58b/aria/cli/constants.py
----------------------------------------------------------------------
diff --git a/aria/cli/constants.py b/aria/cli/constants.py
index 67c094d..c68fb5e 100644
--- a/aria/cli/constants.py
+++ b/aria/cli/constants.py
@@ -14,5 +14,5 @@
 # limitations under the License.
 
 
-SAMPLE_SERVICE_TEMPLATE_FILENAME = 'service_template.yaml'
+DEFAULT_SERVICE_TEMPLATE_FILENAME = 'service_template.yaml'
 HELP_TEXT_COLUMN_BUFFER = 5

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/5dc3a58b/aria/cli/csar.py
----------------------------------------------------------------------
diff --git a/aria/cli/csar.py b/aria/cli/csar.py
index 5ab581b..5bc35ac 100644
--- a/aria/cli/csar.py
+++ b/aria/cli/csar.py
@@ -136,7 +136,7 @@ class _CSARReader(object):
         self.logger.debug('Attempting to parse CSAR metadata YAML')
         with open(csar_metafile) as f:
             self.metadata.update(yaml.load(f))
-        self.logger.debug('CSAR metadata:\n{0}'.format(pprint.pformat(self.metadata)))
+        self.logger.debug('CSAR metadata:{0}{1}'.format(os.linesep, pprint.pformat(self.metadata)))
 
     def _validate(self):
         def validate_key(key, expected=None):

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/5dc3a58b/aria/cli/env.py
----------------------------------------------------------------------
diff --git a/aria/cli/env.py b/aria/cli/env.py
index 6d02cf5..7fe656f 100644
--- a/aria/cli/env.py
+++ b/aria/cli/env.py
@@ -29,7 +29,7 @@ from ..storage.filesystem_rapi import FileSystemResourceAPI
 ARIA_DEFAULT_WORKDIR_NAME = '.aria'
 
 
-class Environment(object):
+class _Environment(object):
 
     def __init__(self, workdir):
 
@@ -112,7 +112,7 @@ class Environment(object):
         return PluginManager(self.model_storage, self._plugins_dir)
 
 
-env = Environment(os.path.join(
+env = _Environment(os.path.join(
     os.environ.get('ARIA_WORKDIR', os.path.expanduser('~')), ARIA_DEFAULT_WORKDIR_NAME))
 
 logger = env.logging.logger

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/5dc3a58b/aria/cli/inputs.py
----------------------------------------------------------------------
diff --git a/aria/cli/inputs.py b/aria/cli/inputs.py
index 2077b67..78db846 100644
--- a/aria/cli/inputs.py
+++ b/aria/cli/inputs.py
@@ -46,21 +46,21 @@ def inputs_to_dict(resources):
             except AriaCliError:
                 raise AriaCliError(
                     "Invalid input: {0}. It must represent a dictionary. "
-                    "Valid values can be one of:\n "
-                    "- A path to a YAML file\n "
-                    "- A path to a directory containing YAML files\n "
+                    "Valid values can be one of:{1} "
+                    "- A path to a YAML file{1} "
+                    "- A path to a directory containing YAML files{1} "
                     "- A single quoted wildcard based path "
-                    "(e.g. '*-inputs.yaml')\n "
-                    "- A string formatted as JSON/YAML\n "
+                    "(e.g. '*-inputs.yaml'){1} "
+                    "- A string formatted as JSON/YAML{1} "
                     "- A string formatted as key1=value1;key2=value2".format(
-                        resource))
+                        resource, os.linesep))
     return parsed_dict
 
 
 def _parse_single_input(resource):
     try:
         # parse resource as string representation of a dictionary
-        return plain_string_to_dict(resource)
+        return _plain_string_to_dict(resource)
     except AriaCliError:
         input_files = glob.glob(resource)
         parsed_dict = dict()
@@ -98,7 +98,7 @@ def _parse_yaml_path(resource):
     return content
 
 
-def plain_string_to_dict(input_string):
+def _plain_string_to_dict(input_string):
     input_string = input_string.strip()
     input_dict = {}
     mapped_inputs = input_string.split(';')

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/5dc3a58b/aria/cli/service_template_utils.py
----------------------------------------------------------------------
diff --git a/aria/cli/service_template_utils.py b/aria/cli/service_template_utils.py
index 7f79668..caeb5c1 100644
--- a/aria/cli/service_template_utils.py
+++ b/aria/cli/service_template_utils.py
@@ -19,11 +19,11 @@ from urlparse import urlparse
 from . import csar
 from . import utils
 from .exceptions import AriaCliError
-from .constants import SAMPLE_SERVICE_TEMPLATE_FILENAME
+from .constants import DEFAULT_SERVICE_TEMPLATE_FILENAME
 from ..utils import archive as archive_utils
 
 
-def get(source, service_template_filename=SAMPLE_SERVICE_TEMPLATE_FILENAME):
+def get(source, service_template_filename=DEFAULT_SERVICE_TEMPLATE_FILENAME):
     """Get a source and return a path to the main service template file
 
     The behavior based on then source argument content is:
@@ -85,7 +85,7 @@ def _get_service_template_file_from_archive(archive, service_template_filename):
     if csar.is_csar_archive(archive):
         service_template_file = _extract_csar_archive(archive)
     else:
-        extract_directory = archive_utils.extract_archive(archive)(archive)
+        extract_directory = archive_utils.extract_archive(archive)
         service_template_dir = os.path.join(
             extract_directory,
             os.listdir(extract_directory)[0],
@@ -116,13 +116,13 @@ def _map_to_github_url(source):
     return url
 
 
-def generate_id(service_template_path, service_template_filename=SAMPLE_SERVICE_TEMPLATE_FILENAME):
+def generate_id(service_template_path, service_template_filename=DEFAULT_SERVICE_TEMPLATE_FILENAME):
     """The name of the service template will be the name of the folder.
     If service_template_filename is provided, it will be appended to the folder.
     """
     service_template_id = os.path.split(os.path.dirname(os.path.abspath(
         service_template_path)))[-1]
-    if service_template_filename != SAMPLE_SERVICE_TEMPLATE_FILENAME:
+    if service_template_filename != DEFAULT_SERVICE_TEMPLATE_FILENAME:
         filename, _ = os.path.splitext(os.path.basename(service_template_filename))
         service_template_id = (service_template_id + '.' + filename)
     return service_template_id.replace('_', '-')

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/5dc3a58b/aria/cli/utils.py
----------------------------------------------------------------------
diff --git a/aria/cli/utils.py b/aria/cli/utils.py
index 44358ec..fad1b07 100644
--- a/aria/cli/utils.py
+++ b/aria/cli/utils.py
@@ -147,15 +147,15 @@ def generate_progress_handler(file_path, action='', max_bar_length=80):
         sys.stdout.write('\r{0} {1} |{2}| {3}%'.format(
             action, file_name, bar, percents))
         if read_bytes >= total_bytes:
-            sys.stdout.write('\n')
+            sys.stdout.write(os.linesep)
 
     return print_progress
 
 
 def handle_storage_exception(e, model_class, name):
     if 'UNIQUE constraint failed' in e.message:
-        msg = 'Could not store {model_class} `{name}`\n' \
+        msg = 'Could not store {model_class} `{name}`{linesep}' \
               'There already a exists a {model_class} with the same name' \
-              .format(model_class=model_class, name=name)
+              .format(model_class=model_class, name=name, linesep=os.linesep)
         raise AriaCliError(msg)
     raise AriaCliError()

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/5dc3a58b/aria/core.py
----------------------------------------------------------------------
diff --git a/aria/core.py b/aria/core.py
index 057f716..0be53c6 100644
--- a/aria/core.py
+++ b/aria/core.py
@@ -14,12 +14,7 @@
 # limitations under the License.
 
 from . import exceptions
-from .parser.consumption import (
-    ConsumptionContext,
-    ConsumerChain,
-    Read,
-    Validate,
-    ServiceTemplate)
+from .parser import consumption
 from .parser.loading.location import UriLocation
 from .storage import exceptions as storage_exceptions
 
@@ -72,7 +67,9 @@ class Core(object):
         service_template = self.model_storage.service_template.get(service_template_id)
 
         # creating an empty ConsumptionContext, initiating a threadlocal context
-        ConsumptionContext()
+        consumption.ConsumptionContext()
+        # setting no autoflush for the duration of instantiation - this helps avoid dependency
+        # constraints as they're being set up
         with self.model_storage._all_api_kwargs['session'].no_autoflush:
             service = service_template.instantiate(None, inputs)
 
@@ -109,9 +106,15 @@ class Core(object):
 
     @staticmethod
     def _parse_service_template(service_template_path):
-        context = ConsumptionContext()
+        context = consumption.ConsumptionContext()
         context.presentation.location = UriLocation(service_template_path)
-        ConsumerChain(context, (Read, Validate, ServiceTemplate)).consume()
+        consumption.ConsumerChain(
+            context,
+            (
+                consumption.Read,
+                consumption.Validate,
+                consumption.ServiceTemplate
+            )).consume()
         if context.validation.dump_issues():
             raise exceptions.ParsingError('Failed to parse service template')
         return context

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/5dc3a58b/aria/modeling/service_common.py
----------------------------------------------------------------------
diff --git a/aria/modeling/service_common.py b/aria/modeling/service_common.py
index 17e0a17..d39c7b7 100644
--- a/aria/modeling/service_common.py
+++ b/aria/modeling/service_common.py
@@ -87,8 +87,8 @@ class ParameterBase(TemplateModelMixin):
         if self.description:
             console.puts(context.style.meta(self.description))
 
-    @classmethod
-    def unwrap_dict(cls, parameters_dict):
+    @staticmethod
+    def unwrap_dict(parameters_dict):
         """
         Takes a parameters dict and simplifies it into key-value dict
         :param parameters_dict: a parameter-name to parameter dict
@@ -107,12 +107,10 @@ class ParameterBase(TemplateModelMixin):
         :param description: Description (optional)
         :type description: basestring
         """
-
-        from . import models
-        return models.Parameter(name=name,
-                                type_name=formatting.full_type_name(value),
-                                value=value,
-                                description=description)
+        return cls(name=name,
+                   type_name=formatting.full_type_name(value),
+                   value=value,
+                   description=description)
 
 
 class TypeBase(InstanceModelMixin):

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/5dc3a58b/aria/modeling/service_template.py
----------------------------------------------------------------------
diff --git a/aria/modeling/service_template.py b/aria/modeling/service_template.py
index 6271bf7..8703164 100644
--- a/aria/modeling/service_template.py
+++ b/aria/modeling/service_template.py
@@ -289,7 +289,6 @@ class ServiceTemplateBase(TemplateModelMixin):
                                  service_template=self)
         context.modeling.instance = service
 
-        # utils.instantiate_dict(self, service.inputs, self.inputs)
         service.inputs = utils.create_inputs(inputs or {}, self.inputs)
         # TODO: now that we have inputs, we should scan properties and inputs and evaluate functions
 

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/5dc3a58b/aria/modeling/utils.py
----------------------------------------------------------------------
diff --git a/aria/modeling/utils.py b/aria/modeling/utils.py
index 917f495..91d7b9c 100644
--- a/aria/modeling/utils.py
+++ b/aria/modeling/utils.py
@@ -13,6 +13,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import os
 from json import JSONEncoder
 from StringIO import StringIO
 
@@ -94,8 +95,8 @@ def _merge_and_validate_inputs(inputs, template_inputs):
     if wrong_type_inputs:
         error_message = StringIO()
         for param_name, param_type in wrong_type_inputs.iteritems():
-            error_message.write('Input "{0}" must be of type {1}\n'.
-                                format(param_name, param_type))
+            error_message.write('Input "{0}" must be of type {1}{2}'
+                                .format(param_name, param_type, os.linesep))
         raise exceptions.InputsOfWrongTypeException(error_message.getvalue())
 
     undeclared_inputs = [input_name for input_name in inputs.keys()

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/5dc3a58b/aria/orchestrator/workflows/exceptions.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflows/exceptions.py b/aria/orchestrator/workflows/exceptions.py
index 4fb8dd7..0d64d65 100644
--- a/aria/orchestrator/workflows/exceptions.py
+++ b/aria/orchestrator/workflows/exceptions.py
@@ -16,6 +16,8 @@
 """
 Workflow related Exception classes
 """
+import os
+
 from .. import exceptions
 
 
@@ -52,10 +54,10 @@ class ProcessException(ExecutorException):
         Describes the error in detail
         """
         return (
-            'Command "{error.command}" executed with an error.\n'
-            'code: {error.return_code}\n'
-            'error: {error.stderr}\n'
-            'output: {error.stdout}'.format(error=self))
+            'Command "{error.command}" executed with an error.{0}'
+            'code: {error.return_code}{0}'
+            'error: {error.stderr}{0}'
+            'output: {error.stdout}'.format(os.linesep, error=self))
 
 
 class AriaEngineError(exceptions.AriaError):

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/5dc3a58b/aria/orchestrator/workflows/executor/dry.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflows/executor/dry.py b/aria/orchestrator/workflows/executor/dry.py
index c2b5341..b14f5d7 100644
--- a/aria/orchestrator/workflows/executor/dry.py
+++ b/aria/orchestrator/workflows/executor/dry.py
@@ -41,11 +41,9 @@ class DryExecutor(BaseExecutor):
         inputs = Parameter.unwrap_dict(task.inputs)
 
         task.context.logger.info(
-            'Executing {actor_type} {actor_name} operation {interface_name} {operation_name}: '
-            '{implementation} (Inputs: {inputs})'
-            .format(actor_type=actor_type, actor_name=task.actor.name,
-                    interface_name=task.interface_name, operation_name=task.operation_name,
-                    implementation=implementation, inputs=inputs))
+            'Executing {actor_type} {task.actor.name} operation {task.interface_name} '
+            '{task.operation_name}: {implementation} (Inputs: {inputs})'
+            .format(actor_type=actor_type, task=task, implementation=implementation, inputs=inputs))
 
         # updating the task manually instead of calling self._task_succeeded(task),
         # to avoid any side effects raising that event might cause

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/5dc3a58b/aria/storage/instrumentation.py
----------------------------------------------------------------------
diff --git a/aria/storage/instrumentation.py b/aria/storage/instrumentation.py
index fb95fcf..bb21b19 100644
--- a/aria/storage/instrumentation.py
+++ b/aria/storage/instrumentation.py
@@ -13,6 +13,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import os
 import copy
 import json
 
@@ -189,9 +190,9 @@ def apply_tracked_changes(tracked_changes, model):
             if not value:
                 del successfully_updated_changes[key]
         model.logger.error(
-            'Registering all the changes to the storage has failed. \n'
-            'The successful updates were: \n '
-            '{0}'.format(json.dumps(successfully_updated_changes, indent=4)))
+            'Registering all the changes to the storage has failed. {0}'
+            'The successful updates were: {0} '
+            '{1}'.format(os.linesep, json.dumps(successfully_updated_changes, indent=4)))
 
         raise
 

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/5dc3a58b/aria/utils/formatting.py
----------------------------------------------------------------------
diff --git a/aria/utils/formatting.py b/aria/utils/formatting.py
index f0ef146..b5e141d 100644
--- a/aria/utils/formatting.py
+++ b/aria/utils/formatting.py
@@ -111,21 +111,6 @@ def decode_dict(data):
     return decoded_dict
 
 
-def try_convert_from_str(string, target_type):
-    if target_type == basestring:
-        return string
-    if target_type == bool:
-        if string.lower() == 'true':
-            return True
-        if string.lower() == 'false':
-            return False
-        return string
-    try:
-        return target_type(string)
-    except ValueError:
-        return string
-
-
 def safe_str(value):
     """
     Like :code:`str` coercion, but makes sure that Unicode strings are properly

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/5dc3a58b/tests/cli/test_service_templates.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_service_templates.py b/tests/cli/test_service_templates.py
index d357fad..7cf6baf 100644
--- a/tests/cli/test_service_templates.py
+++ b/tests/cli/test_service_templates.py
@@ -1,5 +1,5 @@
 from aria.cli import service_template_utils
-from aria.cli.env import Environment
+from aria.cli.env import _Environment as Environment
 from aria.cli.exceptions import AriaCliError
 from aria.core import Core
 from aria.exceptions import AriaException

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/5dc3a58b/tests/mock/models.py
----------------------------------------------------------------------
diff --git a/tests/mock/models.py b/tests/mock/models.py
index 9771fe2..4b935d2 100644
--- a/tests/mock/models.py
+++ b/tests/mock/models.py
@@ -169,10 +169,9 @@ def create_interface(service, interface_name, operation_name, operation_kwargs=N
     the_type = service.service_template.interface_types.get_descendant('test_interface_type')
 
     if operation_kwargs and operation_kwargs.get('inputs'):
-        wrapped_inputs = {}
-        for input_name, input_value in operation_kwargs['inputs'].iteritems():
-            wrapped_inputs[input_name] = models.Parameter.wrap(input_name, input_value)
-        operation_kwargs['inputs'] = wrapped_inputs
+        operation_kwargs['inputs'] = dict(
+            (input_name, models.Parameter.wrap(input_name, input_value))
+            for input_name, input_value in operation_kwargs['inputs'].iteritems())
 
     operation = models.Operation(
         name=operation_name,

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/5dc3a58b/tests/utils/test_threading.py
----------------------------------------------------------------------
diff --git a/tests/utils/test_threading.py b/tests/utils/test_threading.py
index 39ce717..d24661f 100644
--- a/tests/utils/test_threading.py
+++ b/tests/utils/test_threading.py
@@ -19,17 +19,15 @@ import pytest
 from aria.utils import threading
 
 
-class TestPluginManager(object):
+def test_exception_raised_from_thread():
 
-    def test_exception_raised_from_thread(self):
+    def error_raising_func():
+        raise ValueError('This is an error')
 
-        def error_raising_func():
-            raise ValueError('This is an error')
+    thread = threading.ExceptionThread(target=error_raising_func)
+    thread.start()
+    thread.join()
 
-        thread = threading.ExceptionThread(target=error_raising_func)
-        thread.start()
-        thread.join()
-
-        assert thread.is_error()
-        with pytest.raises(ValueError):
-            thread.raise_error_if_exists()
+    assert thread.is_error()
+    with pytest.raises(ValueError):
+        thread.raise_error_if_exists()


[19/19] incubator-ariatosca git commit: Change Environment to _Environment

Posted by av...@apache.org.
Change Environment to _Environment


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

Branch: refs/heads/cli-tests
Commit: d2953788eefca44c27bcbb5df63b251b6a49ade3
Parents: 68c814e
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Sat Apr 15 15:50:56 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Sat Apr 15 15:56:15 2017 +0300

----------------------------------------------------------------------
 tests/cli/test_node_templates.py    | 14 +++++++-------
 tests/cli/test_nodes.py             | 10 +++++-----
 tests/cli/test_service_templates.py | 22 +++++++++++-----------
 tests/cli/test_services.py          | 26 +++++++++++++-------------
 4 files changed, 36 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/d2953788/tests/cli/test_node_templates.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_node_templates.py b/tests/cli/test_node_templates.py
index fbf784c..f0ad539 100644
--- a/tests/cli/test_node_templates.py
+++ b/tests/cli/test_node_templates.py
@@ -1,7 +1,7 @@
 from mock import ANY
 import pytest
 
-from aria.cli.env import _Environment as Environment
+from aria.cli.env import _Environment
 from tests.cli.base_test import TestCliBase, mock_storage  # pylint: disable=unused-import
 
 
@@ -9,7 +9,7 @@ class TestNodeTemplatesShow(TestCliBase):
 
     def test_no_properties_no_nodes(self, monkeypatch, mock_storage):
 
-        monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+        monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
         self.invoke('node_templates show 1')
         assert 'Showing node template 1' in self.logger_output_string
         assert 'Node template properties:' in self.logger_output_string
@@ -21,7 +21,7 @@ class TestNodeTemplatesShow(TestCliBase):
 
     def test_one_property_no_nodes(self, monkeypatch, mock_storage):
 
-        monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+        monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
         self.invoke('node_templates show 2')
         assert 'Showing node template 2' in self.logger_output_string
         assert 'Node template properties:' in self.logger_output_string
@@ -32,7 +32,7 @@ class TestNodeTemplatesShow(TestCliBase):
 
     def test_no_properties_one_node(self, monkeypatch, mock_storage):
 
-        monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+        monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
         self.invoke('node_templates show 3')
         assert 'Showing node template 3' in self.logger_output_string
         assert 'Node template properties:' in self.logger_output_string
@@ -44,7 +44,7 @@ class TestNodeTemplatesShow(TestCliBase):
 
     def test_one_property_one_node(self, monkeypatch, mock_storage):
 
-        monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+        monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
         self.invoke('node_templates show 4')
         assert 'Showing node template 4' in self.logger_output_string
         assert 'Node template properties:' in self.logger_output_string
@@ -65,7 +65,7 @@ class TestNodeTemplatesList(TestCliBase):
     def test_list_specified_service_template(self, monkeypatch, mock_storage, sort_by, order,
                                              sort_by_in_output, order_in_output):
 
-        monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+        monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
         self.invoke('node_templates list -t test_st{sort_by}{order}'.format(sort_by=sort_by,
                                                                             order=order))
         assert 'Listing node templates for service template test_st...' in self.logger_output_string
@@ -87,7 +87,7 @@ class TestNodeTemplatesList(TestCliBase):
     def test_list_no_specified_service_template(self, monkeypatch, mock_storage, sort_by, order,
                                                 sort_by_in_output, order_in_output):
 
-        monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+        monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
         self.invoke('node_templates list{sort_by}{order}'.format(sort_by=sort_by, order=order))
         assert 'Listing all node templates...' in self.logger_output_string
         assert 'Listing node templates for service template test_st...' not in \

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/d2953788/tests/cli/test_nodes.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_nodes.py b/tests/cli/test_nodes.py
index 74e551e..9be97ca 100644
--- a/tests/cli/test_nodes.py
+++ b/tests/cli/test_nodes.py
@@ -1,7 +1,7 @@
 import pytest
 from mock import ANY
 
-from aria.cli.env import _Environment as Environment
+from aria.cli.env import _Environment
 from tests.cli.base_test import TestCliBase, mock_storage  # pylint: disable=unused-import
 
 
@@ -9,7 +9,7 @@ class TestNodesShow(TestCliBase):
 
     def test_no_attributes(self, monkeypatch, mock_storage):
 
-        monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+        monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
         self.invoke('nodes show 1')
         assert 'Showing node 1' in self.logger_output_string
         assert 'Node:' in self.logger_output_string
@@ -20,7 +20,7 @@ class TestNodesShow(TestCliBase):
 
     def test_one_attribute(self, monkeypatch, mock_storage):
 
-        monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+        monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
         self.invoke('nodes show 2')
         assert 'Showing node 2' in self.logger_output_string
         assert 'Node:' in self.logger_output_string
@@ -40,7 +40,7 @@ class TestNodesList(TestCliBase):
     def test_list_specified_service(self, monkeypatch, mock_storage, sort_by, order,
                                     sort_by_in_output, order_in_output):
 
-        monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+        monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
         self.invoke('nodes list -s test_s{sort_by}{order}'.format(sort_by=sort_by,
                                                                   order=order))
         assert 'Listing nodes for service test_s...' in self.logger_output_string
@@ -62,7 +62,7 @@ class TestNodesList(TestCliBase):
     def test_list_no_specified_service(self, monkeypatch, mock_storage, sort_by, order,
                                        sort_by_in_output, order_in_output):
 
-        monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+        monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
         self.invoke('nodes list{sort_by}{order}'.format(sort_by=sort_by,
                                                         order=order))
         assert 'Listing nodes for service test_s...' not in self.logger_output_string

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/d2953788/tests/cli/test_service_templates.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_service_templates.py b/tests/cli/test_service_templates.py
index 83ee35a..ef70c37 100644
--- a/tests/cli/test_service_templates.py
+++ b/tests/cli/test_service_templates.py
@@ -1,7 +1,7 @@
 import pytest
 
 from aria.cli import service_template_utils, csar
-from aria.cli.env import _Environment as Environment
+from aria.cli.env import _Environment
 from aria.cli.exceptions import AriaCliError
 from aria.core import Core
 from aria.exceptions import AriaException
@@ -13,7 +13,7 @@ class TestServiceTemplatesShow(TestCliBase):
 
     def test_show_no_services_no_description(self, monkeypatch, mock_storage):
 
-        monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+        monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
         self.invoke('service_templates show no_services_no_description')
 
         assert 'Showing service template no_services_no_description...' in self.logger_output_string
@@ -22,7 +22,7 @@ class TestServiceTemplatesShow(TestCliBase):
 
     def test_show_no_services_yes_description(self, monkeypatch, mock_storage):
 
-        monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+        monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
         self.invoke('service_templates show no_services_yes_description')
 
         assert 'Showing service template no_services_yes_description...' in \
@@ -32,7 +32,7 @@ class TestServiceTemplatesShow(TestCliBase):
 
     def test_show_one_service_no_description(self, monkeypatch, mock_storage):
 
-        monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+        monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
         self.invoke('service_templates show one_service_no_description')
 
         assert 'Showing service template one_service_no_description...' in self.logger_output_string
@@ -41,7 +41,7 @@ class TestServiceTemplatesShow(TestCliBase):
 
     def test_show_one_service_yes_description(self, monkeypatch, mock_storage):
 
-        monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+        monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
         self.invoke('service_templates show one_service_yes_description')
 
         assert 'Showing service template one_service_yes_description...' in \
@@ -61,7 +61,7 @@ class TestServiceTemplatesList(TestCliBase):
     def test_all_sorting_combinations(self, monkeypatch, mock_storage, sort_by, order,
                                       sort_by_in_output, order_in_output):
 
-        monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+        monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
         self.invoke('service_templates list{sort_by}{order}'.format(sort_by=sort_by, order=order))
 
         mock_storage.service_template.list.assert_called_with(
@@ -76,7 +76,7 @@ class TestServiceTemplatesStore(TestCliBase):
 
         monkeypatch.setattr(Core, 'create_service_template', mock_object)
         monkeypatch.setattr(service_template_utils, 'get', mock_object)
-        outcome = self.invoke('service_templates store stubpath test_st')
+        self.invoke('service_templates store stubpath test_st')
         assert 'Storing service template test_st...' in self.logger_output_string
         assert 'Service template test_st stored' in self.logger_output_string
 
@@ -112,7 +112,7 @@ class TestServiceTemplatesDelete(TestCliBase):
 
     def test_delete_no_exception(self, monkeypatch, mock_object):
 
-        monkeypatch.setattr(Environment, 'model_storage', 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 'Deleting service template test_st...' in self.logger_output_string
@@ -120,7 +120,7 @@ class TestServiceTemplatesDelete(TestCliBase):
 
     def test_delete_raises_exception(self, monkeypatch, mock_object):
 
-        monkeypatch.setattr(Environment, 'model_storage', mock_object)
+        monkeypatch.setattr(_Environment, 'model_storage', mock_object)
         monkeypatch.setattr(Core,
                             'delete_service_template',
                             raise_exception(storage_exceptions.NotFoundError))
@@ -135,13 +135,13 @@ class TestServiceTemplatesDelete(TestCliBase):
 class TestServiceTemplatesInputs(TestCliBase):
 
     def test_inputs_existing_inputs(self, monkeypatch, mock_storage):
-        monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+        monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
         self.invoke('service_templates inputs with_inputs')
         assert 'Showing inputs for service template with_inputs...' in self.logger_output_string
         assert 'input1' in self.logger_output_string and 'value1' in self.logger_output_string
 
     def test_inputs_no_inputs(self, monkeypatch, mock_storage):
-        monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+        monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
         self.invoke('service_templates inputs without_inputs')
         assert 'Showing inputs for service template without_inputs...' in self.logger_output_string
         assert 'No inputs' in self.logger_output_string

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/d2953788/tests/cli/test_services.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_services.py b/tests/cli/test_services.py
index f22fe88..116e449 100644
--- a/tests/cli/test_services.py
+++ b/tests/cli/test_services.py
@@ -1,7 +1,7 @@
 import pytest
 from mock import ANY
 from aria.cli.exceptions import AriaCliError
-from aria.cli.env import _Environment as Environment
+from aria.cli.env import _Environment
 from aria.core import Core
 from aria.exceptions import (AriaException, DependentActiveExecutionsError,
                              DependentAvailableNodesError)
@@ -21,7 +21,7 @@ class TestServicesList(TestCliBase):
     def test_list_no_specified_service_template(self, monkeypatch, mock_storage, sort_by, order,
                                                 sort_by_in_output, order_in_output):
 
-        monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+        monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
         self.invoke('services list{sort_by}{order}'.format(sort_by=sort_by, order=order))
         assert 'Listing all services...' in self.logger_output_string
         assert 'Listing services for service template' not in self.logger_output_string
@@ -41,7 +41,7 @@ class TestServicesList(TestCliBase):
     def test_list_specified_service_template(self, monkeypatch, mock_storage, sort_by, order,
                                              sort_by_in_output, order_in_output):
 
-        monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+        monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
         self.invoke('services list -t test_st{sort_by}{order}'.format(sort_by=sort_by, order=order))
         assert 'Listing services for service template test_st...' in self.logger_output_string
         assert 'Listing all services...' not in self.logger_output_string
@@ -57,7 +57,7 @@ class TestServicesCreate(TestCliBase):
 
     def test_create_no_exception(self, monkeypatch, mock_object):
 
-        monkeypatch.setattr(Environment, 'model_storage', mock_object)
+        monkeypatch.setattr(_Environment, 'model_storage', mock_object)
 
         test_st = create_service_template('test_st')
         mock_object.return_value = create_service(test_st, 'test_s')
@@ -69,7 +69,7 @@ class TestServicesCreate(TestCliBase):
 
     def test_store_raises_storage_error_resulting_from_name_uniqueness(self, monkeypatch,
                                                                        mock_object):
-        monkeypatch.setattr(Environment, 'model_storage', mock_object)
+        monkeypatch.setattr(_Environment, 'model_storage', mock_object)
         monkeypatch.setattr(Core,
                             'create_service',
                             raise_exception(storage_exceptions.NotFoundError,
@@ -84,7 +84,7 @@ class TestServicesCreate(TestCliBase):
         assert "Service created. The service's name is test_s" not in self.logger_output_string
 
     def test_store_raises_other_storage_error(self, monkeypatch, mock_object):
-        monkeypatch.setattr(Environment, 'model_storage', mock_object)
+        monkeypatch.setattr(_Environment, 'model_storage', mock_object)
         monkeypatch.setattr(Core,
                             'create_service',
                             raise_exception(storage_exceptions.NotFoundError))
@@ -97,7 +97,7 @@ class TestServicesCreate(TestCliBase):
         assert "Service created. The service's name is test_s" not in self.logger_output_string
 
     def test_store_raises_aria_exception(self, monkeypatch, mock_storage):
-        monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+        monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
         monkeypatch.setattr(Core,
                             'create_service',
                             raise_exception(AriaException, msg='error creating service `test_s`'))
@@ -118,14 +118,14 @@ class TestServicesDelete(TestCliBase):
 
     def test_delete_no_exception(self, monkeypatch, mock_object):
 
-        monkeypatch.setattr(Environment, 'model_storage', mock_object)
+        monkeypatch.setattr(_Environment, 'model_storage', mock_object)
         monkeypatch.setattr(Core, 'delete_service', mock_object)
         self.invoke('services delete test_s')
         assert 'Deleting service test_s...' in self.logger_output_string
         assert 'Service test_s deleted' in self.logger_output_string
 
     def test_delete_active_execution_error(self, monkeypatch, mock_storage):
-        monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+        monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
         assert_exception_raised(
             self.invoke('services delete service_with_active_executions'),
             expected_exception=DependentActiveExecutionsError,
@@ -135,7 +135,7 @@ class TestServicesDelete(TestCliBase):
         assert 'Deleting service service_with_active_executions...' in self.logger_output_string
 
     def test_delete_available_nodes_error(self, monkeypatch, mock_storage):
-        monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+        monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
         assert_exception_raised(
             self.invoke('services delete service_with_available_nodes'),
             expected_exception=DependentAvailableNodesError,
@@ -145,7 +145,7 @@ class TestServicesDelete(TestCliBase):
         assert 'Deleting service service_with_available_nodes...' in self.logger_output_string
 
     def test_delete_available_nodes_error_with_force(self, monkeypatch, mock_storage):
-        monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+        monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
         self.invoke('services delete service_with_available_nodes --force')
 
         assert mock_storage.service.delete.call_count == 1
@@ -159,7 +159,7 @@ class TestServicesOutputs(TestCliBase):
 class TestServicesInputs(TestCliBase):
 
     def test_inputs_no_inputs(self, monkeypatch, mock_storage):
-        monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+        monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
         self.invoke('services inputs service_with_no_inputs')
 
         assert 'Showing inputs for service service_with_no_inputs...' in self.logger_output_string
@@ -169,7 +169,7 @@ class TestServicesInputs(TestCliBase):
 
     def test_inputs_one_input(self, monkeypatch, mock_storage):
 
-        monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+        monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
         self.invoke('services inputs service_with_one_input')
 
         assert 'Showing inputs for service service_with_one_input...' in self.logger_output_string


[15/19] incubator-ariatosca git commit: Add tests for nodes show and nodes list

Posted by av...@apache.org.
Add tests for nodes show and nodes list


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

Branch: refs/heads/cli-tests
Commit: 0876e3cf087aa620906bb8473381cbc153ea7fa4
Parents: fc3ba61
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Thu Apr 13 17:13:04 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Sat Apr 15 15:51:54 2017 +0300

----------------------------------------------------------------------
 tests/cli/test_nodes.py | 75 ++++++++++++++++++++++++++++++++++++++++++++
 tests/cli/utils.py      | 26 +++++++++++++--
 tests/mock/models.py    |  9 +++---
 3 files changed, 104 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/0876e3cf/tests/cli/test_nodes.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_nodes.py b/tests/cli/test_nodes.py
new file mode 100644
index 0000000..7817e86
--- /dev/null
+++ b/tests/cli/test_nodes.py
@@ -0,0 +1,75 @@
+import pytest
+from mock import ANY
+
+from aria.cli.env import Environment
+from tests.cli.base_test import TestCliBase, mock_storage
+
+
+class TestNodesShow(TestCliBase):
+
+    def test_no_attributes(self, monkeypatch, mock_storage):
+
+        monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+        self.invoke('nodes show 1')
+        assert 'Showing node 1' in self.logger_output_string
+        assert 'Node:' in self.logger_output_string
+        assert 'Node attributes:' in self.logger_output_string
+        assert 'No attributes' in self.logger_output_string
+        assert 'attribute1' not in self.logger_output_string and 'value1' not in self.logger_output_string
+
+    def test_one_attribute(self, monkeypatch, mock_storage):
+
+        monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+        self.invoke('nodes show 2')
+        assert 'Showing node 2' in self.logger_output_string
+        assert 'Node:' in self.logger_output_string
+        assert 'Node attributes:' in self.logger_output_string
+        assert 'No attributes' not in self.logger_output_string
+        assert 'attribute1' in self.logger_output_string and 'value1' in self.logger_output_string
+
+
+class TestNodesList(TestCliBase):
+
+    @pytest.mark.parametrize('sort_by, order, sort_by_in_output, order_in_output', [
+        ('', '', 'service_name', 'asc'),
+        ('', ' --descending', 'service_name', 'desc'),
+        (' --sort-by name', '', 'name', 'asc'),
+        (' --sort-by name', ' --descending', 'name', 'desc')
+    ])
+    def test_list_specified_service(self, monkeypatch, mock_storage, sort_by, order,
+                                    sort_by_in_output, order_in_output):
+
+        monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+        self.invoke('nodes list -s test_s{sort_by}{order}'.format(sort_by=sort_by,
+                                                                  order=order))
+        assert 'Listing nodes for service test_s...' in self.logger_output_string
+        assert 'Listing all nodes...' not in self.logger_output_string
+
+        nodes_list = mock_storage.node.list
+        nodes_list.assert_called_once_with(sort={sort_by_in_output: order_in_output},
+                                           filters={'service': ANY})
+        assert 'Nodes:' in self.logger_output_string
+        assert 'test_s' in self.logger_output_string
+        assert 'test_n' in self.logger_output_string
+
+    @pytest.mark.parametrize('sort_by, order, sort_by_in_output, order_in_output', [
+        ('', '', 'service_name', 'asc'),
+        ('', ' --descending', 'service_name', 'desc'),
+        (' --sort-by name', '', 'name', 'asc'),
+        (' --sort-by name', ' --descending', 'name', 'desc')
+    ])
+    def test_list_specified_service(self, monkeypatch, mock_storage, sort_by, order,
+                                    sort_by_in_output, order_in_output):
+
+        monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+        self.invoke('nodes list{sort_by}{order}'.format(sort_by=sort_by,
+                                                        order=order))
+        assert 'Listing nodes for service test_s...' not in self.logger_output_string
+        assert 'Listing all nodes...' in self.logger_output_string
+
+        nodes_list = mock_storage.node.list
+        nodes_list.assert_called_once_with(sort={sort_by_in_output: order_in_output},
+                                           filters={})
+        assert 'Nodes:' in self.logger_output_string
+        assert 'test_s' in self.logger_output_string
+        assert 'test_n' in self.logger_output_string

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/0876e3cf/tests/cli/utils.py
----------------------------------------------------------------------
diff --git a/tests/cli/utils.py b/tests/cli/utils.py
index b538826..a3868ab 100644
--- a/tests/cli/utils.py
+++ b/tests/cli/utils.py
@@ -50,6 +50,7 @@ class MockStorage(object):
         self.service_template = MockServiceTemplateStorage
         self.service = MockServiceStorage()
         self.node_template = MockNodeTemplateStorage()
+        self.node = MockNodeStorage()
 
 
 class MockServiceTemplateStorage(object):
@@ -118,6 +119,7 @@ class MockServiceStorage(object):
     @staticmethod
     def get_by_name(name):
         test_st = mock_models.create_service_template('test_st')
+        test_s = mock_models.create_service(test_st, 'test_s')
         if name == 'service_with_active_executions':
             m = MagicMock()
             m.id = '1'
@@ -127,9 +129,9 @@ class MockServiceStorage(object):
             m.id = '2'
             return m
         elif name == 'service_with_no_inputs':
-            test_s = mock_models.create_service(test_st, 'service_with_no_inputs')
+            test_s. name = 'service_with_no_inputs'
         elif name == 'service_with_one_input':
-            test_s = mock_models.create_service(test_st, 'service_with_one_input')
+            test_s.name = 'service_with_one_input'
             input = mock_models.create_parameter(name='input1', value='value1')
             test_s.inputs = {'input1': input}
 
@@ -160,3 +162,23 @@ class MockNodeTemplateStorage(object):
             nt.properties = {'prop1': prop1}
             mock_models.create_node('node1', nt, s)
         return nt
+
+class MockNodeStorage(object):
+
+    def __init__(self):
+        self.st = mock_models.create_service_template('test_st')
+        self.s = mock_models.create_service(self.st, 'test_s')
+        self.nt = mock_models.create_node_template(service_template=self.st, name='test_nt')
+        self.list = MagicMock(return_value=[mock_models.create_node('test_n', self.nt, self.s)])
+
+    @staticmethod
+    def get(id):
+        st = mock_models.create_service_template('test_st')
+        s = mock_models.create_service(st, 'test_s')
+        nt = mock_models.create_node_template(service_template=st, name='test_nt')
+        n = mock_models.create_node('test_n', nt, s)
+        if id == '1':
+            pass
+        elif id == '2':
+            n.runtime_properties = {'attribute1': 'value1'}
+        return n

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/0876e3cf/tests/mock/models.py
----------------------------------------------------------------------
diff --git a/tests/mock/models.py b/tests/mock/models.py
index a2b119d..57f48e3 100644
--- a/tests/mock/models.py
+++ b/tests/mock/models.py
@@ -141,13 +141,14 @@ def create_dependent_node_template(
     )
 
 
-def create_node(name, dependency_node_template, service,
-                interfaces=None, state=models.Node.INITIAL):
-
+def create_node(name, dependency_node_template, service, state=models.Node.INITIAL,
+                runtime_properties=None):
+    runtime_properties = runtime_properties or {}
+    tmp_runtime_properties = {'ip': '1.1.1.1'}
     node = models.Node(
         name=name,
         type=dependency_node_template.type,
-        runtime_properties={'ip': '1.1.1.1'},
+        runtime_properties=runtime_properties,
         version=None,
         node_template=dependency_node_template,
         state=state,


[08/19] incubator-ariatosca git commit: Add tests for services list

Posted by av...@apache.org.
Add tests for services list


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

Branch: refs/heads/cli-tests
Commit: 5968eb5d13c63fd5baaa19de6fe5d59cb40378d9
Parents: 3560ea2
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Wed Apr 12 15:58:32 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Sat Apr 15 15:51:54 2017 +0300

----------------------------------------------------------------------
 aria/cli/commands/services.py       |  4 +--
 tests/cli/base_test.py              |  2 +-
 tests/cli/test_services.py          | 57 ++++++++++++++++++++++++++++++++
 tests/cli/utils.py                  | 15 ++++++++-
 tests/storage/test_model_storage.py |  2 +-
 5 files changed, 75 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/5968eb5d/aria/cli/commands/services.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/services.py b/aria/cli/commands/services.py
index 1059e10..b785006 100644
--- a/aria/cli/commands/services.py
+++ b/aria/cli/commands/services.py
@@ -58,10 +58,10 @@ def list(service_template_name,
     if service_template_name:
         logger.info('Listing services for service template {0}...'.format(
             service_template_name))
-        service_template = model_storage.service_template.get(service_template_name)
+        service_template = model_storage.service_template.get_by_name(service_template_name)
         filters = dict(service_template=service_template)
     else:
-        logger.info('Listing all service...')
+        logger.info('Listing all services...')
         filters = {}
 
     services_list = [d.to_dict() for d in model_storage.service.list(

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/5968eb5d/tests/cli/base_test.py
----------------------------------------------------------------------
diff --git a/tests/cli/base_test.py b/tests/cli/base_test.py
index 430781a..a1a1acd 100644
--- a/tests/cli/base_test.py
+++ b/tests/cli/base_test.py
@@ -6,7 +6,7 @@ from utils import setup_logger, MockStorage
 import pytest
 
 
-@pytest.fixture()
+@pytest.fixture
 def mock_storage():
     return MockStorage()
 

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/5968eb5d/tests/cli/test_services.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_services.py b/tests/cli/test_services.py
new file mode 100644
index 0000000..4f7b98b
--- /dev/null
+++ b/tests/cli/test_services.py
@@ -0,0 +1,57 @@
+import pytest
+from mock import ANY
+
+from tests.cli.base_test import TestCliBase, mock_storage
+from aria.cli.env import Environment
+
+
+class TestServicesList(TestCliBase):
+
+    @pytest.mark.parametrize('sort_by, order, sort_by_in_output, order_in_output', [
+        ('', '', 'created_at', 'asc'),
+        ('', ' --descending', 'created_at', 'desc'),
+        (' --sort-by name', '', 'name', 'asc'),
+        (' --sort-by name', ' --descending', 'name', 'desc')
+    ])
+    def test_services_list_specified_service_template(self, monkeypatch, mock_storage, sort_by,
+                                                      order, sort_by_in_output, order_in_output):
+
+        monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+        self.invoke('services list -t test_st{sort_by}{order}'.format(sort_by=sort_by,
+                                                                      order=order))
+        assert 'Listing services for service template test_st...' in self.logger_output_string
+        assert 'Listing all services...' not in self.logger_output_string
+
+        services_list = mock_storage.service.list
+        services_list.assert_called_once_with(sort={sort_by_in_output: order_in_output},
+                                              filters={'service_template': ANY})
+        assert 'Services:' in self.logger_output_string
+        assert 'test_st' in self.logger_output_string
+        assert 'test_s' in self.logger_output_string
+
+    @pytest.mark.parametrize('sort_by, order, sort_by_in_output, order_in_output', [
+        ('', '', 'created_at', 'asc'),
+        ('', ' --descending', 'created_at', 'desc'),
+        (' --sort-by name', '', 'name', 'asc'),
+        (' --sort-by name', ' --descending', 'name', 'desc')
+    ])
+    def test_services_list_no_specified_service_template(self, monkeypatch, mock_storage, sort_by,
+                                                         order, sort_by_in_output, order_in_output):
+
+        monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+        self.invoke('services list{sort_by}{order}'.format(sort_by=sort_by,
+                                                           order=order))
+        assert 'Listing all services...' in self.logger_output_string
+        assert 'Listing services for service template' not in self.logger_output_string
+
+        services_list = mock_storage.service.list
+        services_list.assert_called_once_with(sort={sort_by_in_output: order_in_output}, filters={})
+        assert 'Services:' in self.logger_output_string
+        assert 'test_st' in self.logger_output_string
+        assert 'test_s' in self.logger_output_string
+
+
+
+
+
+

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/5968eb5d/tests/cli/utils.py
----------------------------------------------------------------------
diff --git a/tests/cli/utils.py b/tests/cli/utils.py
index c046ed3..97f6a67 100644
--- a/tests/cli/utils.py
+++ b/tests/cli/utils.py
@@ -1,5 +1,7 @@
 import logging
 
+from mock import MagicMock
+
 from tests.mock import models
 
 
@@ -46,6 +48,7 @@ class MockStorage(object):
 
     def __init__(self):
         self.service_template = MockServiceTemplateStorage
+        self.service = MockServiceStorage()
 
 
 class MockServiceTemplateStorage(object):
@@ -80,4 +83,14 @@ class MockServiceTemplateStorage(object):
             st.inputs = {'input1': input}
         if name == 'without_inputs':
             st.inputs = {}
-        return st
\ No newline at end of file
+        if name == 'one_service':
+            service = models.create_service(st, 'test_s')
+            st.services = [service]
+        return st
+
+
+class MockServiceStorage(object):
+
+    def __init__(self):
+        st = models.create_service_template('test_st')
+        self.list = MagicMock(return_value=[models.create_service(st, 'test_s')])

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/5968eb5d/tests/storage/test_model_storage.py
----------------------------------------------------------------------
diff --git a/tests/storage/test_model_storage.py b/tests/storage/test_model_storage.py
index 4dabfaf..8dd781b 100644
--- a/tests/storage/test_model_storage.py
+++ b/tests/storage/test_model_storage.py
@@ -167,7 +167,7 @@ class MockModel(modeling.models.aria_declarative_base, modeling.mixins.ModelMixi
 
 class TestFilterOperands(object):
 
-    @pytest.fixture()
+    @pytest.fixture
     def storage(self):
         model_storage = application_model_storage(
             sql_mapi.SQLAlchemyModelAPI, initiator=tests_storage.init_inmemory_model_storage)


[05/19] incubator-ariatosca git commit: Add checking for initial logger strings for service templates

Posted by av...@apache.org.
Add checking for initial logger strings for service templates


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

Branch: refs/heads/cli-tests
Commit: f2b387bc98f51a2222c6aeabe41c0695d6cefc33
Parents: 0876e3c
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Thu Apr 13 17:59:04 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Sat Apr 15 15:51:54 2017 +0300

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


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/f2b387bc/tests/cli/test_service_templates.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_service_templates.py b/tests/cli/test_service_templates.py
index 45656cd..ea16f8b 100644
--- a/tests/cli/test_service_templates.py
+++ b/tests/cli/test_service_templates.py
@@ -16,6 +16,7 @@ class TestServiceTemplatesShow(TestCliBase):
         monkeypatch.setattr(Environment, 'model_storage', mock_storage)
         self.invoke('service_templates show 1')
 
+        assert 'Showing service template 1...' in self.logger_output_string
         assert 'Description:' not in self.logger_output_string
         assert 'Existing services:\n[]' in self.logger_output_string
 
@@ -24,6 +25,7 @@ class TestServiceTemplatesShow(TestCliBase):
         monkeypatch.setattr(Environment, 'model_storage', mock_storage)
         self.invoke('service_templates show 2')
 
+        assert 'Showing service template 2...' in self.logger_output_string
         assert 'Description:\ntest_description' in self.logger_output_string
         assert 'Existing services:\n[]' in self.logger_output_string
 
@@ -32,6 +34,7 @@ class TestServiceTemplatesShow(TestCliBase):
         monkeypatch.setattr(Environment, 'model_storage', mock_storage)
         self.invoke('service_templates show 3')
 
+        assert 'Showing service template 3...' in self.logger_output_string
         assert 'Description:\ntest_description' in self.logger_output_string
         assert "Existing services:\n['test_s']" in self.logger_output_string
 
@@ -40,6 +43,7 @@ class TestServiceTemplatesShow(TestCliBase):
         monkeypatch.setattr(Environment, 'model_storage', mock_storage)
         self.invoke('service_templates show 4')
 
+        assert 'Showing service template 4...' in self.logger_output_string
         assert 'Description:' not in self.logger_output_string
         assert "Existing services:\n['test_s']" in self.logger_output_string
 
@@ -52,6 +56,8 @@ class TestServiceTemplatesShow(TestCliBase):
             expected_exception=storage_exceptions.NotFoundError,
             expected_msg='Requested `ServiceTemplate` with ID `5` was not found')
 
+        assert 'Showing service template 5...' in self.logger_output_string
+
 
 class TestServiceTemplatesList(TestCliBase):
 
@@ -59,6 +65,8 @@ class TestServiceTemplatesList(TestCliBase):
 
         monkeypatch.setattr(Environment, 'model_storage', mock_storage)
         self.invoke('service_templates list')
+
+        assert 'Listing all service templates...' in self.logger_output_string
         assert 'test_st' in self.logger_output_string
         assert 'test_st2' in self.logger_output_string
 
@@ -67,18 +75,21 @@ class TestServiceTemplatesList(TestCliBase):
         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'})
+        assert 'Listing all service templates...' in self.logger_output_string
 
     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'})
+        assert 'Listing all service templates...' in self.logger_output_string
 
     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'})
+        assert 'Listing all service templates...' in self.logger_output_string
 
 
 class TestServiceTemplatesStore(TestCliBase):
@@ -88,6 +99,7 @@ class TestServiceTemplatesStore(TestCliBase):
         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 'Storing service template test_st...' in self.logger_output_string
         assert 'Service template test_st stored' in self.logger_output_string
 
     def test_store_raises_exception_resulting_from_name_uniqueness(self, monkeypatch, mock_object):
@@ -103,6 +115,7 @@ 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')
+        assert 'Storing service template test_st...' in self.logger_output_string
 
     def test_store_raises_exception(self, monkeypatch, mock_object):
 
@@ -114,6 +127,7 @@ class TestServiceTemplatesStore(TestCliBase):
         assert_exception_raised(
             self.invoke('service_templates store stubpath test_st'),
             expected_exception=AriaCliError)
+        assert 'Storing service template test_st...' in self.logger_output_string
 
 
 class TestServiceTemplatesDelete(TestCliBase):
@@ -123,6 +137,7 @@ class TestServiceTemplatesDelete(TestCliBase):
         monkeypatch.setattr(Environment, 'model_storage', mock_object)
         monkeypatch.setattr(Core, 'delete_service_template', mock_object)
         self.invoke('service_templates delete test_st')
+        assert 'Deleting service template test_st...' in self.logger_output_string
         assert 'Service template test_st deleted' in self.logger_output_string
 
     def test_delete_raises_exception(self, monkeypatch, mock_object):
@@ -136,6 +151,7 @@ class TestServiceTemplatesDelete(TestCliBase):
             self.invoke('service_templates delete test_st'),
             expected_exception=AriaCliError,
             expected_msg='')
+        assert 'Deleting service template test_st...' in self.logger_output_string
 
 
 class TestServiceTemplatesInputs(TestCliBase):
@@ -143,11 +159,13 @@ class TestServiceTemplatesInputs(TestCliBase):
     def test_inputs_existing_inputs(self, monkeypatch, mock_storage):
         monkeypatch.setattr(Environment, 'model_storage', mock_storage)
         self.invoke('service_templates inputs with_inputs')
+        assert 'Showing inputs for service template with_inputs...' in self.logger_output_string
         assert 'input1' in self.logger_output_string and 'value1' in self.logger_output_string
 
     def test_inputs_no_inputs(self, monkeypatch, mock_storage):
         monkeypatch.setattr(Environment, 'model_storage', mock_storage)
         self.invoke('service_templates inputs without_inputs')
+        assert 'Showing inputs for service template without_inputs...' in self.logger_output_string
         assert 'No inputs' in self.logger_output_string
 
 
@@ -157,6 +175,7 @@ class TestServiceTemplatesValidate(TestCliBase):
         monkeypatch.setattr(Core, 'validate_service_template', mock_object)
         monkeypatch.setattr(service_template_utils, 'get', mock_object)
         self.invoke('service_templates validate stubpath')
+        assert 'Validating service template: stubpath' in self.logger_output_string
         assert 'Service template validated successfully' in self.logger_output_string
 
     def test_validate_raises_exception(self, monkeypatch, mock_object):
@@ -165,6 +184,7 @@ class TestServiceTemplatesValidate(TestCliBase):
         assert_exception_raised(
             self.invoke('service_templates validate stubpath'),
             expected_exception=AriaCliError)
+        assert 'Validating service template: stubpath' in self.logger_output_string
 
 
 class TestServiceTemplatesCreateArchive(TestCliBase):
@@ -172,4 +192,5 @@ class TestServiceTemplatesCreateArchive(TestCliBase):
     def test_create_archive_successful(self, monkeypatch, mock_object):
         monkeypatch.setattr(csar, 'write', mock_object)
         self.invoke('service_templates create_archive stubpath stubdest')
+        assert 'Creating a csar archive' in self.logger_output_string
         assert 'Csar archive created at stubdest' in self.logger_output_string


[13/19] incubator-ariatosca git commit: Add tests for node-templates show

Posted by av...@apache.org.
Add tests for node-templates show


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

Branch: refs/heads/cli-tests
Commit: 68bf4fea6c0bc66f825fdd6bc1bc7be7cf43b014
Parents: 7be3c64
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Thu Apr 13 15:05:10 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Sat Apr 15 15:51:54 2017 +0300

----------------------------------------------------------------------
 tests/cli/base_test.py           |  5 ++--
 tests/cli/test_node_templates.py | 49 +++++++++++++++++++++++++++++++++++
 tests/cli/utils.py               | 44 +++++++++++++++++++++++--------
 tests/mock/models.py             |  2 +-
 4 files changed, 86 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/68bf4fea/tests/cli/base_test.py
----------------------------------------------------------------------
diff --git a/tests/cli/base_test.py b/tests/cli/base_test.py
index a1a1acd..9268f71 100644
--- a/tests/cli/base_test.py
+++ b/tests/cli/base_test.py
@@ -1,10 +1,11 @@
 from StringIO import StringIO
 import logging
 
-import runner
-from utils import setup_logger, MockStorage
 import pytest
 
+import tests.cli.runner as runner
+from tests.cli.utils import setup_logger, MockStorage
+
 
 @pytest.fixture
 def mock_storage():

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/68bf4fea/tests/cli/test_node_templates.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_node_templates.py b/tests/cli/test_node_templates.py
new file mode 100644
index 0000000..4fb2b9d
--- /dev/null
+++ b/tests/cli/test_node_templates.py
@@ -0,0 +1,49 @@
+from aria.cli.env import Environment
+from tests.cli.base_test import TestCliBase, mock_storage
+
+
+class TestNodeTemplatesShow(TestCliBase):
+
+    def test_no_properties_no_nodes(self, monkeypatch, mock_storage):
+
+        monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+        self.invoke('node_templates show 1')
+        assert 'Showing node template 1' in self.logger_output_string
+        assert 'Node template properties:' in self.logger_output_string
+        assert 'No properties' in self.logger_output_string
+        assert 'prop1' not in self.logger_output_string and 'value1' not in self.logger_output_string
+        assert 'No nodes' in self.logger_output_string
+        assert 'node1' not in self.logger_output_string
+
+    def test_one_property_no_nodes(self, monkeypatch, mock_storage):
+
+        monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+        self.invoke('node_templates show 2')
+        assert 'Showing node template 2' in self.logger_output_string
+        assert 'Node template properties:' in self.logger_output_string
+        assert 'No properties' not in self.logger_output_string
+        assert 'prop1' in self.logger_output_string and 'value1' in self.logger_output_string
+        assert 'No nodes' in self.logger_output_string
+        assert 'node1' not in self.logger_output_string
+
+    def test_no_properties_one_node(self, monkeypatch, mock_storage):
+
+        monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+        self.invoke('node_templates show 3')
+        assert 'Showing node template 3' in self.logger_output_string
+        assert 'Node template properties:' in self.logger_output_string
+        assert 'No properties' in self.logger_output_string
+        assert 'prop1' not in self.logger_output_string and 'value1' not in self.logger_output_string
+        assert 'No nodes' not in self.logger_output_string
+        assert 'node1' in self.logger_output_string
+
+    def test_one_property_one_node(self, monkeypatch, mock_storage):
+
+        monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+        self.invoke('node_templates show 4')
+        assert 'Showing node template 4' in self.logger_output_string
+        assert 'Node template properties:' in self.logger_output_string
+        assert 'No properties' not in self.logger_output_string
+        assert 'prop1' in self.logger_output_string and 'value1' in self.logger_output_string
+        assert 'No nodes' not in self.logger_output_string
+        assert 'node1' in self.logger_output_string

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/68bf4fea/tests/cli/utils.py
----------------------------------------------------------------------
diff --git a/tests/cli/utils.py b/tests/cli/utils.py
index 21047c9..a9ea44b 100644
--- a/tests/cli/utils.py
+++ b/tests/cli/utils.py
@@ -49,6 +49,7 @@ class MockStorage(object):
     def __init__(self):
         self.service_template = MockServiceTemplateStorage
         self.service = MockServiceStorage()
+        self.node_template = MockNodeTemplateStorage
 
 
 class MockServiceTemplateStorage(object):
@@ -63,14 +64,14 @@ class MockServiceTemplateStorage(object):
         st = mock_models.create_service_template('test_st')
         if id == '1':  # no services and no description.
             st.services = []
-        if id == '2':  # no services, but an description
+        elif id == '2':  # no services, but an description
             st.description = 'test_description'
             st.services = []
-        if id == '3':  # one service, and a description
+        elif id == '3':  # one service, and a description
             service = mock_models.create_service(st, 'test_s')
             st.description = 'test_description'
             st.services = [service]
-        if id == '4':  # one service, and a description
+        elif id == '4':  # one service, and a description
             service = mock_models.create_service(st, 'test_s')
             st.services = [service]
         return st
@@ -79,11 +80,11 @@ class MockServiceTemplateStorage(object):
     def get_by_name(name):
         st = mock_models.create_service_template('test_st')
         if name == 'with_inputs':
-            input = mock_models.create_input(name='input1', value='value1')
+            input = mock_models.create_parameter(name='input1', value='value1')
             st.inputs = {'input1': input}
-        if name == 'without_inputs':
+        elif name == 'without_inputs':
             st.inputs = {}
-        if name == 'one_service':
+        elif name == 'one_service':
             service = mock_models.create_service(st, 'test_s')
             st.services = [service]
         return st
@@ -104,7 +105,7 @@ class MockServiceStorage(object):
             execution = mock_models.create_execution(test_s, status=models.Execution.STARTED)
             execution.id = '1'
             test_s.executions = [execution]
-        if id == '2':
+        elif id == '2':
             test_s = mock_models.create_service(test_st, 'service_with_available_nodes')
             node_template = mock_models.create_node_template(service_template=test_st)
             node = mock_models.create_node(name='test_node',
@@ -121,15 +122,36 @@ class MockServiceStorage(object):
             m = MagicMock()
             m.id = '1'
             return m
-        if name == 'service_with_available_nodes':
+        elif name == 'service_with_available_nodes':
             m = MagicMock()
             m.id = '2'
             return m
-        if name == 'service_with_no_inputs':
+        elif name == 'service_with_no_inputs':
             test_s = mock_models.create_service(test_st, 'service_with_no_inputs')
-        if name == 'service_with_one_input':
+        elif name == 'service_with_one_input':
             test_s = mock_models.create_service(test_st, 'service_with_one_input')
-            input = mock_models.create_input(name='input1', value='value1')
+            input = mock_models.create_parameter(name='input1', value='value1')
             test_s.inputs = {'input1': input}
 
         return test_s
+
+
+class MockNodeTemplateStorage(object):
+
+    @staticmethod
+    def get(id):
+        st = mock_models.create_service_template('test_st')
+        s = mock_models.create_service(st, 'test_s')
+        nt = mock_models.create_node_template(service_template=st, name='test_nt')
+        if id == '1':
+            pass
+        elif id == '2':
+            prop1 = mock_models.create_parameter('prop1', 'value1')
+            nt.properties = {'prop1': prop1}
+        elif id == '3':
+            mock_models.create_node('node1', nt, s)
+        elif id == '4':
+            prop1 = mock_models.create_parameter('prop1', 'value1')
+            nt.properties = {'prop1': prop1}
+            mock_models.create_node('node1', nt, s)
+        return nt
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/68bf4fea/tests/mock/models.py
----------------------------------------------------------------------
diff --git a/tests/mock/models.py b/tests/mock/models.py
index 37ecbc0..a2b119d 100644
--- a/tests/mock/models.py
+++ b/tests/mock/models.py
@@ -238,7 +238,7 @@ def create_plugin_specification(name='test_plugin', version='0.1'):
     )
 
 
-def create_input(name, value):
+def create_parameter(name, value):
     p = models.Parameter()
     return p.wrap(name, value)
 


[06/19] incubator-ariatosca git commit: Add test for service-templates create-archive

Posted by av...@apache.org.
Add test for service-templates create-archive


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

Branch: refs/heads/cli-tests
Commit: 3560ea20a98e0b95ecec2b57a07b6fda6f8c9d0a
Parents: c538654
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Wed Apr 12 11:35:40 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Sat Apr 15 15:51:54 2017 +0300

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


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3560ea20/tests/cli/test_service_templates.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_service_templates.py b/tests/cli/test_service_templates.py
index 61999db..d8ea731 100644
--- a/tests/cli/test_service_templates.py
+++ b/tests/cli/test_service_templates.py
@@ -1,3 +1,5 @@
+from aria.cli import service_template_utils, csar
+from aria.cli.env import Environment
 from aria.cli import service_template_utils
 from aria.cli.env import _Environment as Environment
 from aria.cli.exceptions import AriaCliError
@@ -163,3 +165,11 @@ class TestServiceTemplatesValidate(TestCliBase):
         assert_exception_raised(
             self.invoke('service_templates validate stubpath'),
             expected_exception=AriaCliError)
+
+
+class TestServiceTemplatesCreateArchive(TestCliBase):
+
+    def test_create_archive_successful(self, monkeypatch, mock_object):
+        monkeypatch.setattr(csar, 'write', mock_object)
+        self.invoke('service_templates create_archive stubpath stubdest')
+        assert 'Csar archive created at stubdest' in self.logger_output_string


[03/19] incubator-ariatosca git commit: fixed service-template-filename parameter usage

Posted by av...@apache.org.
fixed service-template-filename parameter usage


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

Branch: refs/heads/cli-tests
Commit: 2e9d81a189fe0bf279749d83786b39425b109218
Parents: faa67ac
Author: Ran Ziv <ra...@gigaspaces.com>
Authored: Sat Apr 15 15:43:23 2017 +0300
Committer: Ran Ziv <ra...@gigaspaces.com>
Committed: Sat Apr 15 15:43:23 2017 +0300

----------------------------------------------------------------------
 aria/cli/commands/service_templates.py | 14 +++++++++-----
 aria/cli/service_template_utils.py     | 23 +++++++++++------------
 2 files changed, 20 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/2e9d81a1/aria/cli/commands/service_templates.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/service_templates.py b/aria/cli/commands/service_templates.py
index 79b2104..8e0e91c 100644
--- a/aria/cli/commands/service_templates.py
+++ b/aria/cli/commands/service_templates.py
@@ -99,14 +99,15 @@ def list(sort_by, descending, model_storage, logger):
 @service_templates.command(name='store',
                            short_help='Store a service template')
 @aria.argument('service-template-path')
+@aria.argument('service-template-name')
 @aria.options.service_template_filename
 @aria.options.verbose()
 @aria.pass_model_storage
 @aria.pass_resource_storage
 @aria.pass_plugin_manager
 @aria.pass_logger
-def store(service_template_path, service_template_name, model_storage, resource_storage,
-          plugin_manager, logger):
+def store(service_template_path, service_template_name, service_template_filename,
+          model_storage, resource_storage, plugin_manager, logger):
     """Store a service template
 
     `SERVICE_TEMPLATE_PATH` is the path of the service template to store.
@@ -115,7 +116,8 @@ def store(service_template_path, service_template_name, model_storage, resource_
     """
     logger.info('Storing service template {0}...'.format(service_template_name))
 
-    service_template_path = service_template_utils.get(service_template_path)
+    service_template_path = service_template_utils.get(service_template_path,
+                                                       service_template_filename)
     core = Core(model_storage, resource_storage, plugin_manager)
     try:
         core.create_service_template(service_template_path,
@@ -166,18 +168,20 @@ def inputs(service_template_name, model_storage, logger):
 @service_templates.command(name='validate',
                            short_help='Validate a service template')
 @aria.argument('service-template')
+@aria.options.service_template_filename
 @aria.options.verbose()
 @aria.pass_model_storage
 @aria.pass_resource_storage
 @aria.pass_plugin_manager
 @aria.pass_logger
-def validate(service_template, model_storage, resource_storage, plugin_manager, logger):
+def validate(service_template, service_template_filename,
+             model_storage, resource_storage, plugin_manager, logger):
     """Validate a service template
 
     `SERVICE_TEMPLATE` is the path or url of the service template or archive to validate.
     """
     logger.info('Validating service template: {0}'.format(service_template))
-    service_template_path = service_template_utils.get(service_template)
+    service_template_path = service_template_utils.get(service_template, service_template_filename)
     core = Core(model_storage, resource_storage, plugin_manager)
 
     try:

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/2e9d81a1/aria/cli/service_template_utils.py
----------------------------------------------------------------------
diff --git a/aria/cli/service_template_utils.py b/aria/cli/service_template_utils.py
index caeb5c1..3a0488b 100644
--- a/aria/cli/service_template_utils.py
+++ b/aria/cli/service_template_utils.py
@@ -19,11 +19,10 @@ from urlparse import urlparse
 from . import csar
 from . import utils
 from .exceptions import AriaCliError
-from .constants import DEFAULT_SERVICE_TEMPLATE_FILENAME
 from ..utils import archive as archive_utils
 
 
-def get(source, service_template_filename=DEFAULT_SERVICE_TEMPLATE_FILENAME):
+def get(source, service_template_filename):
     """Get a source and return a path to the main service template file
 
     The behavior based on then source argument content is:
@@ -116,16 +115,16 @@ def _map_to_github_url(source):
     return url
 
 
-def generate_id(service_template_path, service_template_filename=DEFAULT_SERVICE_TEMPLATE_FILENAME):
-    """The name of the service template will be the name of the folder.
-    If service_template_filename is provided, it will be appended to the folder.
-    """
-    service_template_id = os.path.split(os.path.dirname(os.path.abspath(
-        service_template_path)))[-1]
-    if service_template_filename != DEFAULT_SERVICE_TEMPLATE_FILENAME:
-        filename, _ = os.path.splitext(os.path.basename(service_template_filename))
-        service_template_id = (service_template_id + '.' + filename)
-    return service_template_id.replace('_', '-')
+# def generate_id(service_template_path, service_template_filename=DEFAULT_SERVICE_TEMPLATE_FILENAME):
+#     """The name of the service template will be the name of the folder.
+#     If service_template_filename is provided, it will be appended to the folder.
+#     """
+#     service_template_id = os.path.split(os.path.dirname(os.path.abspath(
+#         service_template_path)))[-1]
+#     if service_template_filename != DEFAULT_SERVICE_TEMPLATE_FILENAME:
+#         filename, _ = os.path.splitext(os.path.basename(service_template_filename))
+#         service_template_id = (service_template_id + '.' + filename)
+#     return service_template_id.replace('_', '-')
 
 
 def _is_archive(source):


[02/19] incubator-ariatosca git commit: reorded imports in logger.py

Posted by av...@apache.org.
reorded imports in logger.py


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

Branch: refs/heads/cli-tests
Commit: faa67acdb937f946eafb98c832a90e9d882406f1
Parents: 5dc3a58
Author: max-orlov <ma...@gigaspaces.com>
Authored: Thu Apr 13 17:46:18 2017 +0300
Committer: max-orlov <ma...@gigaspaces.com>
Committed: Thu Apr 13 17:46:18 2017 +0300

----------------------------------------------------------------------
 aria/logger.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/faa67acd/aria/logger.py
----------------------------------------------------------------------
diff --git a/aria/logger.py b/aria/logger.py
index 41e1ac8..dd54264 100644
--- a/aria/logger.py
+++ b/aria/logger.py
@@ -19,16 +19,16 @@ Logging related mixins and functions
 
 import logging
 from logging import handlers as logging_handlers
-from datetime import datetime
-
 # NullHandler doesn't exist in < 27. this workaround is from
 # http://docs.python.org/release/2.6/library/logging.html#configuring-logging-for-a-library
 try:
-    from logging import NullHandler
+    from logging import NullHandler                                                                 # pylint: disable=unused-import
 except ImportError:
     class NullHandler(logging.Handler):
         def emit(self, record):
             pass
+from datetime import datetime
+
 
 TASK_LOGGER_NAME = 'aria.executions.task'
 


[04/19] incubator-ariatosca git commit: Fix tests in nodes list

Posted by av...@apache.org.
Fix tests in nodes list


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

Branch: refs/heads/cli-tests
Commit: 8b2da543ea52988620cf768052083c67d558c8b1
Parents: 0058ee6
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Sat Apr 15 14:07:38 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Sat Apr 15 15:51:54 2017 +0300

----------------------------------------------------------------------
 tests/cli/test_nodes.py | 42 +++++++++++++++++++++---------------------
 1 file changed, 21 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/8b2da543/tests/cli/test_nodes.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_nodes.py b/tests/cli/test_nodes.py
index 2313241..69c8827 100644
--- a/tests/cli/test_nodes.py
+++ b/tests/cli/test_nodes.py
@@ -53,24 +53,24 @@ class TestNodesList(TestCliBase):
         assert 'test_s' in self.logger_output_string
         assert 'test_n' in self.logger_output_string
 
-    # @pytest.mark.parametrize('sort_by, order, sort_by_in_output, order_in_output', [
-    #     ('', '', 'service_name', 'asc'),
-    #     ('', ' --descending', 'service_name', 'desc'),
-    #     (' --sort-by name', '', 'name', 'asc'),
-    #     (' --sort-by name', ' --descending', 'name', 'desc')
-    # ])
-    # def test_list_specified_service(self, monkeypatch, mock_storage, sort_by, order,
-    #                                 sort_by_in_output, order_in_output):
-    #
-    #     monkeypatch.setattr(Environment, 'model_storage', mock_storage)
-    #     self.invoke('nodes list{sort_by}{order}'.format(sort_by=sort_by,
-    #                                                     order=order))
-    #     assert 'Listing nodes for service test_s...' not in self.logger_output_string
-    #     assert 'Listing all nodes...' in self.logger_output_string
-    #
-    #     nodes_list = mock_storage.node.list
-    #     nodes_list.assert_called_once_with(sort={sort_by_in_output: order_in_output},
-    #                                        filters={})
-    #     assert 'Nodes:' in self.logger_output_string
-    #     assert 'test_s' in self.logger_output_string
-    #     assert 'test_n' in self.logger_output_string
+    @pytest.mark.parametrize('sort_by, order, sort_by_in_output, order_in_output', [
+        ('', '', 'service_name', 'asc'),
+        ('', ' --descending', 'service_name', 'desc'),
+        (' --sort-by name', '', 'name', 'asc'),
+        (' --sort-by name', ' --descending', 'name', 'desc')
+    ])
+    def test_list_no_specified_service(self, monkeypatch, mock_storage, sort_by, order,
+                                       sort_by_in_output, order_in_output):
+
+        monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+        self.invoke('nodes list{sort_by}{order}'.format(sort_by=sort_by,
+                                                        order=order))
+        assert 'Listing nodes for service test_s...' not in self.logger_output_string
+        assert 'Listing all nodes...' in self.logger_output_string
+
+        nodes_list = mock_storage.node.list
+        nodes_list.assert_called_once_with(sort={sort_by_in_output: order_in_output},
+                                           filters={})
+        assert 'Nodes:' in self.logger_output_string
+        assert 'test_s' in self.logger_output_string
+        assert 'test_n' in self.logger_output_string


[10/19] incubator-ariatosca git commit: Add tests for services delete

Posted by av...@apache.org.
Add tests for services 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/b332bcb6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/b332bcb6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/b332bcb6

Branch: refs/heads/cli-tests
Commit: b332bcb6d0d5b4864326e627d8142a021bf74042
Parents: 2bda233
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Thu Apr 13 00:37:08 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Sat Apr 15 15:51:54 2017 +0300

----------------------------------------------------------------------
 tests/cli/test_services.py | 50 ++++++++++++++++++++++++++++++----
 tests/cli/utils.py         | 53 +++++++++++++++++++++++++++---------
 tests/mock/models.py       | 60 ++++++++++++++++++++++++++---------------
 3 files changed, 125 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/b332bcb6/tests/cli/test_services.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_services.py b/tests/cli/test_services.py
index 0c89b14..af10a45 100644
--- a/tests/cli/test_services.py
+++ b/tests/cli/test_services.py
@@ -3,7 +3,8 @@ from mock import ANY
 from aria.cli.exceptions import AriaCliError
 from aria.cli.env import Environment
 from aria.core import Core
-from aria.exceptions import AriaException
+from aria.exceptions import (AriaException, DependentActiveExecutionsError,
+                             DependentAvailableNodesError)
 from aria.storage import exceptions as storage_exceptions
 from tests.cli.base_test import TestCliBase, mock_storage, raise_exception, assert_exception_raised
 from tests.mock.models import create_service, create_service_template
@@ -17,8 +18,8 @@ class TestServicesList(TestCliBase):
         (' --sort-by name', '', 'name', 'asc'),
         (' --sort-by name', ' --descending', 'name', 'desc')
     ])
-    def test_services_list_specified_service_template(self, monkeypatch, mock_storage, sort_by,
-                                                      order, sort_by_in_output, order_in_output):
+    def test_list_specified_service_template(self, monkeypatch, mock_storage, sort_by, order,
+                                             sort_by_in_output, order_in_output):
 
         monkeypatch.setattr(Environment, 'model_storage', mock_storage)
         self.invoke('services list -t test_st{sort_by}{order}'.format(sort_by=sort_by,
@@ -39,8 +40,8 @@ class TestServicesList(TestCliBase):
         (' --sort-by name', '', 'name', 'asc'),
         (' --sort-by name', ' --descending', 'name', 'desc')
     ])
-    def test_services_list_no_specified_service_template(self, monkeypatch, mock_storage, sort_by,
-                                                         order, sort_by_in_output, order_in_output):
+    def test_list_no_specified_service_template(self, monkeypatch, mock_storage, sort_by, order,
+                                                sort_by_in_output, order_in_output):
 
         monkeypatch.setattr(Environment, 'model_storage', mock_storage)
         self.invoke('services list{sort_by}{order}'.format(sort_by=sort_by,
@@ -113,3 +114,42 @@ class TestServicesCreate(TestCliBase):
         assert 'error creating service `test_s`' in self.logger_output_string
         assert 'input1' in self.logger_output_string and 'value1' in self.logger_output_string
         assert "Service created. The service's name is test_s" not in self.logger_output_string
+
+
+class TestServicesDelete(TestCliBase):
+
+    def test_delete_no_exception(self, monkeypatch, mock_object):
+
+        monkeypatch.setattr(Environment, 'model_storage', mock_object)
+        monkeypatch.setattr(Core, 'delete_service', mock_object)
+        self.invoke('services delete test_s')
+        assert 'Deleting service test_s...' in self.logger_output_string
+        assert 'Service test_s deleted' in self.logger_output_string
+
+    def test_delete_active_execution_error(self, monkeypatch, mock_storage):
+        monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+        assert_exception_raised(
+            self.invoke('services delete service_with_active_executions'),
+            expected_exception=DependentActiveExecutionsError,
+            expected_msg="Can't delete service service_with_active_executions - there is an active "
+                         "execution for this service. Active execution id: 1"
+        )
+        assert 'Deleting service service_with_active_executions...' in self.logger_output_string
+
+    def test_delete_available_nodes_error(self, monkeypatch, mock_storage):
+        monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+        assert_exception_raised(
+            self.invoke('services delete service_with_available_nodes'),
+            expected_exception=DependentAvailableNodesError,
+            expected_msg="Can't delete service service_with_active_executions - "
+                         "there are available nodes for this service. Available node ids: 1"
+        )
+        assert 'Deleting service service_with_available_nodes...' in self.logger_output_string
+
+    def test_delete_available_nodes_error_with_force(self, monkeypatch, mock_storage):
+        monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+        self.invoke('services delete service_with_available_nodes --force')
+
+        assert mock_storage.service.delete.call_count == 1
+        assert 'Deleting service service_with_available_nodes...' in self.logger_output_string
+        assert 'Service service_with_available_nodes deleted' in self.logger_output_string

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/b332bcb6/tests/cli/utils.py
----------------------------------------------------------------------
diff --git a/tests/cli/utils.py b/tests/cli/utils.py
index 97f6a67..222a225 100644
--- a/tests/cli/utils.py
+++ b/tests/cli/utils.py
@@ -1,8 +1,8 @@
 import logging
-
+from aria.modeling import models
 from mock import MagicMock
 
-from tests.mock import models
+from tests.mock import models as mock_models
 
 
 def setup_logger(logger_name,
@@ -55,36 +55,36 @@ class MockServiceTemplateStorage(object):
 
     @staticmethod
     def list(**_):
-        return [models.create_service_template('test_st'),
-                models.create_service_template('test_st2')]
+        return [mock_models.create_service_template('test_st'),
+                mock_models.create_service_template('test_st2')]
 
     @staticmethod
     def get(id):
-        st = models.create_service_template('test_st')
+        st = mock_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 = []
         if id == '3':  # one service, and a description
-            service = models.create_service(st, 'test_s')
+            service = mock_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')
+            service = mock_models.create_service(st, 'test_s')
             st.services = [service]
         return st
 
     @staticmethod
     def get_by_name(name):
-        st = models.create_service_template('test_st')
+        st = mock_models.create_service_template('test_st')
         if name == 'with_inputs':
-            input = models.create_input(name='input1', value='value1')
+            input = mock_models.create_input(name='input1', value='value1')
             st.inputs = {'input1': input}
         if name == 'without_inputs':
             st.inputs = {}
         if name == 'one_service':
-            service = models.create_service(st, 'test_s')
+            service = mock_models.create_service(st, 'test_s')
             st.services = [service]
         return st
 
@@ -92,5 +92,34 @@ class MockServiceTemplateStorage(object):
 class MockServiceStorage(object):
 
     def __init__(self):
-        st = models.create_service_template('test_st')
-        self.list = MagicMock(return_value=[models.create_service(st, 'test_s')])
+        self.st = mock_models.create_service_template('test_st')
+        self.list = MagicMock(return_value=[mock_models.create_service(self.st, 'test_s')])
+        self.delete = MagicMock()
+
+    @staticmethod
+    def get(id):
+        test_st = mock_models.create_service_template('test_st')
+        test_s = mock_models.create_service(test_st, 'service_with_active_executions')
+        if id == '1':
+            execution = mock_models.create_execution(test_s, status=models.Execution.STARTED)
+            execution.id = '1'
+            test_s.executions = [execution]
+        if id == '2':
+            node_template = mock_models.create_node_template(service_template=test_st)
+            node = mock_models.create_node(name='test_node',
+                                           dependency_node_template=node_template,
+                                           service=test_s,
+                                           state=models.Node.STARTED)
+            node.id = '1'
+        return test_s
+
+    @staticmethod
+    def get_by_name(name):
+        if name == 'service_with_active_executions':
+            m = MagicMock()
+            m.id = '1'
+            return m
+        if name == 'service_with_available_nodes':
+            m = MagicMock()
+            m.id = '2'
+            return m

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/b332bcb6/tests/mock/models.py
----------------------------------------------------------------------
diff --git a/tests/mock/models.py b/tests/mock/models.py
index 4b935d2..37ecbc0 100644
--- a/tests/mock/models.py
+++ b/tests/mock/models.py
@@ -39,6 +39,7 @@ from aria.orchestrator.workflows.builtin.workflows import (
 
 SERVICE_NAME = 'test_service_name'
 SERVICE_TEMPLATE_NAME = 'test_service_template_name'
+NODE_TEMPLATE_NAME = 'test_node_template'
 WORKFLOW_NAME = 'test_workflow_name'
 TASK_RETRY_INTERVAL = 1
 TASK_MAX_ATTEMPTS = 1
@@ -80,6 +81,33 @@ def create_service(service_template, name=SERVICE_NAME):
     )
 
 
+def create_node_template(service_template,
+                         name=NODE_TEMPLATE_NAME,
+                         type=models.Type(variant='node', name='test_node_type'),
+                         capability_templates=None,
+                         requirement_templates=None,
+                         interface_templates=None,
+                         default_instances=1,
+                         min_instances=1,
+                         max_instances=1):
+    capability_templates = capability_templates or {}
+    requirement_templates = requirement_templates or []
+    interface_templates = interface_templates or {}
+    node_template = models.NodeTemplate(
+        name=name,
+        type=type,
+        capability_templates=capability_templates,
+        requirement_templates=requirement_templates,
+        interface_templates=interface_templates,
+        default_instances=default_instances,
+        min_instances=min_instances,
+        max_instances=max_instances,
+        service_template=service_template)
+
+    service_template.node_templates[node_template.name] = node_template
+    return node_template
+
+
 def create_dependency_node_template(service_template, name=DEPENDENCY_NODE_TEMPLATE_NAME):
     node_type = service_template.node_types.get_descendant('test_node_type')
     capability_type = service_template.capability_types.get_descendant('test_capability_type')
@@ -88,18 +116,12 @@ def create_dependency_node_template(service_template, name=DEPENDENCY_NODE_TEMPL
         name='capability',
         type=capability_type
     )
-
-    node_template = models.NodeTemplate(
+    return create_node_template(
+        service_template=service_template,
         name=name,
         type=node_type,
-        capability_templates=_dictify(capability_template),
-        default_instances=1,
-        min_instances=1,
-        max_instances=1,
-        service_template=service_template
+        capability_templates=_dictify(capability_template)
     )
-    service_template.node_templates[node_template.name] = node_template
-    return node_template
 
 
 def create_dependent_node_template(
@@ -110,29 +132,25 @@ def create_dependent_node_template(
         name='requirement',
         target_node_template=dependency_node_template
     )
-
-    node_template = models.NodeTemplate(
+    return create_node_template(
+        service_template=service_template,
         name=name,
         type=the_type,
-        default_instances=1,
-        min_instances=1,
-        max_instances=1,
         interface_templates=_dictify(get_standard_interface_template(service_template)),
         requirement_templates=[requirement_template],
-        service_template=service_template
     )
-    service_template.node_templates[node_template.name] = node_template
-    return node_template
 
 
-def create_node(name, dependency_node_template, service):
+def create_node(name, dependency_node_template, service,
+                interfaces=None, state=models.Node.INITIAL):
+
     node = models.Node(
         name=name,
         type=dependency_node_template.type,
         runtime_properties={'ip': '1.1.1.1'},
         version=None,
         node_template=dependency_node_template,
-        state=models.Node.INITIAL,
+        state=state,
         scaling_groups=[],
         service=service,
         interfaces=get_standard_interface(service),
@@ -185,10 +203,10 @@ def create_interface(service, interface_name, operation_name, operation_kwargs=N
     )
 
 
-def create_execution(service):
+def create_execution(service, status=models.Execution.PENDING):
     return models.Execution(
         service=service,
-        status=models.Execution.PENDING,
+        status=status,
         workflow_name=WORKFLOW_NAME,
         created_at=datetime.utcnow(),
         started_at=datetime.utcnow(),


[18/19] incubator-ariatosca git commit: Add tests for services inputs

Posted by av...@apache.org.
Add tests for services 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/7be3c645
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/7be3c645
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/7be3c645

Branch: refs/heads/cli-tests
Commit: 7be3c645c415e6eaaf42b2f52fdf52308bfedad4
Parents: b332bcb
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Thu Apr 13 12:12:22 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Sat Apr 15 15:51:54 2017 +0300

----------------------------------------------------------------------
 tests/cli/test_service_templates.py |  2 +-
 tests/cli/test_services.py          | 26 +++++++++++++++++++++++++-
 tests/cli/utils.py                  | 12 +++++++++++-
 3 files changed, 37 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7be3c645/tests/cli/test_service_templates.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_service_templates.py b/tests/cli/test_service_templates.py
index d8ea731..45656cd 100644
--- a/tests/cli/test_service_templates.py
+++ b/tests/cli/test_service_templates.py
@@ -55,7 +55,7 @@ class TestServiceTemplatesShow(TestCliBase):
 
 class TestServiceTemplatesList(TestCliBase):
 
-    def test_list_one_service_template(self, monkeypatch, mock_storage):
+    def test_list_two_service_templates(self, monkeypatch, mock_storage):
 
         monkeypatch.setattr(Environment, 'model_storage', mock_storage)
         self.invoke('service_templates list')

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7be3c645/tests/cli/test_services.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_services.py b/tests/cli/test_services.py
index af10a45..7538512 100644
--- a/tests/cli/test_services.py
+++ b/tests/cli/test_services.py
@@ -141,7 +141,7 @@ class TestServicesDelete(TestCliBase):
         assert_exception_raised(
             self.invoke('services delete service_with_available_nodes'),
             expected_exception=DependentAvailableNodesError,
-            expected_msg="Can't delete service service_with_active_executions - "
+            expected_msg="Can't delete service service_with_available_nodes - "
                          "there are available nodes for this service. Available node ids: 1"
         )
         assert 'Deleting service service_with_available_nodes...' in self.logger_output_string
@@ -153,3 +153,27 @@ class TestServicesDelete(TestCliBase):
         assert mock_storage.service.delete.call_count == 1
         assert 'Deleting service service_with_available_nodes...' in self.logger_output_string
         assert 'Service service_with_available_nodes deleted' in self.logger_output_string
+
+class TestServicesOutputs(TestCliBase):
+    # TODO implement this after the `services outputs` command will work
+    pass
+
+
+class TestServicesInputs(TestCliBase):
+
+    def test_inputs_no_inputs(self, monkeypatch, mock_storage):
+        monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+        self.invoke('services inputs service_with_no_inputs')
+
+        assert 'Showing inputs for service service_with_no_inputs...' in self.logger_output_string
+        assert 'No inputs' in self.logger_output_string
+        assert 'input1' not in self.logger_output_string and 'value1' not in self.logger_output_string
+
+    def test_inputs_one_input(self, monkeypatch, mock_storage):
+
+        monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+        self.invoke('services inputs service_with_one_input')
+
+        assert 'Showing inputs for service service_with_one_input...' in self.logger_output_string
+        assert 'input1' in self.logger_output_string and 'value1' in self.logger_output_string
+        assert 'No inputs' not in self.logger_output_string

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7be3c645/tests/cli/utils.py
----------------------------------------------------------------------
diff --git a/tests/cli/utils.py b/tests/cli/utils.py
index 222a225..21047c9 100644
--- a/tests/cli/utils.py
+++ b/tests/cli/utils.py
@@ -99,12 +99,13 @@ class MockServiceStorage(object):
     @staticmethod
     def get(id):
         test_st = mock_models.create_service_template('test_st')
-        test_s = mock_models.create_service(test_st, 'service_with_active_executions')
         if id == '1':
+            test_s = mock_models.create_service(test_st, 'service_with_active_executions')
             execution = mock_models.create_execution(test_s, status=models.Execution.STARTED)
             execution.id = '1'
             test_s.executions = [execution]
         if id == '2':
+            test_s = mock_models.create_service(test_st, 'service_with_available_nodes')
             node_template = mock_models.create_node_template(service_template=test_st)
             node = mock_models.create_node(name='test_node',
                                            dependency_node_template=node_template,
@@ -115,6 +116,7 @@ class MockServiceStorage(object):
 
     @staticmethod
     def get_by_name(name):
+        test_st = mock_models.create_service_template('test_st')
         if name == 'service_with_active_executions':
             m = MagicMock()
             m.id = '1'
@@ -123,3 +125,11 @@ class MockServiceStorage(object):
             m = MagicMock()
             m.id = '2'
             return m
+        if name == 'service_with_no_inputs':
+            test_s = mock_models.create_service(test_st, 'service_with_no_inputs')
+        if name == 'service_with_one_input':
+            test_s = mock_models.create_service(test_st, 'service_with_one_input')
+            input = mock_models.create_input(name='input1', value='value1')
+            test_s.inputs = {'input1': input}
+
+        return test_s


[12/19] incubator-ariatosca git commit: Fix pylint issues

Posted by av...@apache.org.
Fix pylint issues


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

Branch: refs/heads/cli-tests
Commit: 0058ee658341cb0f3273f3f87180c8599bd1bd2d
Parents: b36212b
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Sat Apr 15 14:04:54 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Sat Apr 15 15:51:54 2017 +0300

----------------------------------------------------------------------
 tests/cli/runner.py                 |  1 -
 tests/cli/test_node_templates.py    | 11 +++++---
 tests/cli/test_nodes.py             | 47 ++++++++++++++++----------------
 tests/cli/test_service_templates.py |  5 ++--
 tests/cli/test_services.py          | 12 ++++----
 tests/mock/models.py                |  2 +-
 6 files changed, 42 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/0058ee65/tests/cli/runner.py
----------------------------------------------------------------------
diff --git a/tests/cli/runner.py b/tests/cli/runner.py
index 8b4294a..1682f95 100644
--- a/tests/cli/runner.py
+++ b/tests/cli/runner.py
@@ -3,7 +3,6 @@ import click.testing
 
 
 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()

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/0058ee65/tests/cli/test_node_templates.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_node_templates.py b/tests/cli/test_node_templates.py
index aa202d4..090be65 100644
--- a/tests/cli/test_node_templates.py
+++ b/tests/cli/test_node_templates.py
@@ -2,7 +2,7 @@ from mock import ANY
 import pytest
 
 from aria.cli.env import Environment
-from tests.cli.base_test import TestCliBase, mock_storage
+from tests.cli.base_test import TestCliBase, mock_storage  # pylint: disable=unused-import
 
 
 class TestNodeTemplatesShow(TestCliBase):
@@ -14,7 +14,8 @@ class TestNodeTemplatesShow(TestCliBase):
         assert 'Showing node template 1' in self.logger_output_string
         assert 'Node template properties:' in self.logger_output_string
         assert 'No properties' in self.logger_output_string
-        assert 'prop1' not in self.logger_output_string and 'value1' not in self.logger_output_string
+        assert 'prop1' not in self.logger_output_string
+        assert 'value1' not in self.logger_output_string
         assert 'No nodes' in self.logger_output_string
         assert 'node1' not in self.logger_output_string
 
@@ -36,7 +37,8 @@ class TestNodeTemplatesShow(TestCliBase):
         assert 'Showing node template 3' in self.logger_output_string
         assert 'Node template properties:' in self.logger_output_string
         assert 'No properties' in self.logger_output_string
-        assert 'prop1' not in self.logger_output_string and 'value1' not in self.logger_output_string
+        assert 'prop1' not in self.logger_output_string
+        assert 'value1' not in self.logger_output_string
         assert 'No nodes' not in self.logger_output_string
         assert 'node1' in self.logger_output_string
 
@@ -88,7 +90,8 @@ class TestNodeTemplatesList(TestCliBase):
         monkeypatch.setattr(Environment, 'model_storage', mock_storage)
         self.invoke('node_templates list{sort_by}{order}'.format(sort_by=sort_by, order=order))
         assert 'Listing all node templates...' in self.logger_output_string
-        assert 'Listing node templates for service template test_st...' not in self.logger_output_string
+        assert 'Listing node templates for service template test_st...' not in \
+               self.logger_output_string
 
         node_templates_list = mock_storage.node_template.list
         node_templates_list.assert_called_once_with(sort={sort_by_in_output: order_in_output},

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/0058ee65/tests/cli/test_nodes.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_nodes.py b/tests/cli/test_nodes.py
index 7817e86..2313241 100644
--- a/tests/cli/test_nodes.py
+++ b/tests/cli/test_nodes.py
@@ -2,7 +2,7 @@ import pytest
 from mock import ANY
 
 from aria.cli.env import Environment
-from tests.cli.base_test import TestCliBase, mock_storage
+from tests.cli.base_test import TestCliBase, mock_storage  # pylint: disable=unused-import
 
 
 class TestNodesShow(TestCliBase):
@@ -15,7 +15,8 @@ class TestNodesShow(TestCliBase):
         assert 'Node:' in self.logger_output_string
         assert 'Node attributes:' in self.logger_output_string
         assert 'No attributes' in self.logger_output_string
-        assert 'attribute1' not in self.logger_output_string and 'value1' not in self.logger_output_string
+        assert 'attribute1' not in self.logger_output_string
+        assert 'value1' not in self.logger_output_string
 
     def test_one_attribute(self, monkeypatch, mock_storage):
 
@@ -52,24 +53,24 @@ class TestNodesList(TestCliBase):
         assert 'test_s' in self.logger_output_string
         assert 'test_n' in self.logger_output_string
 
-    @pytest.mark.parametrize('sort_by, order, sort_by_in_output, order_in_output', [
-        ('', '', 'service_name', 'asc'),
-        ('', ' --descending', 'service_name', 'desc'),
-        (' --sort-by name', '', 'name', 'asc'),
-        (' --sort-by name', ' --descending', 'name', 'desc')
-    ])
-    def test_list_specified_service(self, monkeypatch, mock_storage, sort_by, order,
-                                    sort_by_in_output, order_in_output):
-
-        monkeypatch.setattr(Environment, 'model_storage', mock_storage)
-        self.invoke('nodes list{sort_by}{order}'.format(sort_by=sort_by,
-                                                        order=order))
-        assert 'Listing nodes for service test_s...' not in self.logger_output_string
-        assert 'Listing all nodes...' in self.logger_output_string
-
-        nodes_list = mock_storage.node.list
-        nodes_list.assert_called_once_with(sort={sort_by_in_output: order_in_output},
-                                           filters={})
-        assert 'Nodes:' in self.logger_output_string
-        assert 'test_s' in self.logger_output_string
-        assert 'test_n' in self.logger_output_string
+    # @pytest.mark.parametrize('sort_by, order, sort_by_in_output, order_in_output', [
+    #     ('', '', 'service_name', 'asc'),
+    #     ('', ' --descending', 'service_name', 'desc'),
+    #     (' --sort-by name', '', 'name', 'asc'),
+    #     (' --sort-by name', ' --descending', 'name', 'desc')
+    # ])
+    # def test_list_specified_service(self, monkeypatch, mock_storage, sort_by, order,
+    #                                 sort_by_in_output, order_in_output):
+    #
+    #     monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+    #     self.invoke('nodes list{sort_by}{order}'.format(sort_by=sort_by,
+    #                                                     order=order))
+    #     assert 'Listing nodes for service test_s...' not in self.logger_output_string
+    #     assert 'Listing all nodes...' in self.logger_output_string
+    #
+    #     nodes_list = mock_storage.node.list
+    #     nodes_list.assert_called_once_with(sort={sort_by_in_output: order_in_output},
+    #                                        filters={})
+    #     assert 'Nodes:' in self.logger_output_string
+    #     assert 'test_s' in self.logger_output_string
+    #     assert 'test_n' in self.logger_output_string

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/0058ee65/tests/cli/test_service_templates.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_service_templates.py b/tests/cli/test_service_templates.py
index 04432e3..0a6ee77 100644
--- a/tests/cli/test_service_templates.py
+++ b/tests/cli/test_service_templates.py
@@ -8,7 +8,7 @@ from aria.cli.exceptions import AriaCliError
 from aria.core import Core
 from aria.exceptions import AriaException
 from aria.storage import exceptions as storage_exceptions
-from tests.cli.base_test import TestCliBase, assert_exception_raised, raise_exception, mock_storage
+from tests.cli.base_test import TestCliBase, assert_exception_raised, raise_exception, mock_storage  # pylint: disable=unused-import
 
 
 class TestServiceTemplatesShow(TestCliBase):
@@ -75,7 +75,8 @@ class TestServiceTemplatesList(TestCliBase):
         monkeypatch.setattr(Environment, 'model_storage', mock_storage)
         self.invoke('service_templates list{sort_by}{order}'.format(sort_by=sort_by, order=order))
 
-        mock_storage.service_template.list.assert_called_with(sort={sort_by_in_output: order_in_output})
+        mock_storage.service_template.list.assert_called_with(
+            sort={sort_by_in_output: order_in_output})
         assert 'Listing all service templates...' in self.logger_output_string
         assert 'test_st' in self.logger_output_string
 

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/0058ee65/tests/cli/test_services.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_services.py b/tests/cli/test_services.py
index 38b3348..932c95b 100644
--- a/tests/cli/test_services.py
+++ b/tests/cli/test_services.py
@@ -6,7 +6,7 @@ from aria.core import Core
 from aria.exceptions import (AriaException, DependentActiveExecutionsError,
                              DependentAvailableNodesError)
 from aria.storage import exceptions as storage_exceptions
-from tests.cli.base_test import TestCliBase, mock_storage, raise_exception, assert_exception_raised
+from tests.cli.base_test import TestCliBase, raise_exception, assert_exception_raised, mock_storage  #pylint: disable=unused-import
 from tests.mock.models import create_service, create_service_template
 
 
@@ -107,7 +107,8 @@ class TestServicesCreate(TestCliBase):
             expected_exception=AriaCliError,
             expected_msg='error creating service `test_s`')
 
-        assert 'Creating new service from service template with_inputs...' in self.logger_output_string
+        assert 'Creating new service from service template with_inputs...' in \
+               self.logger_output_string
         assert 'error creating service `test_s`' in self.logger_output_string
         assert 'input1' in self.logger_output_string and 'value1' in self.logger_output_string
         assert "Service created. The service's name is test_s" not in self.logger_output_string
@@ -152,7 +153,6 @@ class TestServicesDelete(TestCliBase):
         assert 'Service service_with_available_nodes deleted' in self.logger_output_string
 
 class TestServicesOutputs(TestCliBase):
-    # TODO implement this after the `services outputs` command will work
     pass
 
 
@@ -164,7 +164,8 @@ class TestServicesInputs(TestCliBase):
 
         assert 'Showing inputs for service service_with_no_inputs...' in self.logger_output_string
         assert 'No inputs' in self.logger_output_string
-        assert 'input1' not in self.logger_output_string and 'value1' not in self.logger_output_string
+        assert 'input1' not in self.logger_output_string
+        assert 'value1' not in self.logger_output_string
 
     def test_inputs_one_input(self, monkeypatch, mock_storage):
 
@@ -172,5 +173,6 @@ class TestServicesInputs(TestCliBase):
         self.invoke('services inputs service_with_one_input')
 
         assert 'Showing inputs for service service_with_one_input...' in self.logger_output_string
-        assert 'input1' in self.logger_output_string and 'value1' in self.logger_output_string
+        assert 'input1' in self.logger_output_string
+        assert 'value1' in self.logger_output_string
         assert 'No inputs' not in self.logger_output_string

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/0058ee65/tests/mock/models.py
----------------------------------------------------------------------
diff --git a/tests/mock/models.py b/tests/mock/models.py
index 57f48e3..38c2b28 100644
--- a/tests/mock/models.py
+++ b/tests/mock/models.py
@@ -144,7 +144,7 @@ def create_dependent_node_template(
 def create_node(name, dependency_node_template, service, state=models.Node.INITIAL,
                 runtime_properties=None):
     runtime_properties = runtime_properties or {}
-    tmp_runtime_properties = {'ip': '1.1.1.1'}
+    # tmp_runtime_properties = {'ip': '1.1.1.1'}
     node = models.Node(
         name=name,
         type=dependency_node_template.type,


[07/19] incubator-ariatosca git commit: Refactor basetest and fixtures

Posted by av...@apache.org.
Refactor basetest and fixtures


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

Branch: refs/heads/cli-tests
Commit: c538654a59cf658923530ca852d7b599185683d2
Parents: 2e9d81a
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Tue Apr 11 18:48:42 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Sat Apr 15 15:51:54 2017 +0300

----------------------------------------------------------------------
 tests/cli/base_test.py              | 10 ++--
 tests/cli/test_service_templates.py | 79 ++++++--------------------------
 tests/cli/utils.py                  | 43 +++++++++++++++++
 tests/conftest.py                   |  5 ++
 4 files changed, 70 insertions(+), 67 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/c538654a/tests/cli/base_test.py
----------------------------------------------------------------------
diff --git a/tests/cli/base_test.py b/tests/cli/base_test.py
index 55da476..430781a 100644
--- a/tests/cli/base_test.py
+++ b/tests/cli/base_test.py
@@ -1,11 +1,16 @@
 from StringIO import StringIO
 import logging
-#
+
 import runner
-from utils import setup_logger
+from utils import setup_logger, MockStorage
 import pytest
 
 
+@pytest.fixture()
+def mock_storage():
+    return MockStorage()
+
+
 @pytest.mark.usefixtures("redirect_logger")
 class TestCliBase(object):
 
@@ -54,4 +59,3 @@ def get_default_logger_config():
             'level': logger.level}
 
 _default_logger_config = get_default_logger_config()
-

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/c538654a/tests/cli/test_service_templates.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_service_templates.py b/tests/cli/test_service_templates.py
index 7cf6baf..61999db 100644
--- a/tests/cli/test_service_templates.py
+++ b/tests/cli/test_service_templates.py
@@ -4,87 +4,38 @@ from aria.cli.exceptions import AriaCliError
 from aria.core import Core
 from aria.exceptions import AriaException
 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
-
-
-class MockServiceTemplateStorage(object):
-
-    @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 = []
-        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
-
-    @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
+from tests.cli.base_test import TestCliBase, assert_exception_raised, raise_exception, mock_storage
 
 
 class TestServiceTemplatesShow(TestCliBase):
 
-    def test_show_no_services_no_description(self, monkeypatch):
+    def test_show_no_services_no_description(self, monkeypatch, mock_storage):
 
-        monkeypatch.setattr(Environment, 'model_storage', MockStorage())
+        monkeypatch.setattr(Environment, 'model_storage', mock_storage)
         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):
+    def test_show_no_services_yes_description(self, monkeypatch, mock_storage):
 
-        monkeypatch.setattr(Environment, 'model_storage', MockStorage())
+        monkeypatch.setattr(Environment, 'model_storage', mock_storage)
         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):
+    def test_show_one_service_yes_description(self, monkeypatch, mock_storage):
 
-        monkeypatch.setattr(Environment, 'model_storage', MockStorage())
+        monkeypatch.setattr(Environment, 'model_storage', mock_storage)
         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):
+    def test_show_one_service_no_description(self, monkeypatch, mock_storage):
 
-        monkeypatch.setattr(Environment, 'model_storage', MockStorage())
+        monkeypatch.setattr(Environment, 'model_storage', mock_storage)
         self.invoke('service_templates show 4')
 
         assert 'Description:' not in self.logger_output_string
@@ -102,9 +53,9 @@ class TestServiceTemplatesShow(TestCliBase):
 
 class TestServiceTemplatesList(TestCliBase):
 
-    def test_list_one_service_template(self, monkeypatch):
+    def test_list_one_service_template(self, monkeypatch, mock_storage):
 
-        monkeypatch.setattr(Environment, 'model_storage', MockStorage())
+        monkeypatch.setattr(Environment, 'model_storage', mock_storage)
         self.invoke('service_templates list')
         assert 'test_st' in self.logger_output_string
         assert 'test_st2' in self.logger_output_string
@@ -187,13 +138,13 @@ class TestServiceTemplatesDelete(TestCliBase):
 
 class TestServiceTemplatesInputs(TestCliBase):
 
-    def test_inputs_existing_inputs(self, monkeypatch):
-        monkeypatch.setattr(Environment, 'model_storage', MockStorage())
+    def test_inputs_existing_inputs(self, monkeypatch, mock_storage):
+        monkeypatch.setattr(Environment, 'model_storage', mock_storage)
         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())
+    def test_inputs_no_inputs(self, monkeypatch, mock_storage):
+        monkeypatch.setattr(Environment, 'model_storage', mock_storage)
         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/c538654a/tests/cli/utils.py
----------------------------------------------------------------------
diff --git a/tests/cli/utils.py b/tests/cli/utils.py
index 7093e34..c046ed3 100644
--- a/tests/cli/utils.py
+++ b/tests/cli/utils.py
@@ -1,5 +1,7 @@
 import logging
 
+from tests.mock import models
+
 
 def setup_logger(logger_name,
                  level=logging.INFO,
@@ -38,3 +40,44 @@ def setup_logger(logger_name,
         logger.propagate = False
 
     return logger
+
+
+class MockStorage(object):
+
+    def __init__(self):
+        self.service_template = MockServiceTemplateStorage
+
+
+class MockServiceTemplateStorage(object):
+
+    @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 = []
+        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
+
+    @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
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/c538654a/tests/conftest.py
----------------------------------------------------------------------
diff --git a/tests/conftest.py b/tests/conftest.py
index 312ee0b..8f2c273 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -40,3 +40,8 @@ def logging_handler_cleanup(request):
     def clear_logging_handlers():
         logging.getLogger(logger.TASK_LOGGER_NAME).handlers = []
     request.addfinalizer(clear_logging_handlers)
+
+
+@pytest.fixture
+def mock_object(mocker):
+    return mocker.MagicMock()


[11/19] incubator-ariatosca git commit: Add tests for services create

Posted by av...@apache.org.
Add tests for services create


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

Branch: refs/heads/cli-tests
Commit: 2bda233546972e25128dc6a68667dacc1a604315
Parents: 5968eb5
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Wed Apr 12 17:36:03 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Sat Apr 15 15:51:54 2017 +0300

----------------------------------------------------------------------
 tests/cli/test_services.py          | 62 ++++++++++++++++++++++++++++++--
 tests/storage/test_model_storage.py |  2 +-
 2 files changed, 61 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/2bda2335/tests/cli/test_services.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_services.py b/tests/cli/test_services.py
index 4f7b98b..0c89b14 100644
--- a/tests/cli/test_services.py
+++ b/tests/cli/test_services.py
@@ -1,8 +1,12 @@
 import pytest
 from mock import ANY
-
-from tests.cli.base_test import TestCliBase, mock_storage
+from aria.cli.exceptions import AriaCliError
 from aria.cli.env import Environment
+from aria.core import Core
+from aria.exceptions import AriaException
+from aria.storage import exceptions as storage_exceptions
+from tests.cli.base_test import TestCliBase, mock_storage, raise_exception, assert_exception_raised
+from tests.mock.models import create_service, create_service_template
 
 
 class TestServicesList(TestCliBase):
@@ -51,7 +55,61 @@ class TestServicesList(TestCliBase):
         assert 'test_s' in self.logger_output_string
 
 
+class TestServicesCreate(TestCliBase):
+
+    def test_create_no_exception(self, monkeypatch, mock_object):
+
+        monkeypatch.setattr(Environment, 'model_storage', mock_object)
+
+        test_st = create_service_template('test_st')
+        mock_object.return_value = create_service(test_st, 'test_s')
+        monkeypatch.setattr(Core, 'create_service', mock_object)
+        self.invoke('services create -t test_st test_s')
+
+        assert 'Creating new service from service template test_st...' in self.logger_output_string
+        assert "Service created. The service's name is test_s" in self.logger_output_string
 
+    def test_store_raises_storage_error_resulting_from_name_uniqueness(self, monkeypatch,
+                                                                       mock_object):
+        monkeypatch.setattr(Environment, 'model_storage', mock_object)
+        monkeypatch.setattr(Core,
+                            'create_service',
+                            raise_exception(storage_exceptions.NotFoundError,
+                                            msg='UNIQUE constraint failed'))
+        assert_exception_raised(
+            self.invoke('services create -t test_st test_s'),
+            expected_exception=AriaCliError,
+            expected_msg='Could not store service `test_s`\n'
+                         'There already a exists a service with the same name')
 
+        assert 'Creating new service from service template test_st...' in self.logger_output_string
+        assert "Service created. The service's name is test_s" not in self.logger_output_string
+
+    def test_store_raises_other_storage_error(self, monkeypatch, mock_object):
+        monkeypatch.setattr(Environment, 'model_storage', mock_object)
+        monkeypatch.setattr(Core,
+                            'create_service',
+                            raise_exception(storage_exceptions.NotFoundError))
+
+        assert_exception_raised(
+            self.invoke('services create -t test_st test_s'),
+            expected_exception=AriaCliError)
+
+        assert 'Creating new service from service template test_st...' in self.logger_output_string
+        assert "Service created. The service's name is test_s" not in self.logger_output_string
+
+    def test_store_raises_aria_exception(self, monkeypatch, mock_storage):
+        monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+        monkeypatch.setattr(Core,
+                            'create_service',
+                            raise_exception(AriaException, msg='error creating service `test_s`'))
 
+        assert_exception_raised(
+            self.invoke('services create -t with_inputs test_s'),
+            expected_exception=AriaCliError,
+            expected_msg='error creating service `test_s`')
 
+        assert 'Creating new service from service template with_inputs...' in self.logger_output_string
+        assert 'error creating service `test_s`' in self.logger_output_string
+        assert 'input1' in self.logger_output_string and 'value1' in self.logger_output_string
+        assert "Service created. The service's name is test_s" not in self.logger_output_string

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/2bda2335/tests/storage/test_model_storage.py
----------------------------------------------------------------------
diff --git a/tests/storage/test_model_storage.py b/tests/storage/test_model_storage.py
index 8dd781b..4dabfaf 100644
--- a/tests/storage/test_model_storage.py
+++ b/tests/storage/test_model_storage.py
@@ -167,7 +167,7 @@ class MockModel(modeling.models.aria_declarative_base, modeling.mixins.ModelMixi
 
 class TestFilterOperands(object):
 
-    @pytest.fixture
+    @pytest.fixture()
     def storage(self):
         model_storage = application_model_storage(
             sql_mapi.SQLAlchemyModelAPI, initiator=tests_storage.init_inmemory_model_storage)


[16/19] incubator-ariatosca git commit: Refactor service names in the mock storage

Posted by av...@apache.org.
Refactor service names in the mock storage


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

Branch: refs/heads/cli-tests
Commit: b36212b45e8dfad69fe8a784bbe24904a7bb6cd8
Parents: 968cd2b
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Thu Apr 13 18:40:17 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Sat Apr 15 15:51:54 2017 +0300

----------------------------------------------------------------------
 tests/cli/test_services.py | 4 ++--
 tests/cli/utils.py         | 6 ++----
 2 files changed, 4 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/b36212b4/tests/cli/test_services.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_services.py b/tests/cli/test_services.py
index 89b3a89..38b3348 100644
--- a/tests/cli/test_services.py
+++ b/tests/cli/test_services.py
@@ -128,7 +128,7 @@ class TestServicesDelete(TestCliBase):
         assert_exception_raised(
             self.invoke('services delete service_with_active_executions'),
             expected_exception=DependentActiveExecutionsError,
-            expected_msg="Can't delete service service_with_active_executions - there is an active "
+            expected_msg="Can't delete service test_s - there is an active "
                          "execution for this service. Active execution id: 1"
         )
         assert 'Deleting service service_with_active_executions...' in self.logger_output_string
@@ -138,7 +138,7 @@ class TestServicesDelete(TestCliBase):
         assert_exception_raised(
             self.invoke('services delete service_with_available_nodes'),
             expected_exception=DependentAvailableNodesError,
-            expected_msg="Can't delete service service_with_available_nodes - "
+            expected_msg="Can't delete service test_s - "
                          "there are available nodes for this service. Available node ids: 1"
         )
         assert 'Deleting service service_with_available_nodes...' in self.logger_output_string

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/b36212b4/tests/cli/utils.py
----------------------------------------------------------------------
diff --git a/tests/cli/utils.py b/tests/cli/utils.py
index 94523e2..499732a 100644
--- a/tests/cli/utils.py
+++ b/tests/cli/utils.py
@@ -99,13 +99,12 @@ class MockServiceStorage(object):
     @staticmethod
     def get(id):
         test_st = mock_models.create_service_template('test_st')
+        test_s = mock_models.create_service(test_st, 'test_s')
         if id == '1':
-            test_s = mock_models.create_service(test_st, 'service_with_active_executions')
             execution = mock_models.create_execution(test_s, status=models.Execution.STARTED)
             execution.id = '1'
             test_s.executions = [execution]
         elif id == '2':
-            test_s = mock_models.create_service(test_st, 'service_with_available_nodes')
             node_template = mock_models.create_node_template(service_template=test_st)
             node = mock_models.create_node(name='test_node',
                                            dependency_node_template=node_template,
@@ -127,9 +126,8 @@ class MockServiceStorage(object):
             m.id = '2'
             return m
         elif name == 'service_with_no_inputs':
-            test_s. name = 'service_with_no_inputs'
+            pass
         elif name == 'service_with_one_input':
-            test_s.name = 'service_with_one_input'
             input = mock_models.create_parameter(name='input1', value='value1')
             test_s.inputs = {'input1': input}
 


[09/19] incubator-ariatosca git commit: Parametrize service templates list tests

Posted by av...@apache.org.
Parametrize service templates list 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/968cd2b2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/968cd2b2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/968cd2b2

Branch: refs/heads/cli-tests
Commit: 968cd2b27b08244d16eae1a6469f2cda4430fe57
Parents: f2b387b
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Thu Apr 13 18:29:04 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Sat Apr 15 15:51:54 2017 +0300

----------------------------------------------------------------------
 tests/cli/test_service_templates.py | 36 +++++++++++---------------------
 tests/cli/test_services.py          | 29 +++++++++++++------------
 tests/cli/utils.py                  |  9 ++++----
 3 files changed, 30 insertions(+), 44 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/968cd2b2/tests/cli/test_service_templates.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_service_templates.py b/tests/cli/test_service_templates.py
index ea16f8b..04432e3 100644
--- a/tests/cli/test_service_templates.py
+++ b/tests/cli/test_service_templates.py
@@ -1,3 +1,5 @@
+import pytest
+
 from aria.cli import service_template_utils, csar
 from aria.cli.env import Environment
 from aria.cli import service_template_utils
@@ -61,35 +63,21 @@ class TestServiceTemplatesShow(TestCliBase):
 
 class TestServiceTemplatesList(TestCliBase):
 
-    def test_list_two_service_templates(self, monkeypatch, mock_storage):
+    @pytest.mark.parametrize('sort_by, order, sort_by_in_output, order_in_output', [
+        ('', '', 'created_at', 'asc'),
+        ('', ' --descending', 'created_at', 'desc'),
+        (' --sort-by name', '', 'name', 'asc'),
+        (' --sort-by name', ' --descending', 'name', 'desc')
+    ])
+    def test_all_sorting_combinations(self, monkeypatch, mock_storage, sort_by, order,
+                                      sort_by_in_output, order_in_output):
 
         monkeypatch.setattr(Environment, 'model_storage', mock_storage)
-        self.invoke('service_templates list')
+        self.invoke('service_templates list{sort_by}{order}'.format(sort_by=sort_by, order=order))
 
+        mock_storage.service_template.list.assert_called_with(sort={sort_by_in_output: order_in_output})
         assert 'Listing all service templates...' in self.logger_output_string
         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'})
-        assert 'Listing all service templates...' in self.logger_output_string
-
-    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'})
-        assert 'Listing all service templates...' in self.logger_output_string
-
-    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'})
-        assert 'Listing all service templates...' in self.logger_output_string
 
 
 class TestServiceTemplatesStore(TestCliBase):

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/968cd2b2/tests/cli/test_services.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_services.py b/tests/cli/test_services.py
index e23848b..89b3a89 100644
--- a/tests/cli/test_services.py
+++ b/tests/cli/test_services.py
@@ -18,17 +18,16 @@ class TestServicesList(TestCliBase):
         (' --sort-by name', '', 'name', 'asc'),
         (' --sort-by name', ' --descending', 'name', 'desc')
     ])
-    def test_list_specified_service_template(self, monkeypatch, mock_storage, sort_by, order,
-                                             sort_by_in_output, order_in_output):
+    def test_list_no_specified_service_template(self, monkeypatch, mock_storage, sort_by, order,
+                                                sort_by_in_output, order_in_output):
 
         monkeypatch.setattr(Environment, 'model_storage', mock_storage)
-        self.invoke('services list -t test_st{sort_by}{order}'.format(sort_by=sort_by, order=order))
-        assert 'Listing services for service template test_st...' in self.logger_output_string
-        assert 'Listing all services...' not in self.logger_output_string
+        self.invoke('services list{sort_by}{order}'.format(sort_by=sort_by, order=order))
+        assert 'Listing all services...' in self.logger_output_string
+        assert 'Listing services for service template' not in self.logger_output_string
 
-        services_list = mock_storage.service.list
-        services_list.assert_called_once_with(sort={sort_by_in_output: order_in_output},
-                                              filters={'service_template': ANY})
+        mock_storage.service.list.assert_called_once_with(sort={sort_by_in_output: order_in_output},
+                                                          filters={})
         assert 'Services:' in self.logger_output_string
         assert 'test_st' in self.logger_output_string
         assert 'test_s' in self.logger_output_string
@@ -39,16 +38,16 @@ class TestServicesList(TestCliBase):
         (' --sort-by name', '', 'name', 'asc'),
         (' --sort-by name', ' --descending', 'name', 'desc')
     ])
-    def test_list_no_specified_service_template(self, monkeypatch, mock_storage, sort_by, order,
-                                                sort_by_in_output, order_in_output):
+    def test_list_specified_service_template(self, monkeypatch, mock_storage, sort_by, order,
+                                             sort_by_in_output, order_in_output):
 
         monkeypatch.setattr(Environment, 'model_storage', mock_storage)
-        self.invoke('services list{sort_by}{order}'.format(sort_by=sort_by, order=order))
-        assert 'Listing all services...' in self.logger_output_string
-        assert 'Listing services for service template' not in self.logger_output_string
+        self.invoke('services list -t test_st{sort_by}{order}'.format(sort_by=sort_by, order=order))
+        assert 'Listing services for service template test_st...' in self.logger_output_string
+        assert 'Listing all services...' not in self.logger_output_string
 
-        services_list = mock_storage.service.list
-        services_list.assert_called_once_with(sort={sort_by_in_output: order_in_output}, filters={})
+        mock_storage.service.list.assert_called_once_with(sort={sort_by_in_output: order_in_output},
+                                                          filters={'service_template': ANY})
         assert 'Services:' in self.logger_output_string
         assert 'test_st' in self.logger_output_string
         assert 'test_s' in self.logger_output_string

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/968cd2b2/tests/cli/utils.py
----------------------------------------------------------------------
diff --git a/tests/cli/utils.py b/tests/cli/utils.py
index a3868ab..94523e2 100644
--- a/tests/cli/utils.py
+++ b/tests/cli/utils.py
@@ -47,7 +47,7 @@ def setup_logger(logger_name,
 class MockStorage(object):
 
     def __init__(self):
-        self.service_template = MockServiceTemplateStorage
+        self.service_template = MockServiceTemplateStorage()
         self.service = MockServiceStorage()
         self.node_template = MockNodeTemplateStorage()
         self.node = MockNodeStorage()
@@ -55,10 +55,8 @@ class MockStorage(object):
 
 class MockServiceTemplateStorage(object):
 
-    @staticmethod
-    def list(**_):
-        return [mock_models.create_service_template('test_st'),
-                mock_models.create_service_template('test_st2')]
+    def __init__(self):
+        self.list = MagicMock(return_value=[mock_models.create_service_template('test_st')])
 
     @staticmethod
     def get(id):
@@ -163,6 +161,7 @@ class MockNodeTemplateStorage(object):
             mock_models.create_node('node1', nt, s)
         return nt
 
+
 class MockNodeStorage(object):
 
     def __init__(self):


[17/19] incubator-ariatosca git commit: Fix service templates show tests to use names instead of ids

Posted by av...@apache.org.
Fix service templates show tests to use names instead of ids


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

Branch: refs/heads/cli-tests
Commit: 68c814e91721d4bcf27ab91738fda19dca7cfe62
Parents: 8b2da54
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Sat Apr 15 15:49:18 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Sat Apr 15 15:51:54 2017 +0300

----------------------------------------------------------------------
 tests/cli/test_node_templates.py    |  2 +-
 tests/cli/test_nodes.py             |  2 +-
 tests/cli/test_service_templates.py | 41 ++++++++++++--------------------
 tests/cli/test_services.py          |  2 +-
 tests/cli/utils.py                  | 22 +++++++----------
 5 files changed, 26 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/68c814e9/tests/cli/test_node_templates.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_node_templates.py b/tests/cli/test_node_templates.py
index 090be65..fbf784c 100644
--- a/tests/cli/test_node_templates.py
+++ b/tests/cli/test_node_templates.py
@@ -1,7 +1,7 @@
 from mock import ANY
 import pytest
 
-from aria.cli.env import Environment
+from aria.cli.env import _Environment as Environment
 from tests.cli.base_test import TestCliBase, mock_storage  # pylint: disable=unused-import
 
 

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/68c814e9/tests/cli/test_nodes.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_nodes.py b/tests/cli/test_nodes.py
index 69c8827..74e551e 100644
--- a/tests/cli/test_nodes.py
+++ b/tests/cli/test_nodes.py
@@ -1,7 +1,7 @@
 import pytest
 from mock import ANY
 
-from aria.cli.env import Environment
+from aria.cli.env import _Environment as Environment
 from tests.cli.base_test import TestCliBase, mock_storage  # pylint: disable=unused-import
 
 

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/68c814e9/tests/cli/test_service_templates.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_service_templates.py b/tests/cli/test_service_templates.py
index 0a6ee77..83ee35a 100644
--- a/tests/cli/test_service_templates.py
+++ b/tests/cli/test_service_templates.py
@@ -1,8 +1,6 @@
 import pytest
 
 from aria.cli import service_template_utils, csar
-from aria.cli.env import Environment
-from aria.cli import service_template_utils
 from aria.cli.env import _Environment as Environment
 from aria.cli.exceptions import AriaCliError
 from aria.core import Core
@@ -16,49 +14,40 @@ class TestServiceTemplatesShow(TestCliBase):
     def test_show_no_services_no_description(self, monkeypatch, mock_storage):
 
         monkeypatch.setattr(Environment, 'model_storage', mock_storage)
-        self.invoke('service_templates show 1')
+        self.invoke('service_templates show no_services_no_description')
 
-        assert 'Showing service template 1...' in self.logger_output_string
+        assert 'Showing service template no_services_no_description...' in self.logger_output_string
         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, mock_storage):
 
         monkeypatch.setattr(Environment, 'model_storage', mock_storage)
-        self.invoke('service_templates show 2')
+        self.invoke('service_templates show no_services_yes_description')
 
-        assert 'Showing service template 2...' in self.logger_output_string
+        assert 'Showing service template no_services_yes_description...' in \
+               self.logger_output_string
         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, mock_storage):
-
-        monkeypatch.setattr(Environment, 'model_storage', mock_storage)
-        self.invoke('service_templates show 3')
-
-        assert 'Showing service template 3...' in self.logger_output_string
-        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, mock_storage):
 
         monkeypatch.setattr(Environment, 'model_storage', mock_storage)
-        self.invoke('service_templates show 4')
+        self.invoke('service_templates show one_service_no_description')
 
-        assert 'Showing service template 4...' in self.logger_output_string
+        assert 'Showing service template one_service_no_description...' in self.logger_output_string
         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):
+    def test_show_one_service_yes_description(self, monkeypatch, mock_storage):
 
-        # TODO consider removing as it does not seem to test the cli but rather the message received
-        # from the storage
-        assert_exception_raised(
-            self.invoke('service_templates show 5'),
-            expected_exception=storage_exceptions.NotFoundError,
-            expected_msg='Requested `ServiceTemplate` with ID `5` was not found')
+        monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+        self.invoke('service_templates show one_service_yes_description')
 
-        assert 'Showing service template 5...' in self.logger_output_string
+        assert 'Showing service template one_service_yes_description...' in \
+               self.logger_output_string
+        assert 'Description:\ntest_description' in self.logger_output_string
+        assert "Existing services:\n['test_s']" in self.logger_output_string
 
 
 class TestServiceTemplatesList(TestCliBase):
@@ -87,7 +76,7 @@ class TestServiceTemplatesStore(TestCliBase):
 
         monkeypatch.setattr(Core, 'create_service_template', mock_object)
         monkeypatch.setattr(service_template_utils, 'get', mock_object)
-        self.invoke('service_templates store stubpath test_st')
+        outcome = self.invoke('service_templates store stubpath test_st')
         assert 'Storing service template test_st...' in self.logger_output_string
         assert 'Service template test_st stored' in self.logger_output_string
 

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/68c814e9/tests/cli/test_services.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_services.py b/tests/cli/test_services.py
index 932c95b..f22fe88 100644
--- a/tests/cli/test_services.py
+++ b/tests/cli/test_services.py
@@ -1,7 +1,7 @@
 import pytest
 from mock import ANY
 from aria.cli.exceptions import AriaCliError
-from aria.cli.env import Environment
+from aria.cli.env import _Environment as Environment
 from aria.core import Core
 from aria.exceptions import (AriaException, DependentActiveExecutionsError,
                              DependentAvailableNodesError)

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/68c814e9/tests/cli/utils.py
----------------------------------------------------------------------
diff --git a/tests/cli/utils.py b/tests/cli/utils.py
index 499732a..20fdb90 100644
--- a/tests/cli/utils.py
+++ b/tests/cli/utils.py
@@ -59,26 +59,20 @@ class MockServiceTemplateStorage(object):
         self.list = MagicMock(return_value=[mock_models.create_service_template('test_st')])
 
     @staticmethod
-    def get(id):
+    def get_by_name(name):
         st = mock_models.create_service_template('test_st')
-        if id == '1':  # no services and no description.
-            st.services = []
-        elif id == '2':  # no services, but an description
+        if name == 'no_services_no_description':
+            pass
+        elif name == 'no_services_yes_description':
             st.description = 'test_description'
-            st.services = []
-        elif id == '3':  # one service, and a description
+        elif name == 'one_service_no_description':
             service = mock_models.create_service(st, 'test_s')
-            st.description = 'test_description'
             st.services = [service]
-        elif id == '4':  # one service, and a description
+        elif name == 'one_service_yes_description':
             service = mock_models.create_service(st, 'test_s')
+            st.description = 'test_description'
             st.services = [service]
-        return st
-
-    @staticmethod
-    def get_by_name(name):
-        st = mock_models.create_service_template('test_st')
-        if name == 'with_inputs':
+        elif name == 'with_inputs':
             input = mock_models.create_parameter(name='input1', value='value1')
             st.inputs = {'input1': input}
         elif name == 'without_inputs':


[14/19] incubator-ariatosca git commit: Add tests for node-templates list

Posted by av...@apache.org.
Add tests for node-templates list


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

Branch: refs/heads/cli-tests
Commit: fc3ba6143baa0e5ce22d79c8525edef7f2c48b44
Parents: 68bf4fe
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Thu Apr 13 15:40:41 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Sat Apr 15 15:51:54 2017 +0300

----------------------------------------------------------------------
 tests/cli/test_node_templates.py | 49 +++++++++++++++++++++++++++++++++++
 tests/cli/test_services.py       |  6 ++---
 tests/cli/utils.py               |  9 +++++--
 3 files changed, 58 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/fc3ba614/tests/cli/test_node_templates.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_node_templates.py b/tests/cli/test_node_templates.py
index 4fb2b9d..aa202d4 100644
--- a/tests/cli/test_node_templates.py
+++ b/tests/cli/test_node_templates.py
@@ -1,3 +1,6 @@
+from mock import ANY
+import pytest
+
 from aria.cli.env import Environment
 from tests.cli.base_test import TestCliBase, mock_storage
 
@@ -47,3 +50,49 @@ class TestNodeTemplatesShow(TestCliBase):
         assert 'prop1' in self.logger_output_string and 'value1' in self.logger_output_string
         assert 'No nodes' not in self.logger_output_string
         assert 'node1' in self.logger_output_string
+
+
+class TestNodeTemplatesList(TestCliBase):
+
+    @pytest.mark.parametrize('sort_by, order, sort_by_in_output, order_in_output', [
+        ('', '', 'service_template_name', 'asc'),
+        ('', ' --descending', 'service_template_name', 'desc'),
+        (' --sort-by name', '', 'name', 'asc'),
+        (' --sort-by name', ' --descending', 'name', 'desc')
+    ])
+    def test_list_specified_service_template(self, monkeypatch, mock_storage, sort_by, order,
+                                             sort_by_in_output, order_in_output):
+
+        monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+        self.invoke('node_templates list -t test_st{sort_by}{order}'.format(sort_by=sort_by,
+                                                                            order=order))
+        assert 'Listing node templates for service template test_st...' in self.logger_output_string
+        assert 'Listing all node templates...' not in self.logger_output_string
+
+        node_templates_list = mock_storage.node_template.list
+        node_templates_list.assert_called_once_with(sort={sort_by_in_output: order_in_output},
+                                                    filters={'service_template': ANY})
+        assert 'Node templates:' in self.logger_output_string
+        assert 'test_st' in self.logger_output_string
+        assert 'test_nt' in self.logger_output_string
+
+    @pytest.mark.parametrize('sort_by, order, sort_by_in_output, order_in_output', [
+        ('', '', 'service_template_name', 'asc'),
+        ('', ' --descending', 'service_template_name', 'desc'),
+        (' --sort-by name', '', 'name', 'asc'),
+        (' --sort-by name', ' --descending', 'name', 'desc')
+    ])
+    def test_list_no_specified_service_template(self, monkeypatch, mock_storage, sort_by, order,
+                                                sort_by_in_output, order_in_output):
+
+        monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+        self.invoke('node_templates list{sort_by}{order}'.format(sort_by=sort_by, order=order))
+        assert 'Listing all node templates...' in self.logger_output_string
+        assert 'Listing node templates for service template test_st...' not in self.logger_output_string
+
+        node_templates_list = mock_storage.node_template.list
+        node_templates_list.assert_called_once_with(sort={sort_by_in_output: order_in_output},
+                                                    filters={})
+        assert 'Node templates:' in self.logger_output_string
+        assert 'test_st' in self.logger_output_string
+        assert 'test_nt' in self.logger_output_string

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/fc3ba614/tests/cli/test_services.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_services.py b/tests/cli/test_services.py
index 7538512..e23848b 100644
--- a/tests/cli/test_services.py
+++ b/tests/cli/test_services.py
@@ -22,8 +22,7 @@ class TestServicesList(TestCliBase):
                                              sort_by_in_output, order_in_output):
 
         monkeypatch.setattr(Environment, 'model_storage', mock_storage)
-        self.invoke('services list -t test_st{sort_by}{order}'.format(sort_by=sort_by,
-                                                                      order=order))
+        self.invoke('services list -t test_st{sort_by}{order}'.format(sort_by=sort_by, order=order))
         assert 'Listing services for service template test_st...' in self.logger_output_string
         assert 'Listing all services...' not in self.logger_output_string
 
@@ -44,8 +43,7 @@ class TestServicesList(TestCliBase):
                                                 sort_by_in_output, order_in_output):
 
         monkeypatch.setattr(Environment, 'model_storage', mock_storage)
-        self.invoke('services list{sort_by}{order}'.format(sort_by=sort_by,
-                                                           order=order))
+        self.invoke('services list{sort_by}{order}'.format(sort_by=sort_by, order=order))
         assert 'Listing all services...' in self.logger_output_string
         assert 'Listing services for service template' not in self.logger_output_string
 

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/fc3ba614/tests/cli/utils.py
----------------------------------------------------------------------
diff --git a/tests/cli/utils.py b/tests/cli/utils.py
index a9ea44b..b538826 100644
--- a/tests/cli/utils.py
+++ b/tests/cli/utils.py
@@ -49,7 +49,7 @@ class MockStorage(object):
     def __init__(self):
         self.service_template = MockServiceTemplateStorage
         self.service = MockServiceStorage()
-        self.node_template = MockNodeTemplateStorage
+        self.node_template = MockNodeTemplateStorage()
 
 
 class MockServiceTemplateStorage(object):
@@ -138,6 +138,11 @@ class MockServiceStorage(object):
 
 class MockNodeTemplateStorage(object):
 
+    def __init__(self):
+        self.st = mock_models.create_service_template('test_st')
+        self.list = MagicMock(return_value=[mock_models.create_node_template(self.st, 'test_nt')])
+
+
     @staticmethod
     def get(id):
         st = mock_models.create_service_template('test_st')
@@ -154,4 +159,4 @@ class MockNodeTemplateStorage(object):
             prop1 = mock_models.create_parameter('prop1', 'value1')
             nt.properties = {'prop1': prop1}
             mock_models.create_node('node1', nt, s)
-        return nt
\ No newline at end of file
+        return nt