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/15 13:07:56 UTC
[10/16] incubator-ariatosca git commit: Add tests for node-templates
show
Add tests for node-templates show
Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/68bf4fea
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/68bf4fea
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/68bf4fea
Branch: refs/heads/ARIA-48-aria-cli
Commit: 68bf4fea6c0bc66f825fdd6bc1bc7be7cf43b014
Parents: 7be3c64
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Thu Apr 13 15:05:10 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Sat Apr 15 15:51:54 2017 +0300
----------------------------------------------------------------------
tests/cli/base_test.py | 5 ++--
tests/cli/test_node_templates.py | 49 +++++++++++++++++++++++++++++++++++
tests/cli/utils.py | 44 +++++++++++++++++++++++--------
tests/mock/models.py | 2 +-
4 files changed, 86 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/68bf4fea/tests/cli/base_test.py
----------------------------------------------------------------------
diff --git a/tests/cli/base_test.py b/tests/cli/base_test.py
index a1a1acd..9268f71 100644
--- a/tests/cli/base_test.py
+++ b/tests/cli/base_test.py
@@ -1,10 +1,11 @@
from StringIO import StringIO
import logging
-import runner
-from utils import setup_logger, MockStorage
import pytest
+import tests.cli.runner as runner
+from tests.cli.utils import setup_logger, MockStorage
+
@pytest.fixture
def mock_storage():
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/68bf4fea/tests/cli/test_node_templates.py
----------------------------------------------------------------------
diff --git a/tests/cli/test_node_templates.py b/tests/cli/test_node_templates.py
new file mode 100644
index 0000000..4fb2b9d
--- /dev/null
+++ b/tests/cli/test_node_templates.py
@@ -0,0 +1,49 @@
+from aria.cli.env import Environment
+from tests.cli.base_test import TestCliBase, mock_storage
+
+
+class TestNodeTemplatesShow(TestCliBase):
+
+ def test_no_properties_no_nodes(self, monkeypatch, mock_storage):
+
+ monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+ self.invoke('node_templates show 1')
+ assert 'Showing node template 1' in self.logger_output_string
+ assert 'Node template properties:' in self.logger_output_string
+ assert 'No properties' in self.logger_output_string
+ assert 'prop1' not in self.logger_output_string and 'value1' not in self.logger_output_string
+ assert 'No nodes' in self.logger_output_string
+ assert 'node1' not in self.logger_output_string
+
+ def test_one_property_no_nodes(self, monkeypatch, mock_storage):
+
+ monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+ self.invoke('node_templates show 2')
+ assert 'Showing node template 2' in self.logger_output_string
+ assert 'Node template properties:' in self.logger_output_string
+ assert 'No properties' not in self.logger_output_string
+ assert 'prop1' in self.logger_output_string and 'value1' in self.logger_output_string
+ assert 'No nodes' in self.logger_output_string
+ assert 'node1' not in self.logger_output_string
+
+ def test_no_properties_one_node(self, monkeypatch, mock_storage):
+
+ monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+ self.invoke('node_templates show 3')
+ assert 'Showing node template 3' in self.logger_output_string
+ assert 'Node template properties:' in self.logger_output_string
+ assert 'No properties' in self.logger_output_string
+ assert 'prop1' not in self.logger_output_string and 'value1' not in self.logger_output_string
+ assert 'No nodes' not in self.logger_output_string
+ assert 'node1' in self.logger_output_string
+
+ def test_one_property_one_node(self, monkeypatch, mock_storage):
+
+ monkeypatch.setattr(Environment, 'model_storage', mock_storage)
+ self.invoke('node_templates show 4')
+ assert 'Showing node template 4' in self.logger_output_string
+ assert 'Node template properties:' in self.logger_output_string
+ assert 'No properties' not in self.logger_output_string
+ assert 'prop1' in self.logger_output_string and 'value1' in self.logger_output_string
+ assert 'No nodes' not in self.logger_output_string
+ assert 'node1' in self.logger_output_string
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/68bf4fea/tests/cli/utils.py
----------------------------------------------------------------------
diff --git a/tests/cli/utils.py b/tests/cli/utils.py
index 21047c9..a9ea44b 100644
--- a/tests/cli/utils.py
+++ b/tests/cli/utils.py
@@ -49,6 +49,7 @@ class MockStorage(object):
def __init__(self):
self.service_template = MockServiceTemplateStorage
self.service = MockServiceStorage()
+ self.node_template = MockNodeTemplateStorage
class MockServiceTemplateStorage(object):
@@ -63,14 +64,14 @@ class MockServiceTemplateStorage(object):
st = mock_models.create_service_template('test_st')
if id == '1': # no services and no description.
st.services = []
- if id == '2': # no services, but an description
+ elif id == '2': # no services, but an description
st.description = 'test_description'
st.services = []
- if id == '3': # one service, and a description
+ elif id == '3': # one service, and a description
service = mock_models.create_service(st, 'test_s')
st.description = 'test_description'
st.services = [service]
- if id == '4': # one service, and a description
+ elif id == '4': # one service, and a description
service = mock_models.create_service(st, 'test_s')
st.services = [service]
return st
@@ -79,11 +80,11 @@ class MockServiceTemplateStorage(object):
def get_by_name(name):
st = mock_models.create_service_template('test_st')
if name == 'with_inputs':
- input = mock_models.create_input(name='input1', value='value1')
+ input = mock_models.create_parameter(name='input1', value='value1')
st.inputs = {'input1': input}
- if name == 'without_inputs':
+ elif name == 'without_inputs':
st.inputs = {}
- if name == 'one_service':
+ elif name == 'one_service':
service = mock_models.create_service(st, 'test_s')
st.services = [service]
return st
@@ -104,7 +105,7 @@ class MockServiceStorage(object):
execution = mock_models.create_execution(test_s, status=models.Execution.STARTED)
execution.id = '1'
test_s.executions = [execution]
- if id == '2':
+ elif id == '2':
test_s = mock_models.create_service(test_st, 'service_with_available_nodes')
node_template = mock_models.create_node_template(service_template=test_st)
node = mock_models.create_node(name='test_node',
@@ -121,15 +122,36 @@ class MockServiceStorage(object):
m = MagicMock()
m.id = '1'
return m
- if name == 'service_with_available_nodes':
+ elif name == 'service_with_available_nodes':
m = MagicMock()
m.id = '2'
return m
- if name == 'service_with_no_inputs':
+ elif name == 'service_with_no_inputs':
test_s = mock_models.create_service(test_st, 'service_with_no_inputs')
- if name == 'service_with_one_input':
+ elif name == 'service_with_one_input':
test_s = mock_models.create_service(test_st, 'service_with_one_input')
- input = mock_models.create_input(name='input1', value='value1')
+ input = mock_models.create_parameter(name='input1', value='value1')
test_s.inputs = {'input1': input}
return test_s
+
+
+class MockNodeTemplateStorage(object):
+
+ @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')
+ if id == '1':
+ pass
+ elif id == '2':
+ prop1 = mock_models.create_parameter('prop1', 'value1')
+ nt.properties = {'prop1': prop1}
+ elif id == '3':
+ mock_models.create_node('node1', nt, s)
+ elif id == '4':
+ prop1 = mock_models.create_parameter('prop1', 'value1')
+ nt.properties = {'prop1': prop1}
+ mock_models.create_node('node1', nt, s)
+ return nt
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/68bf4fea/tests/mock/models.py
----------------------------------------------------------------------
diff --git a/tests/mock/models.py b/tests/mock/models.py
index 37ecbc0..a2b119d 100644
--- a/tests/mock/models.py
+++ b/tests/mock/models.py
@@ -238,7 +238,7 @@ def create_plugin_specification(name='test_plugin', version='0.1'):
)
-def create_input(name, value):
+def create_parameter(name, value):
p = models.Parameter()
return p.wrap(name, value)