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.
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 TestNodesShow(TestCliBase):
30 def test_header_strings(self, monkeypatch, mock_storage):
31 monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
32 self.invoke('nodes show 1')
33 assert 'Showing node 1' in self.logger_output_string
34 assert 'Node:' in self.logger_output_string
35 assert 'Node attributes:' in self.logger_output_string
37 def test_no_attributes(self, monkeypatch, mock_storage):
39 monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
40 self.invoke('nodes show 2')
41 assert 'No attributes' in self.logger_output_string
42 assert 'attribute1' not in self.logger_output_string
43 assert 'value1' not in self.logger_output_string
45 def test_one_attribute(self, monkeypatch, mock_storage):
47 monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
49 return_value=mock_models.create_node_with_dependencies(include_attribute=True))
50 monkeypatch.setattr(mock_storage.node, 'get', m)
51 self.invoke('nodes show 3')
52 assert 'No attributes' not in self.logger_output_string
53 assert 'attribute1' in self.logger_output_string
54 assert 'value1' in self.logger_output_string
57 class TestNodesList(TestCliBase):
59 @pytest.mark.parametrize('sort_by, order, sort_by_in_output, order_in_output', [
60 ('', '', 'service_name', 'asc'),
61 ('', ' --descending', 'service_name', 'desc'),
62 (' --sort-by name', '', 'name', 'asc'),
63 (' --sort-by name', ' --descending', 'name', 'desc')
65 def test_list_specified_service(self, monkeypatch, mock_storage, sort_by, order,
66 sort_by_in_output, order_in_output):
68 monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
69 self.invoke('nodes list -s test_s{sort_by}{order}'.format(sort_by=sort_by,
71 assert 'Listing nodes for service test_s...' in self.logger_output_string
72 assert 'Listing all nodes...' not in self.logger_output_string
74 nodes_list = mock_storage.node.list
75 nodes_list.assert_called_once_with(sort={sort_by_in_output: order_in_output},
76 filters={'service': mock.ANY})
77 assert 'Nodes:' in self.logger_output_string
78 assert 'test_s' in self.logger_output_string
79 assert 'test_n' in self.logger_output_string
81 @pytest.mark.parametrize('sort_by, order, sort_by_in_output, order_in_output', [
82 ('', '', 'service_name', 'asc'),
83 ('', ' --descending', 'service_name', 'desc'),
84 (' --sort-by name', '', 'name', 'asc'),
85 (' --sort-by name', ' --descending', 'name', 'desc')
87 def test_list_no_specified_service(self, monkeypatch, mock_storage, sort_by, order,
88 sort_by_in_output, order_in_output):
90 monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
91 self.invoke('nodes list{sort_by}{order}'.format(sort_by=sort_by,
93 assert 'Listing nodes for service test_s...' not in self.logger_output_string
94 assert 'Listing all nodes...' in self.logger_output_string
96 nodes_list = mock_storage.node.list
97 nodes_list.assert_called_once_with(sort={sort_by_in_output: order_in_output},
99 assert 'Nodes:' in self.logger_output_string
100 assert 'test_s' in self.logger_output_string
101 assert 'test_n' in self.logger_output_string