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:28 UTC
[1/3] incubator-ariatosca git commit: Add test for storing a service
template without exceptions
Repository: incubator-ariatosca
Updated Branches:
refs/heads/cli-tests 007e1642e -> 7f370a9e1
Add test for storing a service template without exceptions
Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/cba58712
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/cba58712
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/cba58712
Branch: refs/heads/cli-tests
Commit: cba58712776ae6dc67917bb2ac7b063cb87657cb
Parents: 007e164
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Wed Apr 5 18:12:40 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Wed Apr 5 18:12:40 2017 +0300
----------------------------------------------------------------------
aria/cli/commands/service_templates.py | 1 -
tests/cli/test_service_templates.py | 12 ++++++++++++
2 files changed, 12 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/cba58712/aria/cli/commands/service_templates.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/service_templates.py b/aria/cli/commands/service_templates.py
index 90d02c1..e05492e 100644
--- a/aria/cli/commands/service_templates.py
+++ b/aria/cli/commands/service_templates.py
@@ -15,7 +15,6 @@
import os
-import json
from .. import utils
from .. import csar
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/cba58712/tests/cli/test_service_templates.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_service_templates.py b/tests/cli/test_service_templates.py
index 4c2bf4d..87d859c 100644
--- a/tests/cli/test_service_templates.py
+++ b/tests/cli/test_service_templates.py
@@ -1,4 +1,6 @@
+from aria.cli import service_template_utils
from aria.cli.env import Environment
+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.mock import models
@@ -111,3 +113,13 @@ class TestServiceTemplatesList(TestCliBase):
monkeypatch.setattr(Environment, 'model_storage', mock_object)
self.invoke('service_templates list')
mock_object.service_template.list.assert_called_with(sort={'created_at': 'asc'})
+
+
+class TestServiceTemplatesStore(TestCliBase):
+
+ def test_store_no_exception(self, monkeypatch, mock_object):
+
+ monkeypatch.setattr(Core, 'create_service_template', mock_object)
+ 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
[2/3] incubator-ariatosca git commit: Add TODO for considering
removing a test
Posted by av...@apache.org.
Add TODO for considering removing a test
Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/061dcd3b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/061dcd3b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/061dcd3b
Branch: refs/heads/cli-tests
Commit: 061dcd3b9f42eef8b0d11b390c0c6fe380b037c4
Parents: cba5871
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Wed Apr 5 18:17:57 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Wed Apr 5 18:17:57 2017 +0300
----------------------------------------------------------------------
tests/cli/test_service_templates.py | 2 ++
1 file changed, 2 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/061dcd3b/tests/cli/test_service_templates.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_service_templates.py b/tests/cli/test_service_templates.py
index 87d859c..fc60fef 100644
--- a/tests/cli/test_service_templates.py
+++ b/tests/cli/test_service_templates.py
@@ -80,6 +80,8 @@ class TestServiceTemplatesShow(TestCliBase):
def test_show_exception_raise_when_no_service_template_with_given_id(self):
+ # TODO consider removing as it does not seem to test the cli but rather the message received
+ # from the storage
outcome = self.invoke('service_templates show 5')
assert_exception_raised(
outcome,
[3/3] incubator-ariatosca git commit: Add test for storing a service
template that raises an exception
Posted by av...@apache.org.
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')