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/bfa49be8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/bfa49be8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/bfa49be8

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

Reply via email to