ariatosca-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [08/16] incubator-ariatosca git commit: Add tests for services create
Date Sat, 15 Apr 2017 13:07:54 GMT
Add tests for services create


Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/2bda2335
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/2bda2335
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/2bda2335

Branch: refs/heads/ARIA-48-aria-cli
Commit: 2bda233546972e25128dc6a68667dacc1a604315
Parents: 5968eb5
Author: Avia Efrat <avia@gigaspaces.com>
Authored: Wed Apr 12 17:36:03 2017 +0300
Committer: Avia Efrat <avia@gigaspaces.com>
Committed: Sat Apr 15 15:51:54 2017 +0300

----------------------------------------------------------------------
 tests/cli/test_services.py          | 62 ++++++++++++++++++++++++++++++--
 tests/storage/test_model_storage.py |  2 +-
 2 files changed, 61 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/2bda2335/tests/cli/test_services.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_services.py b/tests/cli/test_services.py
index 4f7b98b..0c89b14 100644
--- a/tests/cli/test_services.py
+++ b/tests/cli/test_services.py
@@ -1,8 +1,12 @@
 import pytest
 from mock import ANY
-
-from tests.cli.base_test import TestCliBase, mock_storage
+from aria.cli.exceptions import AriaCliError
 from aria.cli.env import Environment
+from aria.core import Core
+from aria.exceptions import AriaException
+from aria.storage import exceptions as storage_exceptions
+from tests.cli.base_test import TestCliBase, mock_storage, raise_exception, assert_exception_raised
+from tests.mock.models import create_service, create_service_template
 
 
 class TestServicesList(TestCliBase):
@@ -51,7 +55,61 @@ class TestServicesList(TestCliBase):
         assert 'test_s' in self.logger_output_string
 
 
+class TestServicesCreate(TestCliBase):
+
+    def test_create_no_exception(self, monkeypatch, mock_object):
+
+        monkeypatch.setattr(Environment, 'model_storage', mock_object)
+
+        test_st = create_service_template('test_st')
+        mock_object.return_value = create_service(test_st, 'test_s')
+        monkeypatch.setattr(Core, 'create_service', mock_object)
+        self.invoke('services create -t test_st test_s')
+
+        assert 'Creating new service from service template test_st...' in self.logger_output_string
+        assert "Service created. The service's name is test_s" in self.logger_output_string
 
+    def test_store_raises_storage_error_resulting_from_name_uniqueness(self, monkeypatch,
+                                                                       mock_object):
+        monkeypatch.setattr(Environment, 'model_storage', mock_object)
+        monkeypatch.setattr(Core,
+                            'create_service',
+                            raise_exception(storage_exceptions.NotFoundError,
+                                            msg='UNIQUE constraint failed'))
+        assert_exception_raised(
+            self.invoke('services create -t test_st test_s'),
+            expected_exception=AriaCliError,
+            expected_msg='Could not store service `test_s`\n'
+                         'There already a exists a service with the same name')
 
+        assert 'Creating new service from service template test_st...' in self.logger_output_string
+        assert "Service created. The service's name is test_s" not in self.logger_output_string
+
+    def test_store_raises_other_storage_error(self, monkeypatch, mock_object):
+        monkeypatch.setattr(Environment, 'model_storage', mock_object)
+        monkeypatch.setattr(Core,
+                            'create_service',
+                            raise_exception(storage_exceptions.NotFoundError))
+
+        assert_exception_raised(
+            self.invoke('services create -t test_st test_s'),
+            expected_exception=AriaCliError)
+
+        assert 'Creating new service from service template test_st...' in self.logger_output_string
+        assert "Service created. The service's name is test_s" not in self.logger_output_string
+
+    def test_store_raises_aria_exception(self, monkeypatch, mock_storage):
+        monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+        monkeypatch.setattr(Core,
+                            'create_service',
+                            raise_exception(AriaException, msg='error creating service `test_s`'))
 
+        assert_exception_raised(
+            self.invoke('services create -t with_inputs test_s'),
+            expected_exception=AriaCliError,
+            expected_msg='error creating service `test_s`')
 
+        assert 'Creating new service from service template with_inputs...' in self.logger_output_string
+        assert 'error creating service `test_s`' in self.logger_output_string
+        assert 'input1' in self.logger_output_string and 'value1' in self.logger_output_string
+        assert "Service created. The service's name is test_s" not in self.logger_output_string

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/2bda2335/tests/storage/test_model_storage.py
----------------------------------------------------------------------
diff --git a/tests/storage/test_model_storage.py b/tests/storage/test_model_storage.py
index 8dd781b..4dabfaf 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