|
| 1 | +# |
| 2 | +# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 3 | +# not use this file except in compliance with the License. You may obtain |
| 4 | +# a copy of the License at |
| 5 | +# |
| 6 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | +# |
| 8 | +# Unless required by applicable law or agreed to in writing, software |
| 9 | +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 10 | +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 11 | +# License for the specific language governing permissions and limitations |
| 12 | +# under the License. |
| 13 | +# |
| 14 | + |
| 15 | +from osc_lib import utils |
| 16 | + |
| 17 | +from openstackclient.tests.unit.volume.v2 import fakes as volume_fakes |
| 18 | +from openstackclient.volume.v2 import consistency_group |
| 19 | + |
| 20 | + |
| 21 | +class TestConsistencyGroup(volume_fakes.TestVolume): |
| 22 | + |
| 23 | + def setUp(self): |
| 24 | + super(TestConsistencyGroup, self).setUp() |
| 25 | + |
| 26 | + # Get a shortcut to the TransferManager Mock |
| 27 | + self.consistencygroups_mock = ( |
| 28 | + self.app.client_manager.volume.consistencygroups) |
| 29 | + self.consistencygroups_mock.reset_mock() |
| 30 | + |
| 31 | + |
| 32 | +class TestConsistencyGroupList(TestConsistencyGroup): |
| 33 | + |
| 34 | + consistency_groups = ( |
| 35 | + volume_fakes.FakeConsistencyGroup.create_consistency_groups(count=2)) |
| 36 | + |
| 37 | + columns = [ |
| 38 | + 'ID', |
| 39 | + 'Status', |
| 40 | + 'Name', |
| 41 | + ] |
| 42 | + columns_long = [ |
| 43 | + 'ID', |
| 44 | + 'Status', |
| 45 | + 'Availability Zone', |
| 46 | + 'Name', |
| 47 | + 'Description', |
| 48 | + 'Volume Types', |
| 49 | + ] |
| 50 | + data = [] |
| 51 | + for c in consistency_groups: |
| 52 | + data.append(( |
| 53 | + c.id, |
| 54 | + c.status, |
| 55 | + c.name, |
| 56 | + )) |
| 57 | + data_long = [] |
| 58 | + for c in consistency_groups: |
| 59 | + data_long.append(( |
| 60 | + c.id, |
| 61 | + c.status, |
| 62 | + c.availability_zone, |
| 63 | + c.name, |
| 64 | + c.description, |
| 65 | + utils.format_list(c.volume_types) |
| 66 | + )) |
| 67 | + |
| 68 | + def setUp(self): |
| 69 | + super(TestConsistencyGroupList, self).setUp() |
| 70 | + |
| 71 | + self.consistencygroups_mock.list.return_value = self.consistency_groups |
| 72 | + # Get the command to test |
| 73 | + self.cmd = consistency_group.ListConsistencyGroup(self.app, None) |
| 74 | + |
| 75 | + def test_consistency_group_list_without_options(self): |
| 76 | + arglist = [] |
| 77 | + verifylist = [ |
| 78 | + ("all_projects", False), |
| 79 | + ("long", False), |
| 80 | + ] |
| 81 | + |
| 82 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 83 | + columns, data = self.cmd.take_action(parsed_args) |
| 84 | + |
| 85 | + self.consistencygroups_mock.list.assert_called_once_with( |
| 86 | + detailed=True, search_opts={'all_tenants': False}) |
| 87 | + self.assertEqual(self.columns, columns) |
| 88 | + self.assertEqual(self.data, list(data)) |
| 89 | + |
| 90 | + def test_consistency_group_list_with_all_project(self): |
| 91 | + arglist = [ |
| 92 | + "--all-projects" |
| 93 | + ] |
| 94 | + verifylist = [ |
| 95 | + ("all_projects", True), |
| 96 | + ("long", False), |
| 97 | + ] |
| 98 | + |
| 99 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 100 | + columns, data = self.cmd.take_action(parsed_args) |
| 101 | + |
| 102 | + self.consistencygroups_mock.list.assert_called_once_with( |
| 103 | + detailed=True, search_opts={'all_tenants': True}) |
| 104 | + self.assertEqual(self.columns, columns) |
| 105 | + self.assertEqual(self.data, list(data)) |
| 106 | + |
| 107 | + def test_consistency_group_list_with_long(self): |
| 108 | + arglist = [ |
| 109 | + "--long", |
| 110 | + ] |
| 111 | + verifylist = [ |
| 112 | + ("all_projects", False), |
| 113 | + ("long", True), |
| 114 | + ] |
| 115 | + |
| 116 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 117 | + columns, data = self.cmd.take_action(parsed_args) |
| 118 | + |
| 119 | + self.consistencygroups_mock.list.assert_called_once_with( |
| 120 | + detailed=True, search_opts={'all_tenants': False}) |
| 121 | + self.assertEqual(self.columns_long, columns) |
| 122 | + self.assertEqual(self.data_long, list(data)) |
0 commit comments