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/05 17:01:30 UTC
[3/3] incubator-ariatosca git commit: Add test for storing a service
template that raises an exception
Add test for storing a service template that raises an exception
Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/7f370a9e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/7f370a9e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/7f370a9e
Branch: refs/heads/cli-tests
Commit: 7f370a9e1b3d9944fb4837d7a5db3cf3327ee5f9
Parents: 061dcd3
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Wed Apr 5 20:01:06 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Wed Apr 5 20:01:06 2017 +0300
----------------------------------------------------------------------
tests/cli/base_test.py | 17 ++++++++++++++++-
tests/cli/test_service_templates.py | 18 +++++++++++++++++-
2 files changed, 33 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7f370a9e/tests/cli/base_test.py
----------------------------------------------------------------------
diff --git a/tests/cli/base_test.py b/tests/cli/base_test.py
index d77260e..d5db9c2 100644
--- a/tests/cli/base_test.py
+++ b/tests/cli/base_test.py
@@ -20,4 +20,19 @@ class TestCliBase(object):
def assert_exception_raised(outcome, expected_exception, expected_msg):
assert isinstance(outcome.exception, expected_exception)
- assert expected_msg == str(outcome.exception)
\ No newline at end of file
+ assert expected_msg == str(outcome.exception)
+
+
+# This exists as I wanted to mocked a function using monkeypatch to return a function that raises an
+# exception. I tried doing that using a lambda in-place, but this can't be accomplished in a trivial
+# way it seems. So I wrote this silly function instead
+def raise_exception(exception, msg=''):
+
+ def inner(*args, **kwargs):
+ raise exception(msg)
+
+ return inner
+
+
+
+
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7f370a9e/tests/cli/test_service_templates.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_service_templates.py b/tests/cli/test_service_templates.py
index fc60fef..d0daf59 100644
--- a/tests/cli/test_service_templates.py
+++ b/tests/cli/test_service_templates.py
@@ -1,8 +1,9 @@
from aria.cli import service_template_utils
from aria.cli.env import Environment
+from aria.cli.exceptions import AriaCliError
from aria.core import Core
from aria.storage import exceptions as storage_exceptions
-from tests.cli.base_test import TestCliBase, assert_exception_raised
+from tests.cli.base_test import TestCliBase, assert_exception_raised, raise_exception
from tests.mock import models
import pytest
@@ -125,3 +126,18 @@ class TestServiceTemplatesStore(TestCliBase):
monkeypatch.setattr(service_template_utils, 'get', mock_object)
self.invoke('service_templates store stubpath test_st')
assert 'Service template test_st stored' in self.logger_output_string
+
+ def test_store_raises_exception(self, monkeypatch, mock_object):
+
+ monkeypatch.setattr(service_template_utils, 'get', mock_object)
+ monkeypatch.setattr(Core,
+ 'create_service_template',
+ raise_exception(storage_exceptions.NotFoundError,
+ msg='UNIQUE constraint failed'))
+
+ outcome = self.invoke('service_templates store stubpath test_st')
+ assert_exception_raised(
+ outcome,
+ expected_exception=AriaCliError,
+ expected_msg='Could not store service template `test_st`\n'
+ 'There already a exists a service template with the same name')