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

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

Fix service templates show tests to use names instead of ids


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

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

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


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

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

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

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

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