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/06 14:31:13 UTC

[1/6] incubator-ariatosca git commit: Clean up the code a bit

Repository: incubator-ariatosca
Updated Branches:
  refs/heads/ARIA-48-aria-cli 97b865f8e -> e898e1064


Clean up the code a bit


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

Branch: refs/heads/ARIA-48-aria-cli
Commit: e898e1064fa51661c3ba39c711208dd58f856b3a
Parents: 314f09e
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Thu Apr 6 16:25:47 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Thu Apr 6 17:29:56 2017 +0300

----------------------------------------------------------------------
 tests/cli/test_service_templates.py | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/e898e106/tests/cli/test_service_templates.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_service_templates.py b/tests/cli/test_service_templates.py
index f79b22e..d357fad 100644
--- a/tests/cli/test_service_templates.py
+++ b/tests/cli/test_service_templates.py
@@ -94,9 +94,8 @@ class TestServiceTemplatesShow(TestCliBase):
 
         # 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,
+            self.invoke('service_templates show 5'),
             expected_exception=storage_exceptions.NotFoundError,
             expected_msg='Requested `ServiceTemplate` with ID `5` was not found')
 
@@ -146,9 +145,8 @@ class TestServiceTemplatesStore(TestCliBase):
                             raise_exception(storage_exceptions.NotFoundError,
                                             msg='UNIQUE constraint failed'))
 
-        outcome = self.invoke('service_templates store stubpath test_st')
         assert_exception_raised(
-            outcome,
+            self.invoke('service_templates store stubpath test_st'),
             expected_exception=AriaCliError,
             expected_msg='Could not store service template `test_st`\n'
                          'There already a exists a service template with the same name')
@@ -160,9 +158,8 @@ class TestServiceTemplatesStore(TestCliBase):
                             'create_service_template',
                             raise_exception(storage_exceptions.NotFoundError))
 
-        outcome = self.invoke('service_templates store stubpath test_st')
         assert_exception_raised(
-            outcome,
+            self.invoke('service_templates store stubpath test_st'),
             expected_exception=AriaCliError)
 
 


[6/6] incubator-ariatosca git commit: Add test for non `unique name` exception from service-templates store

Posted by av...@apache.org.
Add test for non `unique name` exception from service-templates store


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

Branch: refs/heads/ARIA-48-aria-cli
Commit: fe6ee154be942b51eec7d86e5e849290846848cb
Parents: 81f8894
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Thu Apr 6 15:02:18 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Thu Apr 6 17:29:56 2017 +0300

----------------------------------------------------------------------
 aria/cli/utils.py                   |  2 +-
 tests/cli/base_test.py              |  2 +-
 tests/cli/test_service_templates.py | 14 +++++++++++++-
 3 files changed, 15 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/fe6ee154/aria/cli/utils.py
----------------------------------------------------------------------
diff --git a/aria/cli/utils.py b/aria/cli/utils.py
index 99315c4..44358ec 100644
--- a/aria/cli/utils.py
+++ b/aria/cli/utils.py
@@ -158,4 +158,4 @@ def handle_storage_exception(e, model_class, name):
               'There already a exists a {model_class} with the same name' \
               .format(model_class=model_class, name=name)
         raise AriaCliError(msg)
-    raise
+    raise AriaCliError()

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/fe6ee154/tests/cli/base_test.py
----------------------------------------------------------------------
diff --git a/tests/cli/base_test.py b/tests/cli/base_test.py
index d5db9c2..1dae957 100644
--- a/tests/cli/base_test.py
+++ b/tests/cli/base_test.py
@@ -18,7 +18,7 @@ class TestCliBase(object):
         return self._logger_output.getvalue()
 
 
-def assert_exception_raised(outcome, expected_exception, expected_msg):
+def assert_exception_raised(outcome, expected_exception, expected_msg=''):
     assert isinstance(outcome.exception, expected_exception)
     assert expected_msg == str(outcome.exception)
 

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/fe6ee154/tests/cli/test_service_templates.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_service_templates.py b/tests/cli/test_service_templates.py
index 9d210c1..c98bc7e 100644
--- a/tests/cli/test_service_templates.py
+++ b/tests/cli/test_service_templates.py
@@ -127,7 +127,7 @@ class TestServiceTemplatesStore(TestCliBase):
         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):
