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/12 14:41:18 UTC
[3/3] incubator-ariatosca git commit: Add tests for services create
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/965b69e0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/965b69e0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/965b69e0
Branch: refs/heads/cli-tests
Commit: 965b69e0b570a5e3bacc752248914b2e5d5de18d
Parents: b63dbf2
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Wed Apr 12 17:36:03 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Wed Apr 12 17:40:25 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/965b69e0/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/965b69e0/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)