ariatosca-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [08/14] incubator-ariatosca git commit: Add tests for node-templates list
Date Thu, 13 Apr 2017 14:16:17 GMT
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/e08a68dd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/e08a68dd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/e08a68dd

Branch: refs/heads/cli-tests
Commit: e08a68dde0cd866322fc07d290817e47de28e8dc
Parents: 043374a
Author: Avia Efrat <avia@gigaspaces.com>
Authored: Thu Apr 13 15:40:41 2017 +0300
Committer: Avia Efrat <avia@gigaspaces.com>
Committed: Thu Apr 13 17:15: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/e08a68dd/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/e08a68dd/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/e08a68dd/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


Mime
View raw message