+    def test_store_raises_exception_resulting_from_name_uniqueness(self, monkeypatch, mock_object):
 
         monkeypatch.setattr(service_template_utils, 'get', mock_object)
         monkeypatch.setattr(Core,
@@ -142,6 +142,18 @@ class TestServiceTemplatesStore(TestCliBase):
             expected_msg='Could not store service template `test_st`\n'
                          'There already a exists a service template with the same name')
 
+    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))
+
+        outcome = self.invoke('service_templates store stubpath test_st')
+        assert_exception_raised(
+            outcome,
+            expected_exception=AriaCliError)
+
 
 class TestServiceTemplatesDelete(TestCliBase):
 


[3/6] incubator-ariatosca git commit: Create testing framework for the CLI, and add some tests

Posted by av...@apache.org.
Create testing framework for the CLI, and add some tests

The tests are of:
service-templates show
service-templates list
service-templates store


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

Branch: refs/heads/ARIA-48-aria-cli
Commit: d54b3971f405e43d66a96ff2f710ae98f46030cb
Parents: 97b865f
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Wed Apr 5 11:28:11 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Thu Apr 6 17:29:56 2017 +0300

----------------------------------------------------------------------
 aria/cli/commands/__init__.py          |   1 -
 aria/cli/commands/service_templates.py |   5 +-
 tests/cli/base_test.py                 |  29 +++++-
 tests/cli/runner.py                    |  10 +-
 tests/cli/test_service_templates.py    | 136 ++++++++++++++++++++++++++--
 5 files changed, 160 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/d54b3971/aria/cli/commands/__init__.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/__init__.py b/aria/cli/commands/__init__.py
