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

[06/16] incubator-ariatosca git commit: Parametrize service templates list tests

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):