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/13 14:16:22 UTC
[13/14] incubator-ariatosca git commit: Add tests for nodes show and
nodes list
Add tests for nodes show and nodes 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/b0e15483
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/b0e15483
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/b0e15483
Branch: refs/heads/cli-tests
Commit: b0e15483d7f2d72f08107e2c1c5bf5f00a99d7a9
Parents: e08a68d
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Thu Apr 13 17:13:04 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Thu Apr 13 17:15:54 2017 +0300
----------------------------------------------------------------------
tests/cli/test_nodes.py | 75 ++++++++++++++++++++++++++++++++++++++++++++
tests/cli/utils.py | 26 +++++++++++++--
tests/mock/models.py | 9 +++---
3 files changed, 104 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/b0e15483/tests/cli/test_nodes.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_nodes.py b/tests/cli/test_nodes.py
new file mode 100644
index 0000000..7817e86
--- /dev/null
+++ b/tests/cli/test_nodes.py
@@ -0,0 +1,75 @@
+import pytest
+from mock import ANY
+
+from aria.cli.env import Environment
+from tests.cli.base_test import TestCliBase, mock_storage
+
+
+class TestNodesShow(TestCliBase):
+
+ def test_no_attributes(self, monkeypatch, mock_storage):
+
+ monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+ self.invoke('nodes show 1')
+ assert 'Showing node 1' in self.logger_output_string
+ assert 'Node:' in self.logger_output_string
+ assert 'Node attributes:' in self.logger_output_string
+ assert 'No attributes' in self.logger_output_string
+ assert 'attribute1' not in self.logger_output_string and 'value1' not in self.logger_output_string
+
+ def test_one_attribute(self, monkeypatch, mock_storage):
+
+ monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+ self.invoke('nodes show 2')
+ assert 'Showing node 2' in self.logger_output_string
+ assert 'Node:' in self.logger_output_string
+ assert 'Node attributes:' in self.logger_output_string
+ assert 'No attributes' not in self.logger_output_string
+ assert 'attribute1' in self.logger_output_string and 'value1' in self.logger_output_string
+
+
+class TestNodesList(TestCliBase):
+
+ @pytest.mark.parametrize('sort_by, order, sort_by_in_output, order_in_output', [
+ ('', '', 'service_name', 'asc'),
+ ('', ' --descending', 'service_name', 'desc'),
+ (' --sort-by name', '', 'name', 'asc'),
+ (' --sort-by name', ' --descending', 'name', 'desc')
+ ])
+ def test_list_specified_service(self, monkeypatch, mock_storage, sort_by, order,
+ sort_by_in_output, order_in_output):
+
+ monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+ self.invoke('nodes list -s test_s{sort_by}{order}'.format(sort_by=sort_by,
+ order=order))
+ assert 'Listing nodes for service test_s...' in self.logger_output_string
+ assert 'Listing all nodes...' not in self.logger_output_string
+
+ nodes_list = mock_storage.node.list
+ nodes_list.assert_called_once_with(sort={sort_by_in_output: order_in_output},
+ filters={'service': ANY})
+ assert 'Nodes:' in self.logger_output_string
+ assert 'test_s' in self.logger_output_string
+ assert 'test_n' in self.logger_output_string
+
+ @pytest.mark.parametrize('sort_by, order, sort_by_in_output, order_in_output', [
+ ('', '', 'service_name', 'asc'),
+ ('', ' --descending', 'service_name', 'desc'),
+ (' --sort-by name', '', 'name', 'asc'),
+ (' --sort-by name', ' --descending', 'name', 'desc')
+ ])
+ def test_list_specified_service(self, monkeypatch, mock_storage, sort_by, order,
+ sort_by_in_output, order_in_output):
+
+ monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+ self.invoke('nodes list{sort_by}{order}'.format(sort_by=sort_by,
+ order=order))
+ assert 'Listing nodes for service test_s...' not in self.logger_output_string
+ assert 'Listing all nodes...' in self.logger_output_string
+
+ nodes_list = mock_storage.node.list
+ nodes_list.assert_called_once_with(sort={sort_by_in_output: order_in_output},
+ filters={})
+ assert 'Nodes:' in self.logger_output_string
+ assert 'test_s' in self.logger_output_string
+ assert 'test_n' in self.logger_output_string
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/b0e15483/tests/cli/utils.py
----------------------------------------------------------------------
diff --git a/tests/cli/utils.py b/tests/cli/utils.py
index b538826..a3868ab 100644
--- a/tests/cli/utils.py
+++ b/tests/cli/utils.py
@@ -50,6 +50,7 @@ class MockStorage(object):
self.service_template = MockServiceTemplateStorage
self.service = MockServiceStorage()
self.node_template = MockNodeTemplateStorage()
+ self.node = MockNodeStorage()
class MockServiceTemplateStorage(object):
@@ -118,6 +119,7 @@ class MockServiceStorage(object):
@staticmethod
def get_by_name(name):
test_st = mock_models.create_service_template('test_st')
+ test_s = mock_models.create_service(test_st, 'test_s')
if name == 'service_with_active_executions':
m = MagicMock()
m.id = '1'
@@ -127,9 +129,9 @@ class MockServiceStorage(object):
m.id = '2'
return m
elif name == 'service_with_no_inputs':
- test_s = mock_models.create_service(test_st, 'service_with_no_inputs')
+ test_s. name = 'service_with_no_inputs'
elif name == 'service_with_one_input':
- test_s = mock_models.create_service(test_st, 'service_with_one_input')
+ test_s.name = 'service_with_one_input'
input = mock_models.create_parameter(name='input1', value='value1')
test_s.inputs = {'input1': input}
@@ -160,3 +162,23 @@ class MockNodeTemplateStorage(object):
nt.properties = {'prop1': prop1}
mock_models.create_node('node1', nt, s)
return nt
+
+class MockNodeStorage(object):
+
+ def __init__(self):
+ self.st = mock_models.create_service_template('test_st')
+ self.s = mock_models.create_service(self.st, 'test_s')
+ self.nt = mock_models.create_node_template(service_template=self.st, name='test_nt')
+ self.list = MagicMock(return_value=[mock_models.create_node('test_n', self.nt, self.s)])
+
+ @staticmethod
+ def get(id):
+ st = mock_models.create_service_template('test_st')
+ s = mock_models.create_service(st, 'test_s')
+ nt = mock_models.create_node_template(service_template=st, name='test_nt')
+ n = mock_models.create_node('test_n', nt, s)
+ if id == '1':
+ pass
+ elif id == '2':
+ n.runtime_properties = {'attribute1': 'value1'}
+ return n
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/b0e15483/tests/mock/models.py
----------------------------------------------------------------------
diff --git a/tests/mock/models.py b/tests/mock/models.py
index d2edb70..2f641ad 100644
--- a/tests/mock/models.py
+++ b/tests/mock/models.py
@@ -141,13 +141,14 @@ def create_dependent_node_template(
)
-def create_node(name, dependency_node_template, service,
- interfaces=None, state=models.Node.INITIAL):
-
+def create_node(name, dependency_node_template, service, state=models.Node.INITIAL,
+ runtime_properties=None):
+ runtime_properties = runtime_properties or {}
+ tmp_runtime_properties = {'ip': '1.1.1.1'}
node = models.Node(
name=name,
type=dependency_node_template.type,
- runtime_properties={'ip': '1.1.1.1'},
+ runtime_properties=runtime_properties,
version=None,
node_template=dependency_node_template,
state=state,