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:10 UTC
[3/3] incubator-ariatosca git commit: Add tests for service-templates
list
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'})
+
+