index 5da374b..7777791 100644
--- a/aria/cli/commands/__init__.py
+++ b/aria/cli/commands/__init__.py
@@ -17,7 +17,6 @@ from . import (
     executions,
     logs,
     node_templates,
-    node_templates,
     nodes,
     plugins,
     service_templates,

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/d54b3971/aria/cli/commands/service_templates.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/service_templates.py b/aria/cli/commands/service_templates.py
index a0e651f..5fcc973 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
@@ -66,7 +65,7 @@ def show(service_template_id, model_storage, logger):
         logger.info('{0}\n'.format(service_template_dict['description'].encode('UTF-8') or ''))
 
     logger.info('Existing services:')
-    logger.info('{0}\n'.format(json.dumps([d['name'] for d in services])))
+    logger.info('{0}\n'.format([s['name'] for s in services]))
 
 
 @service_templates.command(name='list',
@@ -122,7 +121,7 @@ def store(service_template_path, service_template_name, model_storage, resource_
                                      service_template_name)
     except storage_exceptions.StorageError as e:
         handle_storage_exception(e, 'service template', service_template_name)
-    logger.info('Service template stored')
+    logger.info('Service template {0} stored'.format(service_template_name))
 
 
 @service_templates.command(name='delete',

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/d54b3971/tests/cli/base_test.py
----------------------------------------------------------------------
diff --git a/tests/cli/base_test.py b/tests/cli/base_test.py
index c8c574b..d5db9c2 100644
--- a/tests/cli/base_test.py
+++ b/tests/cli/base_test.py
@@ -6,8 +6,33 @@ from utils import setup_logger
 
 class TestCliBase(object):
 
-    logger_output = StringIO()
-    setup_logger(logger_name='aria.cli.main', output_stream=logger_output)
+    _logger_output = StringIO()
+    setup_logger(logger_name='aria.cli.main', output_stream=_logger_output)
 
     def invoke(self, command):
+        self._logger_output.truncate(0)
         return runner.invoke(command)
+
+    @property
+    def logger_output_string(self):
+        return self._logger_output.getvalue()
+
+
+def assert_exception_raised(outcome, expected_exception, expected_msg):
+    assert isinstance(outcome.exception, expected_exception)
+    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/d54b3971/tests/cli/runner.py
----------------------------------------------------------------------
diff --git a/tests/cli/runner.py b/tests/cli/runner.py
index 26af20a..8b4294a 100644
--- a/tests/cli/runner.py
+++ b/tests/cli/runner.py
@@ -2,11 +2,11 @@ import aria.cli.commands as commands
 import click.testing
 
 
-def invoke(command):
-    # TODO handle verbosity later
-    command_string = ['service_templates', 'show', '1']
-    command, sub, args = command_string[0], command_string[1], command_string[2:]
+def invoke(command_string):
+    # TODO handle verbosity and co. later
+    command_list = command_string.split()
+    command, sub, args = command_list[0], command_list[1], command_list[2:]
     runner = click.testing.CliRunner()
     outcome = runner.invoke(getattr(
         getattr(commands, command), sub), args)
-    return outcome
\ No newline at end of file
+    return outcome

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/d54b3971/tests/cli/test_service_templates.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_service_templates.py b/tests/cli/test_service_templates.py
index 8e1fa65..d0daf59 100644
--- a/tests/cli/test_service_templates.py
+++ b/tests/cli/test_service_templates.py
@@ -1,27 +1,143 @@
+from aria.cli import service_template_utils
 from aria.cli.env import Environment
-from base_test import TestCliBase
-from aria.modeling.models import ServiceTemplate
+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, raise_exception
+from tests.mock import models
+
+import pytest
+
+
+@pytest.fixture
+def mock_object(mocker):
+    return mocker.MagicMock()
 
 
 class MockStorage(object):
 
     def __init__(self):
-        self.service_template = MockServiceTemplateStorage()
+        self.service_template = MockServiceTemplateStorage
 
 
 class MockServiceTemplateStorage(object):
 
-    def get(self, id_):
-        if id_ == '1':  # a service-template with no description and no services.
-            st = ServiceTemplate()
-            st.name = 'test_st'
+    @staticmethod
+    def list(**_):
+        return [models.create_service_template('test_st'),
+                models.create_service_template('test_st2')]
+
+    @staticmethod
+    def get(id):
+        st = models.create_service_template('test_st')
+        if id == '1':  # no services and no description.
+            st.services = []
+        if id == '2':  # no services, but an description
+            st.description = 'test_description'
             st.services = []
-            return st
+        if id == '3':  # one service, and a description
+            service = models.create_service(st, 'test_s')
+            st.description = 'test_description'
+            st.services = [service]
+        if id == '4':  # one service, and a description
+            service = models.create_service(st, 'test_s')
+            st.services = [service]
+        return st
 
 
 class TestServiceTemplatesShow(TestCliBase):
 
     def test_show_no_services_no_description(self, monkeypatch):
-        # reroute the logger to a special location, and check it's content.
+
+        monkeypatch.setattr(Environment, 'model_storage', MockStorage())
+        self.invoke('service_templates show 1')
+
+        assert 'Description:' not in self.logger_output_string
+        assert 'Existing services:\n[]' in self.logger_output_string
+
+    def test_show_no_services_yes_description(self, monkeypatch):
+
         monkeypatch.setattr(Environment, 'model_storage', MockStorage())
-        outcome = self.invoke('service_templates show 1')
+        self.invoke('service_templates show 2')
+
+        assert 'Description:\ntest_description' in self.logger_output_string
+        assert 'Existing services:\n[]' in self.logger_output_string
+
+    def test_show_one_service_yes_description(self, monkeypatch):
+
+        monkeypatch.setattr(Environment, 'model_storage', MockStorage())
+        self.invoke('service_templates show 3')
+
+        assert 'Description:\ntest_description' in self.logger_output_string
+        assert "Existing services:\n['test_s']" in self.logger_output_string
+
+    def test_show_one_service_no_description(self, monkeypatch):
+
+        monkeypatch.setattr(Environment, 'model_storage', MockStorage())
+        self.invoke('service_templates show 4')
+
+        assert 'Description:' not in self.logger_output_string
+        assert "Existing services:\n['test_s']" in self.logger_output_string
+
+    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,
+            expected_exception=storage_exceptions.NotFoundError,
+            expected_msg='Requested `ServiceTemplate` with ID `5` was not found')
+
+
+class TestServiceTemplatesList(TestCliBase):
+
+    def test_list_one_service_template(self, monkeypatch):
+
+        monkeypatch.setattr(Environment, 'model_storage', MockStorage())
+        self.invoke('service_templates list')
+        assert 'test_st' in self.logger_output_string
+        assert 'test_st2' in self.logger_output_string
+
+    def test_list_ascending(self, monkeypatch, mock_object):
+
+        monkeypatch.setattr(Environment, 'model_storage', mock_object)
+        self.invoke('service_templates list --sort-by name')
+        mock_object.service_template.list.assert_called_with(sort={'name': 'asc'})
+
+    def test_list_descending(self, monkeypatch, mock_object):
+
+        monkeypatch.setattr(Environment, 'model_storage', mock_object)
+        self.invoke('service_templates list --sort-by name --descending')
+        mock_object.service_template.list.assert_called_with(sort={'name': 'desc'})
+
+    def test_list_default_sorting(self, monkeypatch, mock_object):
+
+        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
+
+    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')


[2/6] incubator-ariatosca git commit: Add tests for service-templates inputs

Posted by av...@apache.org.
Add tests for service-templates inputs


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

Branch: refs/heads/ARIA-48-aria-cli
Commit: 54f3f52cab9688df1b9eb7df3bab0de159ee2d22
Parents: fe6ee15
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Thu Apr 6 15:54:26 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Thu Apr 6 17:29:56 2017 +0300

----------------------------------------------------------------------
 tests/cli/test_service_templates.py | 23 +++++++++++++++++++++++
 tests/mock/models.py                |  5 +++++
 2 files changed, 28 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/54f3f52c/tests/cli/test_service_templates.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_service_templates.py b/tests/cli/test_service_templates.py
index c98bc7e..3d5a8fb 100644
--- a/tests/cli/test_service_templates.py
+++ b/tests/cli/test_service_templates.py
@@ -44,6 +44,16 @@ class MockServiceTemplateStorage(object):
             st.services = [service]
         return st
 
+    @staticmethod
+    def get_by_name(name):
+        st = models.create_service_template('test_st')
+        if name == 'with_inputs':
+            input = models.create_input(name='input1', value='value1')
+            st.inputs = {'input1': input}
+        if name == 'without_inputs':
+            st.inputs = {}
+        return st
+
 
 class TestServiceTemplatesShow(TestCliBase):
 
@@ -175,3 +185,16 @@ class TestServiceTemplatesDelete(TestCliBase):
             self.invoke('service_templates delete test_st'),
             expected_exception=AriaCliError,
             expected_msg='')
+
+
+class TestServiceTemplatesInputs(TestCliBase):
+
+    def test_inputs_existing_inputs(self, monkeypatch):
+        monkeypatch.setattr(Environment, 'model_storage', MockStorage())
+        self.invoke('service_templates inputs with_inputs')
+        assert 'input1' in self.logger_output_string and 'value1' in self.logger_output_string
+
+    def test_inputs_no_inputs(self, monkeypatch):
+        monkeypatch.setattr(Environment, 'model_storage', MockStorage())
+        self.invoke('service_templates inputs without_inputs')
+        assert 'No inputs' in self.logger_output_string

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/54f3f52c/tests/mock/models.py
----------------------------------------------------------------------
diff --git a/tests/mock/models.py b/tests/mock/models.py
index 6b7f810..9771fe2 100644
--- a/tests/mock/models.py
+++ b/tests/mock/models.py
@@ -221,6 +221,11 @@ def create_plugin_specification(name='test_plugin', version='0.1'):
     )
 
 
