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:57 UTC

[11/16] incubator-ariatosca git commit: Add tests for node-templates list

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