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 13:58:17 UTC

[01/17] incubator-ariatosca git commit: ARIA-137-Support-for-predicate-based-queries-in-the-SQL-mapi [Forced Update!]

Repository: incubator-ariatosca
Updated Branches:
  refs/heads/cli-tests 10f75b0ec -> 007e1642e (forced update)


ARIA-137-Support-for-predicate-based-queries-in-the-SQL-mapi


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

Branch: refs/heads/cli-tests
Commit: 9df203e829127c91fee05318a5a748d36f744900
Parents: 327cbd1
Author: max-orlov <ma...@gigaspaces.com>
Authored: Tue Apr 4 20:41:59 2017 +0300
Committer: max-orlov <ma...@gigaspaces.com>
Committed: Wed Apr 5 16:36:43 2017 +0300

----------------------------------------------------------------------
 aria/storage/sql_mapi.py            | 28 +++++++++++++++-
 tests/storage/test_model_storage.py | 57 ++++++++++++++++++++++++++++++++
 2 files changed, 84 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/9df203e8/aria/storage/sql_mapi.py
----------------------------------------------------------------------
diff --git a/aria/storage/sql_mapi.py b/aria/storage/sql_mapi.py
index 40c5410..144c925 100644
--- a/aria/storage/sql_mapi.py
+++ b/aria/storage/sql_mapi.py
@@ -31,6 +31,13 @@ from . import (
     exceptions,
 )
 