+def create_input(name, value):
+    p = models.Parameter()
+    return p.wrap(name, value)
+
+
 def _dictify(item):
     return dict(((item.name, item),))
 


[4/6] incubator-ariatosca git commit: Add tests for service-templates delete

Posted by av...@apache.org.
Add tests for service-templates delete


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

Branch: refs/heads/ARIA-48-aria-cli
Commit: 81f8894ebca689950f1de13b124f481891223862
Parents: d54b397
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Thu Apr 6 14:02:56 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Thu Apr 6 17:29:56 2017 +0300

----------------------------------------------------------------------
 tests/cli/test_service_templates.py | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/81f8894e/tests/cli/test_service_templates.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_service_templates.py b/tests/cli/test_service_templates.py
index d0daf59..9d210c1 100644
--- a/tests/cli/test_service_templates.py
+++ b/tests/cli/test_service_templates.py
@@ -141,3 +141,25 @@ class TestServiceTemplatesStore(TestCliBase):
             expected_exception=AriaCliError,
             expected_msg='Could not store service template `test_st`\n'
                          'There already a exists a service template with the same name')
+
+
+class TestServiceTemplatesDelete(TestCliBase):
+
+    def test_delete_no_exception(self, monkeypatch, mock_object):
+
+        monkeypatch.setattr(Environment, 'model_storage', mock_object)
+        monkeypatch.setattr(Core, 'delete_service_template', mock_object)
+        self.invoke('service_templates delete test_st')
+        assert 'Service template test_st deleted' in self.logger_output_string
+
+    def test_delete_raises_exception(self, monkeypatch, mock_object):
+
+        monkeypatch.setattr(Environment, 'model_storage', mock_object)
+        monkeypatch.setattr(Core,
+                            'delete_service_template',
+                            raise_exception(storage_exceptions.NotFoundError))
+
+        assert_exception_raised(
+            self.invoke('service_templates delete test_st'),
+            expected_exception=AriaCliError,
+            expected_msg='')


