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/19 12:36:04 UTC
[1/4] incubator-ariatosca git commit: final review fixes [Forced
Update!]
Repository: incubator-ariatosca
Updated Branches:
refs/heads/cli-tests 0a829ae9e -> e17916e19 (forced update)
final review fixes
Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/82591f06
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/82591f06
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/82591f06
Branch: refs/heads/cli-tests
Commit: 82591f06c023d93755c7cb123b1b49f5c51f5bec
Parents: a39e7d1
Author: Ran Ziv <ra...@gigaspaces.com>
Authored: Wed Apr 19 15:18:08 2017 +0300
Committer: Ran Ziv <ra...@gigaspaces.com>
Committed: Wed Apr 19 15:18:08 2017 +0300
----------------------------------------------------------------------
aria/cli/commands/executions.py | 6 +++---
aria/cli/commands/node_templates.py | 6 +++---
aria/cli/commands/nodes.py | 6 +++---
aria/cli/commands/plugins.py | 6 +++---
aria/cli/commands/services.py | 4 ++--
aria/cli/commands/workflows.py | 6 +++---
aria/cli/core/aria.py | 10 +++++-----
aria/cli/defaults.py | 8 ++++----
aria/orchestrator/plugin.py | 1 +
9 files changed, 27 insertions(+), 26 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/82591f06/aria/cli/commands/executions.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/executions.py b/aria/cli/commands/executions.py
index adec56b..e100f0d 100644
--- a/aria/cli/commands/executions.py
+++ b/aria/cli/commands/executions.py
@@ -16,9 +16,9 @@
import os
from .. import helptexts
+from .. import table
from .. import utils
from ..core import aria
-from ..table import print_data
from ...modeling.models import Execution
from ...orchestrator.workflow_runner import WorkflowRunner
from ...orchestrator.workflows.executor.dry import DryExecutor
@@ -51,7 +51,7 @@ def show(execution_id, model_storage, logger):
logger.info('Showing execution {0}'.format(execution_id))
execution = model_storage.execution.get(execution_id)
- print_data(EXECUTION_COLUMNS, execution, 'Execution:', col_max_width=50)
+ table.print_data(EXECUTION_COLUMNS, execution, 'Execution:', col_max_width=50)
# print execution parameters
logger.info('Execution Inputs:')
@@ -96,7 +96,7 @@ def list(service_name,
filters=filters,
sort=utils.storage_sort_param(sort_by, descending)).items
- print_data(EXECUTION_COLUMNS, executions_list, 'Executions:')
+ table.print_data(EXECUTION_COLUMNS, executions_list, 'Executions:')
@executions.command(name='start',
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/82591f06/aria/cli/commands/node_templates.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/node_templates.py b/aria/cli/commands/node_templates.py
index f0ca2c1..4d53f54 100644
--- a/aria/cli/commands/node_templates.py
+++ b/aria/cli/commands/node_templates.py
@@ -13,9 +13,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+from .. import table
from .. import utils
from ..core import aria
-from ..table import print_data
NODE_TEMPLATE_COLUMNS = ['id', 'name', 'description', 'service_template_name', 'type_name']
@@ -44,7 +44,7 @@ def show(node_template_id, model_storage, logger):
logger.info('Showing node template {0}'.format(node_template_id))
node_template = model_storage.node_template.get(node_template_id)
- print_data(NODE_TEMPLATE_COLUMNS, node_template, 'Node template:', col_max_width=50)
+ table.print_data(NODE_TEMPLATE_COLUMNS, node_template, 'Node template:', col_max_width=50)
# print node template properties
logger.info('Node template properties:')
@@ -90,4 +90,4 @@ def list(service_template_name, sort_by, descending, model_storage, logger):
filters=filters,
sort=utils.storage_sort_param(sort_by, descending)).items
- print_data(NODE_TEMPLATE_COLUMNS, node_templates_list, 'Node templates:')
+ table.print_data(NODE_TEMPLATE_COLUMNS, node_templates_list, 'Node templates:')
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/82591f06/aria/cli/commands/nodes.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/nodes.py b/aria/cli/commands/nodes.py
index 0a00478..eeab338 100644
--- a/aria/cli/commands/nodes.py
+++ b/aria/cli/commands/nodes.py
@@ -13,9 +13,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+from .. import table
from .. import utils
from ..core import aria
-from ..table import print_data
NODE_COLUMNS = ['id', 'name', 'service_name', 'node_template_name', 'state']
@@ -43,7 +43,7 @@ def show(node_id, model_storage, logger):
logger.info('Showing node {0}'.format(node_id))
node = model_storage.node.get(node_id)
- print_data(NODE_COLUMNS, node, 'Node:', 50)
+ table.print_data(NODE_COLUMNS, node, 'Node:', 50)
# print node attributes
logger.info('Node attributes:')
@@ -84,4 +84,4 @@ def list(service_name,
filters=filters,
sort=utils.storage_sort_param(sort_by, descending)).items
- print_data(NODE_COLUMNS, nodes_list, 'Nodes:')
+ table.print_data(NODE_COLUMNS, nodes_list, 'Nodes:')
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/82591f06/aria/cli/commands/plugins.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/plugins.py b/aria/cli/commands/plugins.py
index 22552d6..670288e 100644
--- a/aria/cli/commands/plugins.py
+++ b/aria/cli/commands/plugins.py
@@ -13,9 +13,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+from .. import table
from .. import utils
from ..core import aria
-from ..table import print_data
PLUGIN_COLUMNS = ['id', 'package_name', 'package_version', 'supported_platform',
@@ -80,7 +80,7 @@ def show(plugin_id, model_storage, logger):
"""
logger.info('Showing plugin {0}...'.format(plugin_id))
plugin = model_storage.plugin.get(plugin_id)
- print_data(PLUGIN_COLUMNS, plugin, 'Plugin:')
+ table.print_data(PLUGIN_COLUMNS, plugin, 'Plugin:')
@plugins.command(name='list',
@@ -96,4 +96,4 @@ def list(sort_by, descending, model_storage, logger):
logger.info('Listing all plugins...')
plugins_list = model_storage.plugin.list(
sort=utils.storage_sort_param(sort_by, descending)).items
- print_data(PLUGIN_COLUMNS, plugins_list, 'Plugins:')
+ table.print_data(PLUGIN_COLUMNS, plugins_list, 'Plugins:')
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/82591f06/aria/cli/commands/services.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/services.py b/aria/cli/commands/services.py
index e1569a6..1aa99f3 100644
--- a/aria/cli/commands/services.py
+++ b/aria/cli/commands/services.py
@@ -19,9 +19,9 @@ from StringIO import StringIO
from . import service_templates
from .. import helptexts
+from .. import table
from .. import utils
from ..core import aria
-from ..table import print_data
from ...core import Core
from ...modeling import exceptions as modeling_exceptions
from ...storage import exceptions as storage_exceptions
@@ -67,7 +67,7 @@ def list(service_template_name,
services_list = model_storage.service.list(
sort=utils.storage_sort_param(sort_by=sort_by, descending=descending),
filters=filters).items
- print_data(SERVICE_COLUMNS, services_list, 'Services:')
+ table.print_data(SERVICE_COLUMNS, services_list, 'Services:')
@services.command(name='create',
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/82591f06/aria/cli/commands/workflows.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/workflows.py b/aria/cli/commands/workflows.py
index 5bd23b7..221dbc4 100644
--- a/aria/cli/commands/workflows.py
+++ b/aria/cli/commands/workflows.py
@@ -13,8 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+from .. import table
from ..core import aria
-from ..table import print_data
from ..exceptions import AriaCliError
WORKFLOW_COLUMNS = ['name', 'service_template_name', 'service_name']
@@ -52,7 +52,7 @@ def show(workflow_name, service_name, model_storage, logger):
'service_template_name': service.service_template_name,
'service_name': service.name
}
- print_data(WORKFLOW_COLUMNS, workflow, 'Workflows:', defaults=defaults)
+ table.print_data(WORKFLOW_COLUMNS, workflow, 'Workflows:', defaults=defaults)
# print workflow inputs
required_inputs = dict()
@@ -97,4 +97,4 @@ def list(service_name, model_storage, logger):
'service_template_name': service.service_template_name,
'service_name': service.name
}
- print_data(WORKFLOW_COLUMNS, workflows_list, 'Workflows:', defaults=defaults)
+ table.print_data(WORKFLOW_COLUMNS, workflows_list, 'Workflows:', defaults=defaults)
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/82591f06/aria/cli/core/aria.py
----------------------------------------------------------------------
diff --git a/aria/cli/core/aria.py b/aria/cli/core/aria.py
index fe6dc4b..ed7c490 100644
--- a/aria/cli/core/aria.py
+++ b/aria/cli/core/aria.py
@@ -30,8 +30,8 @@ from ..env import (
from .. import defaults
from .. import helptexts
from ..inputs import inputs_to_dict
-from ...utils.exceptions import get_exception_as_string
from ... import __version__
+from ...utils.exceptions import get_exception_as_string
CLICK_CONTEXT_SETTINGS = dict(
@@ -316,13 +316,13 @@ class Options(object):
'--descending',
required=False,
is_flag=True,
- default=defaults.SORT_DESCENDING_DEFAULT,
+ default=defaults.SORT_DESCENDING,
help=helptexts.DESCENDING)
self.service_template_filename = click.option(
'-n',
'--service-template-filename',
- default=defaults.SERVICE_TEMPLATE_FILENAME_DEFAULT,
+ default=defaults.SERVICE_TEMPLATE_FILENAME,
help=helptexts.SERVICE_TEMPLATE_FILENAME)
@staticmethod
@@ -354,7 +354,7 @@ class Options(object):
help=help)
@staticmethod
- def task_max_attempts(default=defaults.TASK_MAX_ATTEMPTS_DEFAULT):
+ def task_max_attempts(default=defaults.TASK_MAX_ATTEMPTS):
return click.option(
'--task-max-attempts',
type=int,
@@ -370,7 +370,7 @@ class Options(object):
help=helptexts.SORT_BY)
@staticmethod
- def task_retry_interval(default=defaults.TASK_RETRY_INTERVAL_DEFAULT):
+ def task_retry_interval(default=defaults.TASK_RETRY_INTERVAL):
return click.option(
'--task-retry-interval',
type=int,
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/82591f06/aria/cli/defaults.py
----------------------------------------------------------------------
diff --git a/aria/cli/defaults.py b/aria/cli/defaults.py
index 6befd25..5c16938 100644
--- a/aria/cli/defaults.py
+++ b/aria/cli/defaults.py
@@ -14,7 +14,7 @@
# limitations under the License.
-SERVICE_TEMPLATE_FILENAME_DEFAULT = 'service_template.yaml'
-TASK_MAX_ATTEMPTS_DEFAULT = 30
-TASK_RETRY_INTERVAL_DEFAULT = 30
-SORT_DESCENDING_DEFAULT = False
+SERVICE_TEMPLATE_FILENAME = 'service_template.yaml'
+TASK_MAX_ATTEMPTS = 30
+TASK_RETRY_INTERVAL = 30
+SORT_DESCENDING = False
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/82591f06/aria/orchestrator/plugin.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/plugin.py b/aria/orchestrator/plugin.py
index b79d7fc..f99666c 100644
--- a/aria/orchestrator/plugin.py
+++ b/aria/orchestrator/plugin.py
@@ -44,6 +44,7 @@ class PluginManager(object):
os_props = metadata['build_server_os_properties']
plugin = cls(
+ name=metadata['package_name'],
archive_name=metadata['archive_name'],
supported_platform=metadata['supported_platform'],
supported_py_versions=metadata['supported_python_versions'],
[3/4] incubator-ariatosca git commit: Refactor cli tests framework
Posted by av...@apache.org.
Refactor cli tests framework
Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/54b5a9f1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/54b5a9f1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/54b5a9f1
Branch: refs/heads/cli-tests
Commit: 54b5a9f16b573b6614452d661814ca721609f019
Parents: da42f99
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Wed Apr 19 14:17:27 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Wed Apr 19 15:35:17 2017 +0300
----------------------------------------------------------------------
tests/cli/test_logs.py | 23 ------
tests/cli/test_node_templates.py | 56 ++++++++------
tests/cli/test_nodes.py | 21 +++--
tests/cli/test_service_templates.py | 124 +++++++++++++++++++++---------
tests/cli/test_services.py | 93 +++++++++++-----------
tests/cli/utils.py | 128 ++++---------------------------
tests/mock/models.py | 69 +++++++++++++----
tests/mock/topology.py | 8 +-
tests/modeling/test_models.py | 5 +-
9 files changed, 258 insertions(+), 269 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/54b5a9f1/tests/cli/test_logs.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_logs.py b/tests/cli/test_logs.py
deleted file mode 100644
index ad0c4f1..0000000
--- a/tests/cli/test_logs.py
+++ /dev/null
@@ -1,23 +0,0 @@
-from aria.cli.env import _Environment
-from tests.cli.base_test import TestCliBase, mock_storage
-
-
-class TestLogsList(TestCliBase):
-
- def test_existing_logs(self, monkeypatch, mock_storage):
- monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
- self.invoke('logs list exec_id')
-
- assert 'Listing logs for execution id exec_id' in self.logger_output_string
- assert 'log_msg' in self.logger_output_string
- assert 'No logs' not in self.logger_output_string
-
- def test_no_logs(self, monkeypatch, mock_object):
- m = mock_object
- m.log.list.return_value = []
- monkeypatch.setattr(_Environment, 'model_storage', m)
- self.invoke('logs list exec_id')
-
- assert 'Listing logs for execution id exec_id' in self.logger_output_string
- assert 'log_msg' not in self.logger_output_string
- assert 'No logs' in self.logger_output_string
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/54b5a9f1/tests/cli/test_node_templates.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_node_templates.py b/tests/cli/test_node_templates.py
index f0ad539..931c0a4 100644
--- a/tests/cli/test_node_templates.py
+++ b/tests/cli/test_node_templates.py
@@ -1,57 +1,66 @@
-from mock import ANY
+from mock import ANY, MagicMock
import pytest
from aria.cli.env import _Environment
from tests.cli.base_test import TestCliBase, mock_storage # pylint: disable=unused-import
+from tests.mock.models import create_node_template_with_dependencies, NODE_NAME, \
+ SERVICE_TEMPLATE_NAME, NODE_TEMPLATE_NAME
class TestNodeTemplatesShow(TestCliBase):
- def test_no_properties_no_nodes(self, monkeypatch, mock_storage):
-
+ def test_header_strings(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 'Nodes:' in self.logger_output_string
+
+ def test_no_properties_no_nodes(self, monkeypatch, mock_storage):
+
+ monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
+ self.invoke('node_templates show 1')
+
assert 'No properties' 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
+ assert NODE_NAME not in self.logger_output_string
def test_one_property_no_nodes(self, monkeypatch, mock_storage):
monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
+ m = MagicMock(return_value=create_node_template_with_dependencies(include_property=True))
+ monkeypatch.setattr(mock_storage.node_template, 'get', m)
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
+ assert NODE_NAME not in self.logger_output_string
def test_no_properties_one_node(self, monkeypatch, mock_storage):
monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
+ m = MagicMock(return_value=create_node_template_with_dependencies(include_node=True))
+ monkeypatch.setattr(mock_storage.node_template, 'get', m)
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
assert 'value1' not in self.logger_output_string
assert 'No nodes' not in self.logger_output_string
- assert 'node1' in self.logger_output_string
+ assert NODE_NAME in self.logger_output_string
def test_one_property_one_node(self, monkeypatch, mock_storage):
monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
+ m = MagicMock(return_value=create_node_template_with_dependencies(include_node=True,
+ include_property=True))
+ monkeypatch.setattr(mock_storage.node_template, 'get', m)
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
+ assert NODE_NAME in self.logger_output_string
class TestNodeTemplatesList(TestCliBase):
@@ -66,17 +75,20 @@ class TestNodeTemplatesList(TestCliBase):
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
+ self.invoke('node_templates list -t {service_template_name}{sort_by}{order}'
+ .format(service_template_name=SERVICE_TEMPLATE_NAME,
+ sort_by=sort_by,
+ order=order))
+ assert 'Listing node templates for service template ' \
+ '{name}...'.format(name=SERVICE_TEMPLATE_NAME) 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
+ assert SERVICE_TEMPLATE_NAME in self.logger_output_string
+ assert NODE_TEMPLATE_NAME in self.logger_output_string
@pytest.mark.parametrize('sort_by, order, sort_by_in_output, order_in_output', [
('', '', 'service_template_name', 'asc'),
@@ -90,12 +102,12 @@ 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 ' \
+ '{name}...'.format(name=SERVICE_TEMPLATE_NAME) 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
+ assert SERVICE_TEMPLATE_NAME in self.logger_output_string
+ assert NODE_TEMPLATE_NAME in self.logger_output_string
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/54b5a9f1/tests/cli/test_nodes.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_nodes.py b/tests/cli/test_nodes.py
index 9be97ca..e5a081c 100644
--- a/tests/cli/test_nodes.py
+++ b/tests/cli/test_nodes.py
@@ -1,19 +1,24 @@
import pytest
-from mock import ANY
+from mock import ANY, MagicMock
from aria.cli.env import _Environment
from tests.cli.base_test import TestCliBase, mock_storage # pylint: disable=unused-import
+from tests.mock.models import create_node_with_dependencies
class TestNodesShow(TestCliBase):
- def test_no_attributes(self, monkeypatch, mock_storage):
-
+ def test_header_strings(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
+
+ def test_no_attributes(self, monkeypatch, mock_storage):
+
+ monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
+ self.invoke('nodes show 2')
assert 'No attributes' in self.logger_output_string
assert 'attribute1' not in self.logger_output_string
assert 'value1' not in self.logger_output_string
@@ -21,12 +26,12 @@ class TestNodesShow(TestCliBase):
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
+ m = MagicMock(return_value=create_node_with_dependencies(include_attribute=True))
+ monkeypatch.setattr(mock_storage.node, 'get', m)
+ self.invoke('nodes show 3')
assert 'No attributes' not in self.logger_output_string
- assert 'attribute1' in self.logger_output_string and 'value1' in self.logger_output_string
+ assert 'attribute1' in self.logger_output_string
+ assert 'value1' in self.logger_output_string
class TestNodesList(TestCliBase):
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/54b5a9f1/tests/cli/test_service_templates.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_service_templates.py b/tests/cli/test_service_templates.py
index ef70c37..67ba567 100644
--- a/tests/cli/test_service_templates.py
+++ b/tests/cli/test_service_templates.py
@@ -1,4 +1,5 @@
import pytest
+from mock import MagicMock
from aria.cli import service_template_utils, csar
from aria.cli.env import _Environment
@@ -7,51 +8,76 @@ 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 # pylint: disable=unused-import
+from tests.mock.models import create_service_template, create_service, create_parameter, \
+ SERVICE_TEMPLATE_NAME, SERVICE_NAME
class TestServiceTemplatesShow(TestCliBase):
- def test_show_no_services_no_description(self, monkeypatch, mock_storage):
+ def test_header_string(self, monkeypatch, mock_storage):
monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
- self.invoke('service_templates show no_services_no_description')
+ self.invoke('service_templates show test_st')
+ assert 'Showing service template test_st...' in self.logger_output_string
+
+ def test_no_services_no_description(self, monkeypatch, mock_storage):
+
+ monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
+ self.invoke('service_templates show test_st')
- 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
+ assert 'Existing services:' not in self.logger_output_string
- def test_show_no_services_yes_description(self, monkeypatch, mock_storage):
+ def test_no_services_yes_description(self, monkeypatch, mock_storage):
monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
- self.invoke('service_templates show no_services_yes_description')
+ st = create_service_template(description='test_description')
+ monkeypatch.setattr(mock_storage.service_template, 'get_by_name',
+ MagicMock(return_value=st))
- 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
+ self.invoke('service_templates show test_st')
+ assert 'Description:' in self.logger_output_string
+ assert 'test_description' in self.logger_output_string
+ assert 'Existing services:' not in self.logger_output_string
- def test_show_one_service_no_description(self, monkeypatch, mock_storage):
+ def test_one_service_no_description(self, monkeypatch, mock_storage):
monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
- self.invoke('service_templates show one_service_no_description')
+ st = create_service_template()
+ st.services = [create_service(st)]
+ monkeypatch.setattr(mock_storage.service_template, 'get_by_name',
+ MagicMock(return_value=st))
+
+ self.invoke('service_templates show test_st')
- 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
+ assert 'Existing services:' in self.logger_output_string
+ assert SERVICE_NAME in self.logger_output_string
- def test_show_one_service_yes_description(self, monkeypatch, mock_storage):
+ def test_one_service_yes_description(self, monkeypatch, mock_storage):
monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
- self.invoke('service_templates show one_service_yes_description')
+ st = create_service_template(description='test_description')
+ st.services = [create_service(st)]
+ monkeypatch.setattr(mock_storage.service_template, 'get_by_name',
+ MagicMock(return_value=st))
+
+ self.invoke('service_templates show test_st')
- 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
+ assert 'Description:' in self.logger_output_string
+ assert 'test_description' in self.logger_output_string
+ assert 'Existing services:' in self.logger_output_string
+ assert 'test_s' in self.logger_output_string
class TestServiceTemplatesList(TestCliBase):
+ def test_header_string(self, monkeypatch, mock_storage):
+
+ monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
+ self.invoke('service_templates list')
+ assert 'Listing all service templates...' 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'),
@@ -66,19 +92,24 @@ class TestServiceTemplatesList(TestCliBase):
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 SERVICE_TEMPLATE_NAME in self.logger_output_string
class TestServiceTemplatesStore(TestCliBase):
+ def test_header_string(self, monkeypatch, mock_storage):
+
+ monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
+ self.invoke('service_templates store stubpath test_st')
+ assert 'Storing service template test_st...' in self.logger_output_string
+
def test_store_no_exception(self, monkeypatch, mock_object):
monkeypatch.setattr(Core, 'create_service_template', mock_object)
monkeypatch.setattr(service_template_utils, 'get', mock_object)
- self.invoke('service_templates store stubpath test_st')
- assert 'Storing service template test_st...' in self.logger_output_string
- assert 'Service template test_st stored' in self.logger_output_string
+ self.invoke('service_templates store stubpath {name}'.format(name=SERVICE_TEMPLATE_NAME))
+ assert 'Service template {name} stored'.format(name=SERVICE_TEMPLATE_NAME) \
+ in self.logger_output_string
def test_store_raises_exception_resulting_from_name_uniqueness(self, monkeypatch, mock_object):
@@ -93,7 +124,6 @@ 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):
@@ -105,18 +135,23 @@ 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):
+ def test_header_string(self, monkeypatch, mock_storage):
+
+ monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
+ self.invoke('service_templates delete test_st')
+ assert 'Deleting service template test_st...' in self.logger_output_string
+
def test_delete_no_exception(self, monkeypatch, mock_object):
monkeypatch.setattr(_Environment, 'model_storage', mock_object)
monkeypatch.setattr(Core, 'delete_service_template', mock_object)
- self.invoke('service_templates delete test_st')
- assert 'Deleting service template test_st...' in self.logger_output_string
- assert 'Service template test_st deleted' in self.logger_output_string
+ self.invoke('service_templates delete {name}'.format(name=SERVICE_TEMPLATE_NAME))
+ assert 'Service template {name} deleted'.format(name=SERVICE_TEMPLATE_NAME) \
+ in self.logger_output_string
def test_delete_raises_exception(self, monkeypatch, mock_object):
@@ -129,31 +164,44 @@ 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):
+ def test_header_string(self, monkeypatch, mock_storage):
+
+ monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
+ self.invoke('service_templates inputs test_st')
+ assert 'Showing inputs for service template test_st...' in self.logger_output_string
+
def test_inputs_existing_inputs(self, monkeypatch, mock_storage):
monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
+ input = create_parameter(name='input1', value='value1')
+ st = create_service_template(inputs={'input1': input})
+ monkeypatch.setattr(mock_storage.service_template, 'get_by_name',
+ MagicMock(return_value=st))
+
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
class TestServiceTemplatesValidate(TestCliBase):
+ def test_header_string(self, monkeypatch, mock_storage):
+
+ monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
+ self.invoke('service_templates validate stubpath')
+ assert 'Validating service template: stubpath' in self.logger_output_string
+
def test_validate_no_exception(self, monkeypatch, mock_object):
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):
@@ -162,13 +210,17 @@ 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):
+ def test_header_string(self, monkeypatch, mock_storage):
+
+ monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
+ self.invoke('service_templates create_archive stubpath stubdest')
+ assert 'Creating a csar archive' in self.logger_output_string
+
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
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/54b5a9f1/tests/cli/test_services.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_services.py b/tests/cli/test_services.py
index 116e449..7e48593 100644
--- a/tests/cli/test_services.py
+++ b/tests/cli/test_services.py
@@ -1,5 +1,5 @@
import pytest
-from mock import ANY
+from mock import ANY, MagicMock
from aria.cli.exceptions import AriaCliError
from aria.cli.env import _Environment
from aria.core import Core
@@ -7,7 +7,7 @@ from aria.exceptions import (AriaException, DependentActiveExecutionsError,
DependentAvailableNodesError)
from aria.storage import exceptions as storage_exceptions
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
+from tests.mock.models import create_service_with_dependencies, SERVICE_TEMPLATE_NAME, SERVICE_NAME
class TestServicesList(TestCliBase):
@@ -18,8 +18,8 @@ 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_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))
@@ -29,8 +29,8 @@ class TestServicesList(TestCliBase):
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
+ assert SERVICE_TEMPLATE_NAME in self.logger_output_string
+ assert SERVICE_NAME in self.logger_output_string
@pytest.mark.parametrize('sort_by, order, sort_by_in_output, order_in_output', [
('', '', 'created_at', 'asc'),
@@ -38,8 +38,8 @@ 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_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))
@@ -49,27 +49,29 @@ class TestServicesList(TestCliBase):
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
+ assert SERVICE_TEMPLATE_NAME in self.logger_output_string
+ assert SERVICE_NAME in self.logger_output_string
class TestServicesCreate(TestCliBase):
- def test_create_no_exception(self, monkeypatch, mock_object):
+ def test_header_string(self, monkeypatch, mock_storage):
+ monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
+ self.invoke('services create -t test_st test_s')
+ assert 'Creating new service from service template test_st...' in self.logger_output_string
- monkeypatch.setattr(_Environment, 'model_storage', mock_object)
+ def test_no_exception(self, monkeypatch, mock_storage):
- 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')
+ monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
- assert 'Creating new service from service template test_st...' in self.logger_output_string
+ m = MagicMock(return_value=create_service_with_dependencies())
+ monkeypatch.setattr(Core, 'create_service', m)
+ self.invoke('services create -t test_st test_s')
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)
+ def test_raises_storage_error_resulting_from_name_uniqueness(self, monkeypatch,
+ mock_storage):
+ monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
monkeypatch.setattr(Core,
'create_service',
raise_exception(storage_exceptions.NotFoundError,
@@ -80,10 +82,9 @@ class TestServicesCreate(TestCliBase):
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):
+ def test_raises_other_storage_error(self, monkeypatch, mock_object):
monkeypatch.setattr(_Environment, 'model_storage', mock_object)
monkeypatch.setattr(Core,
'create_service',
@@ -93,10 +94,9 @@ class TestServicesCreate(TestCliBase):
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):
+ def test_raises_aria_exception(self, monkeypatch, mock_storage):
monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
monkeypatch.setattr(Core,
'create_service',
@@ -107,62 +107,67 @@ 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 '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):
+ def test_header_string(self, monkeypatch, mock_storage):
+ monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
+ self.invoke('services delete test_s')
+ assert 'Deleting service test_s...' in self.logger_output_string
- monkeypatch.setattr(_Environment, 'model_storage', mock_object)
+ def test_delete_no_exception(self, monkeypatch, mock_storage, mock_object):
+
+ monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
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)
+ mock_service_with_execution = \
+ MagicMock(return_value=create_service_with_dependencies(include_execution=True))
+ monkeypatch.setattr(mock_storage.service, 'get', mock_service_with_execution)
assert_exception_raised(
- self.invoke('services delete service_with_active_executions'),
+ self.invoke('services delete test_s'),
expected_exception=DependentActiveExecutionsError,
- 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
+ expected_msg="Can't delete service {name} - there is an active execution "
+ "for this service. Active execution id: 1".format(name=SERVICE_NAME))
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'),
+ self.invoke('services delete test_s'),
expected_exception=DependentAvailableNodesError,
- expected_msg="Can't delete service test_s - "
- "there are available nodes for this service. Available node ids: 1"
+ expected_msg="Can't delete service {name} - there are available nodes "
+ "for this service. Available node ids: 1".format(name=SERVICE_NAME)
)
- 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
+
class TestServicesOutputs(TestCliBase):
pass
class TestServicesInputs(TestCliBase):
+ def test_header_string(self, monkeypatch, mock_storage):
+ monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
+ self.invoke('services inputs test_s')
+ assert 'Showing inputs for service test_s...' in self.logger_output_string
+
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
assert 'value1' not in self.logger_output_string
@@ -170,9 +175,11 @@ class TestServicesInputs(TestCliBase):
def test_inputs_one_input(self, monkeypatch, mock_storage):
monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
- self.invoke('services inputs service_with_one_input')
+ s = create_service_with_dependencies(include_input=True)
+ monkeypatch.setattr(mock_storage.service, 'get_by_name', MagicMock(return_value=s))
+
+ self.invoke('services inputs test_s')
- assert 'Showing inputs for service service_with_one_input...' 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/54b5a9f1/tests/cli/utils.py
----------------------------------------------------------------------
diff --git a/tests/cli/utils.py b/tests/cli/utils.py
index b1537c5..e33203e 100644
--- a/tests/cli/utils.py
+++ b/tests/cli/utils.py
@@ -1,5 +1,4 @@
import logging
-from aria.modeling import models
from mock import MagicMock
from tests.mock import models as mock_models
@@ -51,135 +50,36 @@ class MockStorage(object):
self.service = MockServiceStorage()
self.node_template = MockNodeTemplateStorage()
self.node = MockNodeStorage()
- self.log = MockLogStorage()
class MockServiceTemplateStorage(object):
def __init__(self):
- self.list = MagicMock(return_value=[mock_models.create_service_template('test_st')])
-
- @staticmethod
- def get_by_name(name):
- st = mock_models.create_service_template('test_st')
- if name == 'no_services_no_description':
- pass
- elif name == 'no_services_yes_description':
- st.description = 'test_description'
- elif name == 'one_service_no_description':
- service = mock_models.create_service(st, 'test_s')
- st.services = [service]
- elif name == 'one_service_yes_description':
- service = mock_models.create_service(st, 'test_s')
- st.description = 'test_description'
- st.services = [service]
- elif name == 'with_inputs':
- input = mock_models.create_parameter(name='input1', value='value1')
- st.inputs = {'input1': input}
- elif name == 'without_inputs':
- st.inputs = {}
- elif name == 'one_service':
- service = mock_models.create_service(st, 'test_s')
- st.services = [service]
- return st
+ self.list = MagicMock(return_value=[mock_models.create_service_template()])
+ self.get_by_name = MagicMock(return_value=mock_models.create_service_template())
class MockServiceStorage(object):
def __init__(self):
- 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, 'test_s')
- if id == '1':
- execution = mock_models.create_execution(test_s, status=models.Execution.STARTED)
- execution.id = '1'
- test_s.executions = [execution]
- elif 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):
- 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'
- return m
- elif name == 'service_with_available_nodes':
- m = MagicMock()
- m.id = '2'
- return m
- elif name == 'service_with_no_inputs':
- pass
- elif name == 'service_with_one_input':
- input = mock_models.create_parameter(name='input1', value='value1')
- test_s.inputs = {'input1': input}
-
- return test_s
+ self.s = mock_models.create_service_with_dependencies()
+
+ self.list = MagicMock(return_value=[self.s])
+ self.create = MagicMock(return_value=self.s)
+ self.get = MagicMock(
+ return_value=mock_models.create_service_with_dependencies(include_node=True))
+ self.get_by_name = MagicMock(return_value=self.s)
+ self.delete = MagicMock()
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')
- 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
+ self.get = MagicMock(return_value=mock_models.create_node_template_with_dependencies())
+ self.list = MagicMock(return_value=[mock_models.create_node_template_with_dependencies()])
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
-
-
-class MockLogStorage(object):
-
def __init__(self):
- st = mock_models.create_service_template('test_st')
- s = mock_models.create_service(st, 'test_s')
- execution = mock_models.create_execution(s)
- self.list = MagicMock(return_value=[mock_models.create_log(execution)])
+ self.get = MagicMock(return_value=mock_models.create_node_with_dependencies())
+ self.list = MagicMock(return_value=[mock_models.create_node_with_dependencies()])
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/54b5a9f1/tests/mock/models.py
----------------------------------------------------------------------
diff --git a/tests/mock/models.py b/tests/mock/models.py
index 328453a..cdedea9 100644
--- a/tests/mock/models.py
+++ b/tests/mock/models.py
@@ -37,10 +37,11 @@ from aria.orchestrator.workflows.builtin.workflows import (
NORMATIVE_REMOVE_SOURCE
)
-SERVICE_NAME = 'test_service_name'
-SERVICE_TEMPLATE_NAME = 'test_service_template_name'
+SERVICE_TEMPLATE_NAME = 'test_service_template'
+SERVICE_NAME = 'test_service1'
NODE_TEMPLATE_NAME = 'test_node_template'
-WORKFLOW_NAME = 'test_workflow_name'
+NODE_NAME = 'test_node1'
+WORKFLOW_NAME = 'test_workflow'
TASK_RETRY_INTERVAL = 1
TASK_MAX_ATTEMPTS = 1
@@ -50,11 +51,13 @@ DEPENDENT_NODE_TEMPLATE_NAME = 'dependent_node_template'
DEPENDENT_NODE_NAME = 'dependent_node'
-def create_service_template(name=SERVICE_TEMPLATE_NAME):
+def create_service_template(name=SERVICE_TEMPLATE_NAME, description=None, inputs=None):
now = datetime.now()
+ inputs = inputs or {}
return models.ServiceTemplate(
name=name,
- description=None,
+ description=description,
+ inputs=inputs,
created_at=now,
updated_at=now,
main_file_name='main_file_name',
@@ -68,10 +71,12 @@ def create_service_template(name=SERVICE_TEMPLATE_NAME):
)
-def create_service(service_template, name=SERVICE_NAME):
+def create_service(service_template, name=SERVICE_NAME, inputs=None):
now = datetime.utcnow()
+ inputs = inputs or {}
return models.Service(
name=name,
+ inputs=inputs,
service_template=service_template,
description='',
created_at=now,
@@ -81,6 +86,46 @@ def create_service(service_template, name=SERVICE_NAME):
)
+def create_service_with_dependencies(include_execution=False,
+ include_input=False,
+ include_node=False):
+ service_template = create_service_template()
+ service = create_service(service_template=service_template)
+ if include_execution:
+ execution = create_execution(service=service, status=models.Execution.STARTED)
+ service.executions = [execution]
+ execution.id = '1'
+ if include_input:
+ input = create_parameter(name='input1', value='value1')
+ service.inputs = {'input1': input}
+ if include_node:
+ node_template = create_node_template(service_template=service_template)
+ node = create_node(node_template, service, state=models.Node.STARTED)
+ node.id = '1'
+ return service
+
+
+def create_node_template_with_dependencies(include_node=False, include_property=False):
+ service_template = create_service_template()
+ node_template = create_node_template(service_template=service_template)
+ if include_node:
+ service = create_service(service_template=service_template)
+ create_node(dependency_node_template=node_template, service=service)
+ if include_property:
+ node_template.properties = {'prop1': create_parameter(name='prop1', value='value1')}
+ return node_template
+
+
+def create_node_with_dependencies(include_attribute=False):
+
+ node_template = create_node_template_with_dependencies()
+ node_template.service_template.services[0] = create_service(node_template.service_template)
+ node = create_node(node_template, node_template.service_template.services[0])
+ if include_attribute:
+ node.runtime_properties = {'attribute1': 'value1'}
+ return node
+
+
def create_node_template(service_template,
name=NODE_TEMPLATE_NAME,
type=models.Type(variant='node', name='test_node_type'),
@@ -141,10 +186,9 @@ def create_dependent_node_template(
)
-def create_node(name, dependency_node_template, service, state=models.Node.INITIAL,
+def create_node(dependency_node_template, service, name=NODE_NAME, 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,
@@ -245,15 +289,6 @@ def create_parameter(name, value):
return p.wrap(name, value)
-def create_log(execution, msg='log_msg', level=0, created_at=datetime.utcnow()):
-
- return models.Log(
- execution=execution,
- msg=msg,
- level=level,
- created_at=created_at)
-
-
def _dictify(item):
return dict(((item.name, item),))
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/54b5a9f1/tests/mock/topology.py
----------------------------------------------------------------------
diff --git a/tests/mock/topology.py b/tests/mock/topology.py
index e5b4e01..bfb7b4e 100644
--- a/tests/mock/topology.py
+++ b/tests/mock/topology.py
@@ -33,7 +33,7 @@ def create_simple_topology_single_node(model_storage, create_operation):
)
node_template.interface_templates[interface_template.name] = interface_template # pylint: disable=unsubscriptable-object
- node = models.create_node(models.DEPENDENCY_NODE_NAME, node_template, service)
+ node = models.create_node(node_template, service, name=models.DEPENDENCY_NODE_NAME)
interface = models.create_interface(
service,
'Standard', 'create',
@@ -59,9 +59,9 @@ def create_simple_topology_two_nodes(model_storage):
dependency_node_template)
dependency_node = models.create_node(
- models.DEPENDENCY_NODE_NAME, dependency_node_template, service)
+ dependency_node_template, service, models.DEPENDENCY_NODE_NAME)
dependent_node = models.create_node(
- models.DEPENDENT_NODE_NAME, dependent_node_template, service)
+ dependent_node_template, service, models.DEPENDENT_NODE_NAME)
dependent_node.outbound_relationships.append(models.create_relationship( # pylint: disable=no-member
source=dependent_node,
@@ -86,7 +86,7 @@ def create_simple_topology_three_nodes(model_storage):
service = model_storage.service.get(service_id)
third_node_template = models.create_dependency_node_template(
service.service_template, name='another_dependency_node_template')
- third_node = models.create_node('another_dependency_node', third_node_template, service)
+ third_node = models.create_node(third_node_template, service, 'another_dependency_node')
new_relationship = models.create_relationship(
source=model_storage.node.get_by_name(models.DEPENDENT_NODE_NAME),
target=third_node,
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/54b5a9f1/tests/modeling/test_models.py
----------------------------------------------------------------------
diff --git a/tests/modeling/test_models.py b/tests/modeling/test_models.py
index d91249a..d64cdba 100644
--- a/tests/modeling/test_models.py
+++ b/tests/modeling/test_models.py
@@ -100,12 +100,13 @@ def _nodes_storage():
service = storage.service.get_by_name(mock.models.SERVICE_NAME)
dependency_node_template = storage.node_template.get_by_name(
mock.models.DEPENDENCY_NODE_TEMPLATE_NAME)
- mock.models.create_node(mock.models.DEPENDENCY_NODE_NAME, dependency_node_template, service)
+ mock.models.create_node(dependency_node_template, service,
+ name=mock.models.DEPENDENCY_NODE_NAME)
dependent_node_template = mock.models.create_dependent_node_template(service.service_template,
dependency_node_template)
- mock.models.create_node(mock.models.DEPENDENT_NODE_NAME, dependent_node_template, service)
+ mock.models.create_node(dependent_node_template, service, name=mock.models.DEPENDENT_NODE_NAME)
storage.service.update(service)
return storage
[2/4] incubator-ariatosca git commit: Add tests for logs list
Posted by av...@apache.org.
Add tests for logs 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/da42f99d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/da42f99d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/da42f99d
Branch: refs/heads/cli-tests
Commit: da42f99d4a32fa57feeefd34a721512771dc9fe8
Parents: 82591f0
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Tue Apr 18 12:28:37 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Wed Apr 19 15:35:17 2017 +0300
----------------------------------------------------------------------
aria/cli/commands/logs.py | 2 +-
tests/cli/test_logs.py | 23 +++++++++++++++++++++++
tests/cli/utils.py | 10 ++++++++++
tests/mock/models.py | 9 +++++++++
4 files changed, 43 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/da42f99d/aria/cli/commands/logs.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/logs.py b/aria/cli/commands/logs.py
index 8888fef..6c83347 100644
--- a/aria/cli/commands/logs.py
+++ b/aria/cli/commands/logs.py
@@ -42,7 +42,7 @@ def list(execution_id,
# TODO: print logs nicely
if logs_list:
for log in logs_list:
- print log
+ logger.info(log)
else:
logger.info('\tNo logs')
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/da42f99d/tests/cli/test_logs.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_logs.py b/tests/cli/test_logs.py
new file mode 100644
index 0000000..ad0c4f1
--- /dev/null
+++ b/tests/cli/test_logs.py
@@ -0,0 +1,23 @@
+from aria.cli.env import _Environment
+from tests.cli.base_test import TestCliBase, mock_storage
+
+
+class TestLogsList(TestCliBase):
+
+ def test_existing_logs(self, monkeypatch, mock_storage):
+ monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
+ self.invoke('logs list exec_id')
+
+ assert 'Listing logs for execution id exec_id' in self.logger_output_string
+ assert 'log_msg' in self.logger_output_string
+ assert 'No logs' not in self.logger_output_string
+
+ def test_no_logs(self, monkeypatch, mock_object):
+ m = mock_object
+ m.log.list.return_value = []
+ monkeypatch.setattr(_Environment, 'model_storage', m)
+ self.invoke('logs list exec_id')
+
+ assert 'Listing logs for execution id exec_id' in self.logger_output_string
+ assert 'log_msg' not in self.logger_output_string
+ assert 'No logs' in self.logger_output_string
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/da42f99d/tests/cli/utils.py
----------------------------------------------------------------------
diff --git a/tests/cli/utils.py b/tests/cli/utils.py
index 20fdb90..b1537c5 100644
--- a/tests/cli/utils.py
+++ b/tests/cli/utils.py
@@ -51,6 +51,7 @@ class MockStorage(object):
self.service = MockServiceStorage()
self.node_template = MockNodeTemplateStorage()
self.node = MockNodeStorage()
+ self.log = MockLogStorage()
class MockServiceTemplateStorage(object):
@@ -173,3 +174,12 @@ class MockNodeStorage(object):
elif id == '2':
n.runtime_properties = {'attribute1': 'value1'}
return n
+
+
+class MockLogStorage(object):
+
+ def __init__(self):
+ st = mock_models.create_service_template('test_st')
+ s = mock_models.create_service(st, 'test_s')
+ execution = mock_models.create_execution(s)
+ self.list = MagicMock(return_value=[mock_models.create_log(execution)])
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/da42f99d/tests/mock/models.py
----------------------------------------------------------------------
diff --git a/tests/mock/models.py b/tests/mock/models.py
index 8a9273b..328453a 100644
--- a/tests/mock/models.py
+++ b/tests/mock/models.py
@@ -245,6 +245,15 @@ def create_parameter(name, value):
return p.wrap(name, value)
+def create_log(execution, msg='log_msg', level=0, created_at=datetime.utcnow()):
+
+ return models.Log(
+ execution=execution,
+ msg=msg,
+ level=level,
+ created_at=created_at)
+
+
def _dictify(item):
return dict(((item.name, item),))
[4/4] incubator-ariatosca git commit: Partial fixes for cli tests
Posted by av...@apache.org.
Partial fixes for cli 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/e17916e1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/e17916e1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/e17916e1
Branch: refs/heads/cli-tests
Commit: e17916e1938bb54522d1e5fb9d4d3256930486fd
Parents: 54b5a9f
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Wed Apr 19 15:34:27 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Wed Apr 19 15:35:57 2017 +0300
----------------------------------------------------------------------
aria/cli/commands/service_templates.py | 9 +++++----
aria/cli/commands/services.py | 2 +-
aria/storage/sql_mapi.py | 22 ++++++----------------
3 files changed, 12 insertions(+), 21 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/e17916e1/aria/cli/commands/service_templates.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/service_templates.py b/aria/cli/commands/service_templates.py
index 189ba51..97367c2 100644
--- a/aria/cli/commands/service_templates.py
+++ b/aria/cli/commands/service_templates.py
@@ -65,9 +65,10 @@ def show(service_template_name, model_storage, logger):
logger.info('{0}{1}'.format(service_template_dict['description'].encode('UTF-8') or '',
os.linesep))
- logger.info('Existing services:')
- for service in service_template.services:
- logger.info('\t{0}'.format(service.name))
+ if service_template.services:
+ logger.info('Existing services:')
+ for service in service_template.services:
+ logger.info('\t{0}'.format(service.name))
@service_templates.command(name='list',
@@ -83,7 +84,7 @@ def list(sort_by, descending, model_storage, logger):
logger.info('Listing all service templates...')
service_templates_list = model_storage.service_template.list(
- sort=utils.storage_sort_param(sort_by, descending)).items
+ sort=utils.storage_sort_param(sort_by, descending))
column_formatters = \
dict(description=table.trim_formatter_generator(DESCRIPTION_FIELD_LENGTH_LIMIT))
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/e17916e1/aria/cli/commands/services.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/services.py b/aria/cli/commands/services.py
index 1aa99f3..81bef7d 100644
--- a/aria/cli/commands/services.py
+++ b/aria/cli/commands/services.py
@@ -19,9 +19,9 @@ from StringIO import StringIO
from . import service_templates
from .. import helptexts
-from .. import table
from .. import utils
from ..core import aria
+from ..table import print_data
from ...core import Core
from ...modeling import exceptions as modeling_exceptions
from ...storage import exceptions as storage_exceptions
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/e17916e1/aria/storage/sql_mapi.py
----------------------------------------------------------------------
diff --git a/aria/storage/sql_mapi.py b/aria/storage/sql_mapi.py
index 144c925..730d007 100644
--- a/aria/storage/sql_mapi.py
+++ b/aria/storage/sql_mapi.py
@@ -92,10 +92,8 @@ class SQLAlchemyModelAPI(api.ModelAPI):
results, total, size, offset = self._paginate(query, pagination)
return ListResult(
- items=results,
- metadata=dict(total=total,
- size=size,
- offset=offset)
+ dict(total=total, size=size, offset=offset),
+ results
)
def iter(self,
@@ -406,19 +404,11 @@ def init_storage(base_dir, filename='db.sqlite'):
return dict(engine=engine, session=session)
-class ListResult(object):
+class ListResult(list):
"""
a ListResult contains results about the requested items.
"""
- def __init__(self, items, metadata):
- self.items = items
+ def __init__(self, metadata, *args, **qwargs):
+ super(ListResult, self).__init__(*args, **qwargs)
self.metadata = metadata
-
- def __len__(self):
- return len(self.items)
-
- def __iter__(self):
- return iter(self.items)
-
- def __getitem__(self, item):
- return self.items[item]
+ self.items = self