+_predicates = {'ge': '__ge__',
+               'gt': '__gt__',
+               'lt': '__lt__',
+               'le': '__le__',
+               'eq': '__eq__',
+               'ne': '__ne__'}
+
 
 class SQLAlchemyModelAPI(api.ModelAPI):
     """
@@ -243,7 +250,10 @@ class SQLAlchemyModelAPI(api.ModelAPI):
     @staticmethod
     def _add_value_filter(query, filters):
         for column, value in filters.items():
-            if isinstance(value, (list, tuple)):
+            if isinstance(value, dict):
+                for predicate, operand in value.items():
+                    query = query.filter(getattr(column, predicate)(operand))
+            elif isinstance(value, (list, tuple)):
                 query = query.filter(column.in_(value))
             else:
                 query = query.filter(column == value)
@@ -269,12 +279,28 @@ class SQLAlchemyModelAPI(api.ModelAPI):
         include, filters, sort, joins = self._get_joins_and_converted_columns(
             include, filters, sort
         )
+        filters = self._convert_operands(filters)
 
         query = self._get_base_query(include, joins)
         query = self._filter_query(query, filters)
         query = self._sort_query(query, sort)
         return query
 
+    @staticmethod
+    def _convert_operands(filters):
+        for column, conditions in filters.items():
+            if isinstance(conditions, dict):
+                for predicate, operand in conditions.items():
+                    if predicate not in _predicates:
+                        raise exceptions.StorageError(
+                            "{0} is not a valid predicate for filtering. Valid predicates are {1}"
+                            .format(predicate, ', '.join(_predicates.keys())))
+                    del filters[column][predicate]
+                    filters[column][_predicates[predicate]] = operand
+
+
+        return filters
+
     def _get_joins_and_converted_columns(self,
                                          include,
                                          filters,

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/9df203e8/tests/storage/test_model_storage.py
----------------------------------------------------------------------
diff --git a/tests/storage/test_model_storage.py b/tests/storage/test_model_storage.py
index e4f3eba..4dabfaf 100644
--- a/tests/storage/test_model_storage.py
+++ b/tests/storage/test_model_storage.py
@@ -15,6 +15,12 @@
 
 import pytest
 
+from sqlalchemy import (
+    Column,
+    Integer,
+    Text
+)
+
 from aria import (
     application_model_storage,
     modeling
@@ -150,3 +156,54 @@ def test_mapi_include(context):
 
     assert_include(service1)
     assert_include(service2)
+
+
+class MockModel(modeling.models.aria_declarative_base, modeling.mixins.ModelMixin): #pylint: disable=abstract-method
+    __tablename__ = 'op_mock_model'
+
+    name = Column(Text)
+    value = Column(Integer)
+
+
+class TestFilterOperands(object):
+
+    @pytest.fixture()
+    def storage(self):
+        model_storage = application_model_storage(
+            sql_mapi.SQLAlchemyModelAPI, initiator=tests_storage.init_inmemory_model_storage)
+        model_storage.register(MockModel)
+        for value in (1, 2, 3, 4):
+            model_storage.op_mock_model.put(MockModel(value=value))
+        yield model_storage
+        tests_storage.release_sqlite_storage(model_storage)
+
+    def test_gt(self, storage):
+        assert len(storage.op_mock_model.list(filters=dict(value=dict(gt=3)))) == 1
+        assert len(storage.op_mock_model.list(filters=dict(value=dict(gt=4)))) == 0
+
+    def test_ge(self, storage):
+        assert len(storage.op_mock_model.list(filters=dict(value=dict(ge=3)))) == 2
+        assert len(storage.op_mock_model.list(filters=dict(value=dict(ge=5)))) == 0
+
+    def test_lt(self, storage):
+        assert len(storage.op_mock_model.list(filters=dict(value=dict(lt=2)))) == 1
+        assert len(storage.op_mock_model.list(filters=dict(value=dict(lt=1)))) == 0
+
+    def test_le(self, storage):
+        assert len(storage.op_mock_model.list(filters=dict(value=dict(le=2)))) == 2
+        assert len(storage.op_mock_model.list(filters=dict(value=dict(le=0)))) == 0
+
+    def test_eq(self, storage):
+        assert len(storage.op_mock_model.list(filters=dict(value=dict(eq=2)))) == 1
+        assert len(storage.op_mock_model.list(filters=dict(value=dict(eq=0)))) == 0
+
+    def test_neq(self, storage):
+        assert len(storage.op_mock_model.list(filters=dict(value=dict(ne=2)))) == 3
+
+    def test_gt_and_lt(self, storage):
+        assert len(storage.op_mock_model.list(filters=dict(value=dict(gt=1, lt=3)))) == 1
+        assert len(storage.op_mock_model.list(filters=dict(value=dict(gt=2, lt=2)))) == 0
+
+    def test_eq_and_ne(self, storage):
+        assert len(storage.op_mock_model.list(filters=dict(value=dict(eq=1, ne=3)))) == 1
+        assert len(storage.op_mock_model.list(filters=dict(value=dict(eq=1, ne=1)))) == 0


[14/17] incubator-ariatosca git commit: Add tests for service-templates list

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


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

Branch: refs/heads/cli-tests
Commit: e3948ce718bf3a07312f0ec3d2f078236fa91cf0
Parents: 90a28a6
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Wed Apr 5 16:15:48 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Wed Apr 5 16:49:57 2017 +0300

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


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/e3948ce7/tests/cli/test_service_templates.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_service_templates.py b/tests/cli/test_service_templates.py
index 62d06ff..d95e9ac 100644
--- a/tests/cli/test_service_templates.py
+++ b/tests/cli/test_service_templates.py
@@ -1,7 +1,16 @@
 from aria.cli.env import Environment
-from base_test import TestCliBase, assert_exception_raised
 from aria.storage import exceptions as storage_exceptions
+from tests.cli.base_test import TestCliBase, assert_exception_raised
 from tests.mock import models
+
+import pytest
+
+
+@pytest.fixture
+def mock_storage(mocker):
+    return mocker.MagicMock()
+
+
 class MockStorage(object):
 
     def __init__(self):
@@ -10,6 +19,10 @@ class MockStorage(object):
 
 class MockServiceTemplateStorage(object):
 
+    def list(self, **_):
+        return [models.create_service_template('test_st'),
+                models.create_service_template('test_st2')]
+
     def get(self, id):
         st = models.create_service_template('test_st')
         if id == '1':  # no services and no description.
@@ -68,3 +81,33 @@ class TestServiceTemplatesShow(TestCliBase):
             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_storage):
+
+        monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+        self.invoke('service_templates list --sort-by name')
+        mock_storage.service_template.list.assert_called_with(sort={'name': 'asc'})
+
+    def test_list_descending(self, monkeypatch, mock_storage):
+
+        monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+        self.invoke('service_templates list --sort-by name --descending')
+        mock_storage.service_template.list.assert_called_with(sort={'name': 'desc'})
+
+    def test_list_default_sorting(self, monkeypatch, mock_storage):
+
+        monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+        self.invoke('service_templates list')
+        mock_storage.service_template.list.assert_called_with(sort={'created_at': 'asc'})
+
+


[15/17] incubator-ariatosca git commit: Use the existing mock models module to create the mock storage

Posted by av...@apache.org.
Use the existing mock models module to create the mock storage


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

Branch: refs/heads/cli-tests
Commit: 90a28a67c4f43563c7097fe2e816400118d5bae2
Parents: 4da1cb9
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Wed Apr 5 14:18:12 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Wed Apr 5 16:49:57 2017 +0300

----------------------------------------------------------------------
 tests/cli/test_service_templates.py | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/90a28a67/tests/cli/test_service_templates.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_service_templates.py b/tests/cli/test_service_templates.py
index 900b8a4..62d06ff 100644
--- a/tests/cli/test_service_templates.py
+++ b/tests/cli/test_service_templates.py
@@ -1,8 +1,7 @@
 from aria.cli.env import Environment
 from base_test import TestCliBase, assert_exception_raised
-from aria.modeling.models import ServiceTemplate, Service
 from aria.storage import exceptions as storage_exceptions
-
+from tests.mock import models
 class MockStorage(object):
 
     def __init__(self):
@@ -12,21 +11,18 @@ class MockStorage(object):
 class MockServiceTemplateStorage(object):
 
     def get(self, id):
-        st = ServiceTemplate()
-        st.name = 'test_st'
+        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 = []
         if id == '3':  # one service, and a description
-            service = Service()
-            service.name = 'test_s'
+            service = models.create_service(st, 'test_s')
             st.description = 'test_description'
             st.services = [service]
         if id == '4':  # one service, and a description
-            service = Service()
-            service.name = 'test_s'
+            service = models.create_service(st, 'test_s')
             st.services = [service]
         return st
 


[10/17] incubator-ariatosca git commit: Add testing service templates with a service and a description

Posted by av...@apache.org.
Add testing service templates with a service and a description


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

Branch: refs/heads/cli-tests
Commit: 43518c73a2e63d0463f3a12a0bd6f2f478138361
Parents: ecf15e1
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Wed Apr 5 11:58:25 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Wed Apr 5 16:49:57 2017 +0300

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


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/43518c73/tests/cli/test_service_templates.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_service_templates.py b/tests/cli/test_service_templates.py
index d5cea10..d35139e 100644
--- a/tests/cli/test_service_templates.py
+++ b/tests/cli/test_service_templates.py
@@ -1,6 +1,6 @@
 from aria.cli.env import Environment
 from base_test import TestCliBase
-from aria.modeling.models import ServiceTemplate
+from aria.modeling.models import ServiceTemplate, Service
 
 
 class MockStorage(object):
@@ -19,6 +19,11 @@ class MockServiceTemplateStorage(object):
         if id == '2':  # no services, but an description
             st.description = 'test_description'
             st.services = []
+        if id == '3':  # one service, and a description
+            service = Service()
+            service.name = 'test_s'
+            st.description = 'test_description'
+            st.services = [service]
         return st
 
 
@@ -39,3 +44,11 @@ class TestServiceTemplatesShow(TestCliBase):
 
         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())
+        outcome = 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


[09/17] incubator-ariatosca git commit: Reset the file holding the logger output before running each command

Posted by av...@apache.org.
Reset the file holding the logger output before running each command


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

Branch: refs/heads/cli-tests
Commit: ecf15e102875d0a5efbaca411ee978be8a4b656f
Parents: 77298d6
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Wed Apr 5 11:47:40 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Wed Apr 5 16:49:57 2017 +0300

----------------------------------------------------------------------
 tests/cli/base_test.py | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/ecf15e10/tests/cli/base_test.py
----------------------------------------------------------------------
diff --git a/tests/cli/base_test.py b/tests/cli/base_test.py
index 70befc0..3b7e746 100644
--- a/tests/cli/base_test.py
+++ b/tests/cli/base_test.py
@@ -10,6 +10,7 @@ class TestCliBase(object):
     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


[03/17] incubator-ariatosca git commit: Add test for trying to show a service template with an invalid id

Posted by av...@apache.org.
Add test for trying to show a service template with an invalid id


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

Branch: refs/heads/cli-tests
Commit: 530cfce0db91f6148d8d41591d004077d049c2ae
Parents: 7759b51
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Wed Apr 5 13:00:14 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Wed Apr 5 16:49:57 2017 +0300

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


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/530cfce0/tests/cli/base_test.py
----------------------------------------------------------------------
diff --git a/tests/cli/base_test.py b/tests/cli/base_test.py
index 3b7e746..d77260e 100644
--- a/tests/cli/base_test.py
+++ b/tests/cli/base_test.py
@@ -16,3 +16,8 @@ class TestCliBase(object):
     @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)
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/530cfce0/tests/cli/test_service_templates.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_service_templates.py b/tests/cli/test_service_templates.py
index 91ddd92..900b8a4 100644
--- a/tests/cli/test_service_templates.py
+++ b/tests/cli/test_service_templates.py
@@ -1,7 +1,7 @@
 from aria.cli.env import Environment
-from base_test import TestCliBase
+from base_test import TestCliBase, assert_exception_raised
 from aria.modeling.models import ServiceTemplate, Service
-
+from aria.storage import exceptions as storage_exceptions
 
 class MockStorage(object):
 
@@ -63,4 +63,12 @@ class TestServiceTemplatesShow(TestCliBase):
         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
\ No newline at end of file
+        assert "Existing services:\n['test_s']" in self.logger_output_string
+
+    def test_show_exception_raise_when_no_service_template_with_given_id(self):
+
+        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')


[04/17] incubator-ariatosca git commit: Fix runner invoke command

Posted by av...@apache.org.
Fix runner invoke command


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

Branch: refs/heads/cli-tests
Commit: bd2904e6e42fbcb58489522d14888a8004480255
Parents: 5e20196
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Wed Apr 5 11:30:49 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Wed Apr 5 16:49:57 2017 +0300

----------------------------------------------------------------------
 tests/cli/runner.py | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/bd2904e6/tests/cli/runner.py
----------------------------------------------------------------------
diff --git a/tests/cli/runner.py b/tests/cli/runner.py
index 26af20a..d956a06 100644
--- a/tests/cli/runner.py
+++ b/tests/cli/runner.py
@@ -2,10 +2,9 @@ import aria.cli.commands as commands
 import click.testing
 
 
-def invoke(command):
+def invoke(command_string):
     # TODO handle verbosity later
-    command_string = ['service_templates', 'show', '1']
-    command, sub, args = command_string[0], command_string[1], command_string[2:]
+    command, sub, args = command_string.split()
     runner = click.testing.CliRunner()
     outcome = runner.invoke(getattr(
         getattr(commands, command), sub), args)


[17/17] incubator-ariatosca git commit: Print stored service template name

Posted by av...@apache.org.
Print stored service template name


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

Branch: refs/heads/cli-tests
Commit: 8b4dbe5444eb1530c4204076462b7a2ce19293c7
Parents: aa82ffa
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Wed Apr 5 16:48:10 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Wed Apr 5 16:49:57 2017 +0300

----------------------------------------------------------------------
 aria/cli/commands/service_templates.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/8b4dbe54/aria/cli/commands/service_templates.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/service_templates.py b/aria/cli/commands/service_templates.py
index d11ca08..90d02c1 100644
--- a/aria/cli/commands/service_templates.py
+++ b/aria/cli/commands/service_templates.py
@@ -121,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',


[06/17] incubator-ariatosca git commit: Add test for show service-template with description

Posted by av...@apache.org.
Add test for show service-template with description


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

Branch: refs/heads/cli-tests
Commit: 9a2befc004ae816da03160e81f26f962aeb361db
Parents: bd2904e
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Wed Apr 5 11:31:58 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Wed Apr 5 16:49:57 2017 +0300

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


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/9a2befc0/tests/cli/test_service_templates.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_service_templates.py b/tests/cli/test_service_templates.py
index 8e1fa65..d5cea10 100644
--- a/tests/cli/test_service_templates.py
+++ b/tests/cli/test_service_templates.py
@@ -11,17 +11,31 @@ class MockStorage(object):
 
 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'
+    def get(self, id):
+        st = ServiceTemplate()
+        st.name = 'test_st'
+        if id == '1':  # no services and no description.
             st.services = []
-            return st
+        if id == '2':  # no services, but an description
+            st.description = 'test_description'
+            st.services = []
+        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())
         outcome = 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 2')
+
+        assert 'Description:\ntest_description' in self.logger_output_string
+        assert 'Existing services:\n[]' in self.logger_output_string


[16/17] incubator-ariatosca git commit: Add mock_object fixture

Posted by av...@apache.org.
Add mock_object fixture


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

Branch: refs/heads/cli-tests
Commit: 007e1642e3f6ce0c587163a860a435d5bf2249ad
Parents: 8b4dbe5
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Wed Apr 5 16:48:50 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Wed Apr 5 16:49:57 2017 +0300

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


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/007e1642/tests/cli/test_service_templates.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_service_templates.py b/tests/cli/test_service_templates.py
index a6b5f12..4c2bf4d 100644
--- a/tests/cli/test_service_templates.py
+++ b/tests/cli/test_service_templates.py
@@ -7,7 +7,7 @@ import pytest
 
 
 @pytest.fixture
-def mock_storage(mocker):
+def mock_object(mocker):
     return mocker.MagicMock()
 
 
@@ -94,20 +94,20 @@ class TestServiceTemplatesList(TestCliBase):
         assert 'test_st' in self.logger_output_string
         assert 'test_st2' in self.logger_output_string
 
-    def test_list_ascending(self, monkeypatch, mock_storage):
+    def test_list_ascending(self, monkeypatch, mock_object):
 
-        monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+        monkeypatch.setattr(Environment, 'model_storage', mock_object)
         self.invoke('service_templates list --sort-by name')
-        mock_storage.service_template.list.assert_called_with(sort={'name': 'asc'})
+        mock_object.service_template.list.assert_called_with(sort={'name': 'asc'})
 
-    def test_list_descending(self, monkeypatch, mock_storage):
+    def test_list_descending(self, monkeypatch, mock_object):
 
-        monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+        monkeypatch.setattr(Environment, 'model_storage', mock_object)
         self.invoke('service_templates list --sort-by name --descending')
-        mock_storage.service_template.list.assert_called_with(sort={'name': 'desc'})
+        mock_object.service_template.list.assert_called_with(sort={'name': 'desc'})
 
-    def test_list_default_sorting(self, monkeypatch, mock_storage):
+    def test_list_default_sorting(self, monkeypatch, mock_object):
 
-        monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+        monkeypatch.setattr(Environment, 'model_storage', mock_object)
         self.invoke('service_templates list')
-        mock_storage.service_template.list.assert_called_with(sort={'created_at': 'asc'})
+        mock_object.service_template.list.assert_called_with(sort={'created_at': 'asc'})


[05/17] incubator-ariatosca git commit: Add testing service templates with a service but no description

Posted by av...@apache.org.
Add testing service templates with a service but no description


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

Branch: refs/heads/cli-tests
Commit: 7759b51e4231c5512e3bce5a2a8e35d5c34cd25e
Parents: 9850296
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Wed Apr 5 12:09:11 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Wed Apr 5 16:49:57 2017 +0300

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


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7759b51e/tests/cli/test_service_templates.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_service_templates.py b/tests/cli/test_service_templates.py
index aa562ce..91ddd92 100644
--- a/tests/cli/test_service_templates.py
+++ b/tests/cli/test_service_templates.py
@@ -24,6 +24,10 @@ class MockServiceTemplateStorage(object):
             service.name = 'test_s'
             st.description = 'test_description'
             st.services = [service]
+        if id == '4':  # one service, and a description
+            service = Service()
+            service.name = 'test_s'
+            st.services = [service]
         return st
 
 
@@ -52,3 +56,11 @@ class TestServiceTemplatesShow(TestCliBase):
 
         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
\ No newline at end of file


[08/17] incubator-ariatosca git commit: Make importing the commands module import all of its subcommands

Posted by av...@apache.org.
Make importing the commands module import all of its subcommands


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

Branch: refs/heads/cli-tests
Commit: 77298d69b2dd316e753acbf8ea967cdd540327ff
Parents: 9a2befc
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Wed Apr 5 11:32:34 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Wed Apr 5 16:49:57 2017 +0300

----------------------------------------------------------------------
 aria/cli/commands/__init__.py | 11 +++++++++++
 1 file changed, 11 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/77298d69/aria/cli/commands/__init__.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/__init__.py b/aria/cli/commands/__init__.py
index ae1e83e..7777791 100644
--- a/aria/cli/commands/__init__.py
+++ b/aria/cli/commands/__init__.py
@@ -12,3 +12,14 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
+
+from . import (
+    executions,
+    logs,
+    node_templates,
+    nodes,
+    plugins,
+    service_templates,
+    services,
+    workflows
+)


[02/17] incubator-ariatosca git commit: Change MockStorage methods to static

Posted by av...@apache.org.
Change MockStorage methods to static


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

Branch: refs/heads/cli-tests
Commit: aa82ffa2dd2d7d6174395eda25cd622f40832a54
Parents: e3948ce
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Wed Apr 5 16:26:41 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Wed Apr 5 16:49:57 2017 +0300

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


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/aa82ffa2/tests/cli/test_service_templates.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_service_templates.py b/tests/cli/test_service_templates.py
index d95e9ac..a6b5f12 100644
--- a/tests/cli/test_service_templates.py
+++ b/tests/cli/test_service_templates.py
@@ -14,16 +14,18 @@ def mock_storage(mocker):
 class MockStorage(object):
 
     def __init__(self):
-        self.service_template = MockServiceTemplateStorage()
+        self.service_template = MockServiceTemplateStorage
 
 
 class MockServiceTemplateStorage(object):
 
-    def list(self, **_):
+    @staticmethod
+    def list(**_):
         return [models.create_service_template('test_st'),
                 models.create_service_template('test_st2')]
 
-    def get(self, id):
+    @staticmethod
+    def get(id):
         st = models.create_service_template('test_st')
         if id == '1':  # no services and no description.
             st.services = []
@@ -109,5 +111,3 @@ class TestServiceTemplatesList(TestCliBase):
         monkeypatch.setattr(Environment, 'model_storage', mock_storage)
         self.invoke('service_templates list')
         mock_storage.service_template.list.assert_called_with(sort={'created_at': 'asc'})
-
-


[07/17] incubator-ariatosca git commit: Add property to get logger output string

Posted by av...@apache.org.
Add property to get logger output string


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

Branch: refs/heads/cli-tests
Commit: 5e2019612687c752b1e5f5ad01314454d9598ff3
Parents: 9df203e
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Wed Apr 5 11:28:11 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Wed Apr 5 16:49:57 2017 +0300

----------------------------------------------------------------------
 tests/cli/base_test.py | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/5e201961/tests/cli/base_test.py
----------------------------------------------------------------------
diff --git a/tests/cli/base_test.py b/tests/cli/base_test.py
index c8c574b..70befc0 100644
--- a/tests/cli/base_test.py
+++ b/tests/cli/base_test.py
@@ -6,8 +6,12 @@ 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):
         return runner.invoke(command)
+
+    @property
+    def logger_output_string(self):
+        return self._logger_output.getvalue()


[11/17] incubator-ariatosca git commit: No need for json.dumps while printing the names of the services

Posted by av...@apache.org.
No need for json.dumps while printing the names of the services


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

Branch: refs/heads/cli-tests
Commit: d346d330df35b9ec5fdee4e947ae39fde05cc931
Parents: 43518c7
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Wed Apr 5 12:04:01 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Wed Apr 5 16:49:57 2017 +0300

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


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/d346d330/aria/cli/commands/service_templates.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/service_templates.py b/aria/cli/commands/service_templates.py
index a324131..d11ca08 100644
--- a/aria/cli/commands/service_templates.py
+++ b/aria/cli/commands/service_templates.py
@@ -66,7 +66,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',

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/d346d330/tests/cli/test_service_templates.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_service_templates.py b/tests/cli/test_service_templates.py
index d35139e..e52207d 100644
--- a/tests/cli/test_service_templates.py
+++ b/tests/cli/test_service_templates.py
@@ -51,4 +51,4 @@ class TestServiceTemplatesShow(TestCliBase):
         outcome = 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
+        assert "Existing services:\n['test_s']" in self.logger_output_string


[13/17] incubator-ariatosca git commit: Improve handling commands with no arguments

Posted by av...@apache.org.
Improve handling commands with no arguments


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

Branch: refs/heads/cli-tests
Commit: 4da1cb9e70b9bc47fe7aa14dd907bd1b0acfd9df
Parents: 530cfce
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Wed Apr 5 13:57:49 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Wed Apr 5 16:49:57 2017 +0300

----------------------------------------------------------------------
 tests/cli/runner.py | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/4da1cb9e/tests/cli/runner.py
----------------------------------------------------------------------
diff --git a/tests/cli/runner.py b/tests/cli/runner.py
index d956a06..8b4294a 100644
--- a/tests/cli/runner.py
+++ b/tests/cli/runner.py
@@ -3,9 +3,10 @@ import click.testing
 
 
 def invoke(command_string):
-    # TODO handle verbosity later
-    command, sub, args = command_string.split()
+    # 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


[12/17] incubator-ariatosca git commit: Remove a variable when it is not used

Posted by av...@apache.org.
Remove a variable when it is not used


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

Branch: refs/heads/cli-tests
Commit: 985029658df665d68058cf4302fd037d7422c48a
Parents: d346d33
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Wed Apr 5 12:06:08 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Wed Apr 5 16:49:57 2017 +0300

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


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/98502965/tests/cli/test_service_templates.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_service_templates.py b/tests/cli/test_service_templates.py
index e52207d..aa562ce 100644
--- a/tests/cli/test_service_templates.py
+++ b/tests/cli/test_service_templates.py
@@ -32,7 +32,7 @@ class TestServiceTemplatesShow(TestCliBase):
     def test_show_no_services_no_description(self, monkeypatch):
 
         monkeypatch.setattr(Environment, 'model_storage', MockStorage())
-        outcome = self.invoke('service_templates show 1')
+        self.invoke('service_templates show 1')
 
         assert 'Description:' not in self.logger_output_string
         assert 'Existing services:\n[]' in self.logger_output_string
@@ -40,7 +40,7 @@ class TestServiceTemplatesShow(TestCliBase):
     def test_show_no_services_yes_description(self, monkeypatch):
 
         monkeypatch.setattr(Environment, 'model_storage', MockStorage())
-        outcome = self.invoke('service_templates show 2')
+        self.invoke('service_templates show 2')
 
         assert 'Description:\ntest_description' in self.logger_output_string
         assert 'Existing services:\n[]' in self.logger_output_string
@@ -48,7 +48,7 @@ class TestServiceTemplatesShow(TestCliBase):
     def test_show_one_service_yes_description(self, monkeypatch):
 
         monkeypatch.setattr(Environment, 'model_storage', MockStorage())
-        outcome = self.invoke('service_templates show 3')
+        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