1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
import copy
from openstackclient.identity.v3 import trust
from openstackclient.tests import fakes
from openstackclient.tests.identity.v3 import fakes as identity_fakes
class TestTrust(identity_fakes.TestIdentityv3):
def setUp(self):
super(TestTrust, self).setUp()
self.trusts_mock = self.app.client_manager.identity.trusts
self.trusts_mock.reset_mock()
self.projects_mock = self.app.client_manager.identity.projects
self.projects_mock.reset_mock()
self.users_mock = self.app.client_manager.identity.users
self.users_mock.reset_mock()
self.roles_mock = self.app.client_manager.identity.roles
self.roles_mock.reset_mock()
class TestTrustCreate(TestTrust):
def setUp(self):
super(TestTrustCreate, self).setUp()
self.projects_mock.get.return_value = fakes.FakeResource(
None,
copy.deepcopy(identity_fakes.PROJECT),
loaded=True,
)
self.users_mock.get.return_value = fakes.FakeResource(
None,
copy.deepcopy(identity_fakes.USER),
loaded=True,
)
self.roles_mock.get.return_value = fakes.FakeResource(
None,
copy.deepcopy(identity_fakes.ROLE),
loaded=True,
)
self.trusts_mock.create.return_value = fakes.FakeResource(
None,
copy.deepcopy(identity_fakes.TRUST),
loaded=True,
)
# Get the command object to test
self.cmd = trust.CreateTrust(self.app, None)
def test_trust_create_basic(self):
arglist = [
'--project', identity_fakes.project_id,
'--role', identity_fakes.role_id,
identity_fakes.user_id,
identity_fakes.user_id
]
verifylist = [
('project', identity_fakes.project_id),
('impersonate', False),
('role', [identity_fakes.role_id]),
('trustor', identity_fakes.user_id),
('trustee', identity_fakes.user_id),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
# DisplayCommandBase.take_action() returns two tuples
columns, data = self.cmd.take_action(parsed_args)
# Set expected values
kwargs = {
'impersonation': False,
'project': identity_fakes.project_id,
'role_names': [identity_fakes.role_name],
'expires_at': None,
}
# TrustManager.create(trustee_id, trustor_id, impersonation=,
# project=, role_names=, expires_at=)
self.trusts_mock.create.assert_called_with(
identity_fakes.user_id,
identity_fakes.user_id,
**kwargs
)
collist = ('expires_at', 'id', 'impersonation', 'project_id',
'roles', 'trustee_user_id', 'trustor_user_id')
self.assertEqual(collist, columns)
datalist = (
identity_fakes.trust_expires,
identity_fakes.trust_id,
identity_fakes.trust_impersonation,
identity_fakes.project_id,
identity_fakes.role_name + ' ',
identity_fakes.user_id,
identity_fakes.user_id
)
self.assertEqual(datalist, data)
class TestTrustDelete(TestTrust):
def setUp(self):
super(TestTrustDelete, self).setUp()
# This is the return value for utils.find_resource()
self.trusts_mock.get.return_value = fakes.FakeResource(
None,
copy.deepcopy(identity_fakes.TRUST),
loaded=True,
)
self.trusts_mock.delete.return_value = None
# Get the command object to test
self.cmd = trust.DeleteTrust(self.app, None)
def test_trust_delete(self):
arglist = [
identity_fakes.trust_id,
]
verifylist = [
('trust', [identity_fakes.trust_id])
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
self.cmd.take_action(parsed_args)
self.trusts_mock.delete.assert_called_with(
identity_fakes.trust_id,
)
class TestTrustList(TestTrust):
def setUp(self):
super(TestTrustList, self).setUp()
self.trusts_mock.list.return_value = [
fakes.FakeResource(
None,
copy.deepcopy(identity_fakes.TRUST),
loaded=True,
),
]
# Get the command object to test
self.cmd = trust.ListTrust(self.app, None)
def test_trust_list_no_options(self):
arglist = []
verifylist = []
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
# DisplayCommandBase.take_action() returns two tuples
columns, data = self.cmd.take_action(parsed_args)
self.trusts_mock.list.assert_called_with()
collist = ('ID', 'Expires At', 'Impersonation', 'Project ID',
'Trustee User ID', 'Trustor User ID')
self.assertEqual(collist, columns)
datalist = ((
identity_fakes.trust_id,
identity_fakes.trust_expires,
identity_fakes.trust_impersonation,
identity_fakes.project_id,
identity_fakes.user_id,
identity_fakes.user_id
), )
self.assertEqual(datalist, tuple(data))
class TestTrustShow(TestTrust):
def setUp(self):
super(TestTrustShow, self).setUp()
self.trusts_mock.get.return_value = fakes.FakeResource(
None,
copy.deepcopy(identity_fakes.TRUST),
loaded=True,
)
# Get the command object to test
self.cmd = trust.ShowTrust(self.app, None)
def test_trust_show(self):
arglist = [
identity_fakes.trust_id,
]
verifylist = [
('trust', identity_fakes.trust_id),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
# DisplayCommandBase.take_action() returns two tuples
columns, data = self.cmd.take_action(parsed_args)
self.trusts_mock.get.assert_called_with(identity_fakes.trust_id)
collist = ('expires_at', 'id', 'impersonation', 'project_id',
'roles', 'trustee_user_id', 'trustor_user_id')
self.assertEqual(collist, columns)
datalist = (
identity_fakes.trust_expires,
identity_fakes.trust_id,
identity_fakes.trust_impersonation,
identity_fakes.project_id,
identity_fakes.role_name + ' ',
identity_fakes.user_id,
identity_fakes.user_id
)
self.assertEqual(datalist, data)
|