|
| 1 | +# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 2 | +# not use this file except in compliance with the License. You may obtain |
| 3 | +# a copy of the License at |
| 4 | +# |
| 5 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | +# |
| 7 | +# Unless required by applicable law or agreed to in writing, software |
| 8 | +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 9 | +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 10 | +# License for the specific language governing permissions and limitations |
| 11 | +# under the License. |
| 12 | +# |
| 13 | + |
| 14 | +import copy |
| 15 | + |
| 16 | +from openstackclient.identity.v3 import group |
| 17 | +from openstackclient.tests import fakes |
| 18 | +from openstackclient.tests.identity.v3 import fakes as identity_fakes |
| 19 | + |
| 20 | + |
| 21 | +class TestGroup(identity_fakes.TestIdentityv3): |
| 22 | + |
| 23 | + def setUp(self): |
| 24 | + super(TestGroup, self).setUp() |
| 25 | + |
| 26 | + # Get a shortcut to the DomainManager Mock |
| 27 | + self.domains_mock = self.app.client_manager.identity.domains |
| 28 | + self.domains_mock.reset_mock() |
| 29 | + |
| 30 | + # Get a shortcut to the GroupManager Mock |
| 31 | + self.groups_mock = self.app.client_manager.identity.groups |
| 32 | + self.groups_mock.reset_mock() |
| 33 | + |
| 34 | + # Get a shortcut to the UserManager Mock |
| 35 | + self.users_mock = self.app.client_manager.identity.users |
| 36 | + self.users_mock.reset_mock() |
| 37 | + |
| 38 | + |
| 39 | +class TestGroupList(TestGroup): |
| 40 | + |
| 41 | + def setUp(self): |
| 42 | + super(TestGroupList, self).setUp() |
| 43 | + |
| 44 | + self.groups_mock.get.return_value = fakes.FakeResource( |
| 45 | + None, |
| 46 | + copy.deepcopy(identity_fakes.GROUP), |
| 47 | + loaded=True, |
| 48 | + ) |
| 49 | + self.groups_mock.list.return_value = [ |
| 50 | + fakes.FakeResource( |
| 51 | + None, |
| 52 | + copy.deepcopy(identity_fakes.GROUP), |
| 53 | + loaded=True, |
| 54 | + ), |
| 55 | + ] |
| 56 | + |
| 57 | + self.domains_mock.get.return_value = fakes.FakeResource( |
| 58 | + None, |
| 59 | + copy.deepcopy(identity_fakes.DOMAIN), |
| 60 | + loaded=True, |
| 61 | + ) |
| 62 | + |
| 63 | + self.users_mock.get.return_value = fakes.FakeResource( |
| 64 | + None, |
| 65 | + copy.deepcopy(identity_fakes.USER), |
| 66 | + loaded=True, |
| 67 | + ) |
| 68 | + |
| 69 | + # Get the command object to test |
| 70 | + self.cmd = group.ListGroup(self.app, None) |
| 71 | + |
| 72 | + def test_group_list_no_options(self): |
| 73 | + arglist = [] |
| 74 | + verifylist = [] |
| 75 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 76 | + |
| 77 | + # DisplayCommandBase.take_action() returns two tuples |
| 78 | + columns, data = self.cmd.take_action(parsed_args) |
| 79 | + |
| 80 | + # Set expected values |
| 81 | + kwargs = { |
| 82 | + 'domain': None, |
| 83 | + 'user': None, |
| 84 | + } |
| 85 | + |
| 86 | + self.groups_mock.list.assert_called_with( |
| 87 | + **kwargs |
| 88 | + ) |
| 89 | + |
| 90 | + collist = ('ID', 'Name') |
| 91 | + self.assertEqual(columns, collist) |
| 92 | + datalist = (( |
| 93 | + identity_fakes.group_id, |
| 94 | + identity_fakes.group_name, |
| 95 | + ), ) |
| 96 | + self.assertEqual(datalist, tuple(data)) |
| 97 | + |
| 98 | + def test_group_list_domain(self): |
| 99 | + arglist = [ |
| 100 | + '--domain', identity_fakes.domain_id, |
| 101 | + ] |
| 102 | + verifylist = [ |
| 103 | + ('domain', identity_fakes.domain_id), |
| 104 | + ] |
| 105 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 106 | + |
| 107 | + # DisplayCommandBase.take_action() returns two tuples |
| 108 | + columns, data = self.cmd.take_action(parsed_args) |
| 109 | + |
| 110 | + # Set expected values |
| 111 | + kwargs = { |
| 112 | + 'domain': identity_fakes.domain_id, |
| 113 | + 'user': None, |
| 114 | + } |
| 115 | + |
| 116 | + self.groups_mock.list.assert_called_with( |
| 117 | + **kwargs |
| 118 | + ) |
| 119 | + |
| 120 | + collist = ('ID', 'Name') |
| 121 | + self.assertEqual(columns, collist) |
| 122 | + datalist = (( |
| 123 | + identity_fakes.group_id, |
| 124 | + identity_fakes.group_name, |
| 125 | + ), ) |
| 126 | + self.assertEqual(datalist, tuple(data)) |
| 127 | + |
| 128 | + def test_group_list_user(self): |
| 129 | + arglist = [ |
| 130 | + '--user', identity_fakes.user_name, |
| 131 | + ] |
| 132 | + verifylist = [ |
| 133 | + ('user', identity_fakes.user_name), |
| 134 | + ] |
| 135 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 136 | + |
| 137 | + # DisplayCommandBase.take_action() returns two tuples |
| 138 | + columns, data = self.cmd.take_action(parsed_args) |
| 139 | + |
| 140 | + # Set expected values |
| 141 | + kwargs = { |
| 142 | + 'domain': None, |
| 143 | + 'user': identity_fakes.user_id, |
| 144 | + } |
| 145 | + |
| 146 | + self.groups_mock.list.assert_called_with( |
| 147 | + **kwargs |
| 148 | + ) |
| 149 | + |
| 150 | + collist = ('ID', 'Name') |
| 151 | + self.assertEqual(columns, collist) |
| 152 | + datalist = (( |
| 153 | + identity_fakes.group_id, |
| 154 | + identity_fakes.group_name, |
| 155 | + ), ) |
| 156 | + self.assertEqual(datalist, tuple(data)) |
| 157 | + |
| 158 | + def test_group_list_long(self): |
| 159 | + arglist = [ |
| 160 | + '--long', |
| 161 | + ] |
| 162 | + verifylist = [ |
| 163 | + ('long', True), |
| 164 | + ] |
| 165 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 166 | + |
| 167 | + # DisplayCommandBase.take_action() returns two tuples |
| 168 | + columns, data = self.cmd.take_action(parsed_args) |
| 169 | + |
| 170 | + # Set expected values |
| 171 | + kwargs = { |
| 172 | + 'domain': None, |
| 173 | + 'user': None, |
| 174 | + } |
| 175 | + |
| 176 | + self.groups_mock.list.assert_called_with( |
| 177 | + **kwargs |
| 178 | + ) |
| 179 | + |
| 180 | + collist = ( |
| 181 | + 'ID', |
| 182 | + 'Name', |
| 183 | + 'Domain ID', |
| 184 | + 'Description', |
| 185 | + ) |
| 186 | + self.assertEqual(columns, collist) |
| 187 | + datalist = (( |
| 188 | + identity_fakes.group_id, |
| 189 | + identity_fakes.group_name, |
| 190 | + '', |
| 191 | + '', |
| 192 | + ), ) |
| 193 | + self.assertEqual(datalist, tuple(data)) |
0 commit comments