1 # Licensed to the Apache Software Foundation (ASF) under one or more
2 # contributor license agreements. See the NOTICE file distributed with
3 # this work for additional information regarding copyright ownership.
4 # The ASF licenses this file to You under the Apache License, Version 2.0
5 # (the "License"); you may not use this file except in compliance with
6 # the License. You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
17 from mock import ANY, MagicMock
19 from aria.cli.env import _Environment
21 from .base_test import ( # pylint: disable=unused-import
25 from ..mock import models as mock_models
28 class TestNodeTemplatesShow(TestCliBase):
30 def test_header_strings(self, monkeypatch, mock_storage):
31 monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
32 self.invoke('node_templates show 1')
33 assert 'Showing node template 1' in self.logger_output_string
34 assert 'Node template properties:' in self.logger_output_string
35 assert 'Nodes:' in self.logger_output_string
37 def test_no_properties_no_nodes(self, monkeypatch, mock_storage):
39 monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
40 self.invoke('node_templates show 1')
42 assert 'No properties' in self.logger_output_string
43 assert 'prop1' not in self.logger_output_string
44 assert 'value1' not in self.logger_output_string
45 assert 'No nodes' in self.logger_output_string
46 assert mock_models.NODE_NAME not in self.logger_output_string
48 def test_one_property_no_nodes(self, monkeypatch, mock_storage):
50 monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
51 m = MagicMock(return_value=mock_models.create_node_template_with_dependencies(
52 include_property=True))
53 monkeypatch.setattr(mock_storage.node_template, 'get', m)
54 self.invoke('node_templates show 2')
55 assert 'No properties' not in self.logger_output_string
56 assert 'prop1' in self.logger_output_string and 'value1' in self.logger_output_string
57 assert 'No nodes' in self.logger_output_string
58 assert mock_models.NODE_NAME not in self.logger_output_string
60 def test_no_properties_one_node(self, monkeypatch, mock_storage):
62 monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
63 m = MagicMock(return_value=mock_models.create_node_template_with_dependencies(
65 monkeypatch.setattr(mock_storage.node_template, 'get', m)
66 self.invoke('node_templates show 3')
67 assert 'No properties' in self.logger_output_string
68 assert 'prop1' not in self.logger_output_string
69 assert 'value1' not in self.logger_output_string
70 assert 'No nodes' not in self.logger_output_string
71 assert mock_models.NODE_NAME in self.logger_output_string
73 def test_one_property_one_node(self, monkeypatch, mock_storage):
75 monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
76 m = MagicMock(return_value=mock_models.create_node_template_with_dependencies(
77 include_node=True, include_property=True))
78 monkeypatch.setattr(mock_storage.node_template, 'get', m)
79 self.invoke('node_templates show 4')
80 assert 'No properties' not in self.logger_output_string
81 assert 'prop1' in self.logger_output_string and 'value1' in self.logger_output_string
82 assert 'No nodes' not in self.logger_output_string
83 assert mock_models.NODE_NAME in self.logger_output_string
86 class TestNodeTemplatesList(TestCliBase):
88 @pytest.mark.parametrize('sort_by, order, sort_by_in_output, order_in_output', [
89 ('', '', 'service_template_name', 'asc'),
90 ('', ' --descending', 'service_template_name', 'desc'),
91 (' --sort-by name', '', 'name', 'asc'),
92 (' --sort-by name', ' --descending', 'name', 'desc')
94 def test_list_specified_service_template(self, monkeypatch, mock_storage, sort_by, order,
95 sort_by_in_output, order_in_output):
97 monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
98 self.invoke('node_templates list -t {service_template_name}{sort_by}{order}'
99 .format(service_template_name=mock_models.SERVICE_TEMPLATE_NAME,
102 assert 'Listing node templates for service template {name}...'\
103 .format(name=mock_models.SERVICE_TEMPLATE_NAME) in self.logger_output_string
104 assert 'Listing all node templates...' not in self.logger_output_string
106 node_templates_list = mock_storage.node_template.list
107 node_templates_list.assert_called_once_with(sort={sort_by_in_output: order_in_output},
108 filters={'service_template': ANY})
109 assert 'Node templates:' in self.logger_output_string
110 assert mock_models.SERVICE_TEMPLATE_NAME in self.logger_output_string
111 assert mock_models.NODE_TEMPLATE_NAME in self.logger_output_string
113 @pytest.mark.parametrize('sort_by, order, sort_by_in_output, order_in_output', [
114 ('', '', 'service_template_name', 'asc'),
115 ('', ' --descending', 'service_template_name', 'desc'),
116 (' --sort-by name', '', 'name', 'asc'),
117 (' --sort-by name', ' --descending', 'name', 'desc')
119 def test_list_no_specified_service_template(self, monkeypatch, mock_storage, sort_by, order,
120 sort_by_in_output, order_in_output):
122 monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
123 self.invoke('node_templates list{sort_by}{order}'.format(sort_by=sort_by, order=order))
124 assert 'Listing all node templates...' in self.logger_output_string
125 assert 'Listing node templates for service template {name}...'\
126 .format(name=mock_models.SERVICE_TEMPLATE_NAME) not in self.logger_output_string
128 node_templates_list = mock_storage.node_template.list
129 node_templates_list.assert_called_once_with(sort={sort_by_in_output: order_in_output},
131 assert 'Node templates:' in self.logger_output_string
132 assert mock_models.SERVICE_TEMPLATE_NAME in self.logger_output_string
133 assert mock_models.NODE_TEMPLATE_NAME in self.logger_output_string