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 13:07:47 UTC

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

Repository: incubator-ariatosca
Updated Branches:
  refs/heads/ARIA-48-aria-cli 2e9d81a18 -> d2953788e


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/ARIA-48-aria-cli
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':


[10/16] 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/ARIA-48-aria-cli
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)
 


[14/16] 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/ARIA-48-aria-cli
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,


[12/16] 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/ARIA-48-aria-cli
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()


[06/16] 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/ARIA-48-aria-cli
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):


[09/16] 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/ARIA-48-aria-cli
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


[11/16] 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/ARIA-48-aria-cli
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


[15/16] 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/ARIA-48-aria-cli
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}
 


[13/16] 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/ARIA-48-aria-cli
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,


[08/16] 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/ARIA-48-aria-cli
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)


[04/16] 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/ARIA-48-aria-cli
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


[05/16] 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/ARIA-48-aria-cli
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)


[07/16] 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/ARIA-48-aria-cli
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(),


[02/16] 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/ARIA-48-aria-cli
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


[03/16] 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/ARIA-48-aria-cli
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


[16/16] 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/ARIA-48-aria-cli
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