ariatosca-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [2/3] incubator-ariatosca git commit: Add tests for services list
Date Wed, 12 Apr 2017 14:41:17 GMT
Add tests for services 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/b63dbf26
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/b63dbf26
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/b63dbf26

Branch: refs/heads/cli-tests
Commit: b63dbf26948718f2fe58612256c0595d9cbbd5b9
Parents: b469b27
Author: Avia Efrat <avia@gigaspaces.com>
Authored: Wed Apr 12 15:58:32 2017 +0300
Committer: Avia Efrat <avia@gigaspaces.com>
Committed: Wed Apr 12 15:58:32 2017 +0300

----------------------------------------------------------------------
 aria/cli/commands/services.py       |  4 +--
 tests/cli/base_test.py              |  2 +-
 tests/cli/test_services.py          | 57 ++++++++++++++++++++++++++++++++
 tests/cli/utils.py                  | 15 ++++++++-
 tests/storage/test_model_storage.py |  2 +-
 5 files changed, 75 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/b63dbf26/aria/cli/commands/services.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/services.py b/aria/cli/commands/services.py
index 1059e10..b785006 100644
--- a/aria/cli/commands/services.py
+++ b/aria/cli/commands/services.py
@@ -58,10 +58,10 @@ def list(service_template_name,
     if service_template_name:
         logger.info('Listing services for service template {0}...'.format(
             service_template_name))
-        service_template = model_storage.service_template.get(service_template_name)
+        service_template = model_storage.service_template.get_by_name(service_template_name)
         filters = dict(service_template=service_template)
     else:
-        logger.info('Listing all service...')
+        logger.info('Listing all services...')
         filters = {}
 
     services_list = [d.to_dict() for d in model_storage.service.list(

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/b63dbf26/tests/cli/base_test.py
----------------------------------------------------------------------
diff --git a/tests/cli/base_test.py b/tests/cli/base_test.py
index 430781a..a1a1acd 100644
--- a/tests/cli/base_test.py
+++ b/tests/cli/base_test.py
@@ -6,7 +6,7 @@ from utils import setup_logger, MockStorage
 import pytest
 
 
-@pytest.fixture()
+@pytest.fixture
 def mock_storage():
     return MockStorage()
 

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/b63dbf26/tests/cli/test_services.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_services.py b/tests/cli/test_services.py
new file mode 100644
index 0000000..4f7b98b
--- /dev/null
+++ b/tests/cli/test_services.py
@@ -0,0 +1,57 @@
+import pytest
+from mock import ANY
+
+from tests.cli.base_test import TestCliBase, mock_storage
+from aria.cli.env import Environment
+
+
+class TestServicesList(TestCliBase):
+
+    @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_services_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 -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={'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
+
+    @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_services_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{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={})
+        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/b63dbf26/tests/cli/utils.py
----------------------------------------------------------------------
diff --git a/tests/cli/utils.py b/tests/cli/utils.py
index c046ed3..97f6a67 100644
--- a/tests/cli/utils.py
+++ b/tests/cli/utils.py
@@ -1,5 +1,7 @@
 import logging
 
+from mock import MagicMock
+
 from tests.mock import models
 
 
@@ -46,6 +48,7 @@ class MockStorage(object):
 
     def __init__(self):
         self.service_template = MockServiceTemplateStorage
+        self.service = MockServiceStorage()
 
 
 class MockServiceTemplateStorage(object):
@@ -80,4 +83,14 @@ class MockServiceTemplateStorage(object):
             st.inputs = {'input1': input}
         if name == 'without_inputs':
             st.inputs = {}
-        return st
\ No newline at end of file
+        if name == 'one_service':
+            service = models.create_service(st, 'test_s')
+            st.services = [service]
+        return st
+
+
+class MockServiceStorage(object):
+
+    def __init__(self):
+        st = models.create_service_template('test_st')
+        self.list = MagicMock(return_value=[models.create_service(st, 'test_s')])

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/b63dbf26/tests/storage/test_model_storage.py
----------------------------------------------------------------------
diff --git a/tests/storage/test_model_storage.py b/tests/storage/test_model_storage.py
index 4dabfaf..8dd781b 100644
--- a/tests/storage/test_model_storage.py
+++ b/tests/storage/test_model_storage.py
@@ -167,7 +167,7 @@ class MockModel(modeling.models.aria_declarative_base, modeling.mixins.ModelMixi
 
 class TestFilterOperands(object):
 
-    @pytest.fixture()
+    @pytest.fixture
     def storage(self):
         model_storage = application_model_storage(
             sql_mapi.SQLAlchemyModelAPI, initiator=tests_storage.init_inmemory_model_storage)


Mime
View raw message