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:16:08 UTC
[1/3] incubator-ariatosca git commit: Improve handling commands with
no arguments
Repository: incubator-ariatosca
Updated Branches:
refs/heads/cli-tests 472976b19 -> 10f75b0ec
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/8bb9c5ea
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/8bb9c5ea
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/8bb9c5ea
Branch: refs/heads/cli-tests
Commit: 8bb9c5ea2865bdb3e1b2dc78d679749de12f193a
Parents: 472976b
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 13:57:49 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/8bb9c5ea/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
[3/3] 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/10f75b0e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/10f75b0e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/10f75b0e
Branch: refs/heads/cli-tests
Commit: 10f75b0ecc64ef55eafe69f75579de1e383a1f6c
Parents: bf43ac7
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:15:48 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/10f75b0e/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'})
+
+
[2/3] 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/bf43ac77
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/bf43ac77
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/bf43ac77
Branch: refs/heads/cli-tests
Commit: bf43ac770a94fdf089c691f5cd6abb4335d42718
Parents: 8bb9c5e
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 14:18:12 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/bf43ac77/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