[5/6] incubator-ariatosca git commit: Add tests for service-templates validate

Posted by av...@apache.org.
Add tests for service-templates validate


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

Branch: refs/heads/ARIA-48-aria-cli
Commit: 314f09e736cd6824da4f4839ff260ba87699bfa2
Parents: 54f3f52
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Thu Apr 6 16:23:02 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Thu Apr 6 17:29:56 2017 +0300

----------------------------------------------------------------------
 aria/cli/commands/service_templates.py |  3 +--
 tests/cli/test_service_templates.py    | 17 +++++++++++++++++
 2 files changed, 18 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/314f09e7/aria/cli/commands/service_templates.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/service_templates.py b/aria/cli/commands/service_templates.py
index 5fcc973..e2e21c7 100644
--- a/aria/cli/commands/service_templates.py
+++ b/aria/cli/commands/service_templates.py
@@ -169,8 +169,7 @@ def inputs(service_template_name, model_storage, logger):
 @aria.pass_resource_storage
 @aria.pass_plugin_manager
 @aria.pass_logger
-def validate_service_template(service_template, model_storage, resource_storage, plugin_manager,
-                              logger):
+def validate(service_template, model_storage, resource_storage, plugin_manager, logger):
     """Validate a service template
 
     `SERVICE_TEMPLATE` is the path or url of the service template or archive to validate.

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/314f09e7/tests/cli/test_service_templates.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_service_templates.py b/tests/cli/test_service_templates.py
index 3d5a8fb..f79b22e 100644
--- a/tests/cli/test_service_templates.py
+++ b/tests/cli/test_service_templates.py
@@ -2,6 +2,7 @@ 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.exceptions import AriaException
 from aria.storage import exceptions as storage_exceptions
 from tests.cli.base_test import TestCliBase, assert_exception_raised, raise_exception
 from tests.mock import models
@@ -198,3 +199,19 @@ class TestServiceTemplatesInputs(TestCliBase):
         monkeypatch.setattr(Environment, 'model_storage', MockStorage())
         self.invoke('service_templates inputs without_inputs')
         assert 'No inputs' in self.logger_output_string
+
+
+class TestServiceTemplatesValidate(TestCliBase):
+
+    def test_validate_no_exception(self, monkeypatch, mock_object):
+        monkeypatch.setattr(Core, 'validate_service_template', mock_object)
+        monkeypatch.setattr(service_template_utils, 'get', mock_object)
+        self.invoke('service_templates validate stubpath')
+        assert 'Service template validated successfully' in self.logger_output_string
+
+    def test_validate_raises_exception(self, monkeypatch, mock_object):
+        monkeypatch.setattr(Core, 'validate_service_template', raise_exception(AriaException))
+        monkeypatch.setattr(service_template_utils, 'get', mock_object)
+        assert_exception_raised(
+            self.invoke('service_templates validate stubpath'),
+            expected_exception=AriaCliError)