Debian Codegraph @

keystoneclient/tests/functional/v3/client_fixtures.py

raw symbols SCIP
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 import fixtures
14 import uuid
15
16
17 RESOURCE_NAME_PREFIX = 'keystoneclient-functional-'
18
19
20 class Base(fixtures.Fixture):
21
22 def __init__(self, client, domain_id=None):
23 super(Base, self).__init__()
24
25 self.client = client
26 self.domain_id = domain_id
27 self.ref = None
28 self.entity = None
29
30 def __getattr__(self, name):
31 """Return the attribute from the represented entity."""
32 return getattr(self.entity, name)
33
34
35 class User(Base):
36
37 def setUp(self):
38 super(User, self).setUp()
39
40 self.ref = {'name': RESOURCE_NAME_PREFIX + uuid.uuid4().hex,
41 'domain': self.domain_id}
42 self.entity = self.client.users.create(**self.ref)
43 self.addCleanup(self.client.users.delete, self.entity)
44
45
46 class Group(Base):
47
48 def setUp(self):
49 super(Group, self).setUp()
50
51 self.ref = {'name': RESOURCE_NAME_PREFIX + uuid.uuid4().hex,
52 'domain': self.domain_id}
53 self.entity = self.client.groups.create(**self.ref)
54 self.addCleanup(self.client.groups.delete, self.entity)
55
56
57 class Domain(Base):
58
59 def setUp(self):
60 super(Domain, self).setUp()
61
62 self.ref = {'name': RESOURCE_NAME_PREFIX + uuid.uuid4().hex,
63 'description': uuid.uuid4().hex,
64 'enabled': True}
65 self.entity = self.client.domains.create(**self.ref)
66
67 # Only disabled domains can be deleted
68 self.addCleanup(self.client.domains.delete, self.entity)
69 self.addCleanup(self.client.domains.update, self.entity, enabled=False)
70
71
72 class Project(Base):
73
74 def __init__(self, client, domain_id=None, parent=None, tags=None):
75 super(Project, self).__init__(client, domain_id)
76 self.parent = parent
77 self.tags = tags if tags else []
78
79 def setUp(self):
80 super(Project, self).setUp()
81
82 self.ref = {'name': RESOURCE_NAME_PREFIX + uuid.uuid4().hex,
83 'domain': self.domain_id,
84 'enabled': True,
85 'parent': self.parent,
86 'tags': self.tags}
87 self.entity = self.client.projects.create(**self.ref)
88 self.addCleanup(self.client.projects.delete, self.entity)
89
90
91 class Role(Base):
92
93 def __init__(self, client, name=None, domain=None):
94 super(Role, self).__init__(client)
95 self.name = name or RESOURCE_NAME_PREFIX + uuid.uuid4().hex
96 self.domain = domain
97
98 def setUp(self):
99 super(Role, self).setUp()
100
101 self.ref = {'name': self.name,
102 'domain': self.domain}
103 self.entity = self.client.roles.create(**self.ref)
104 self.addCleanup(self.client.roles.delete, self.entity)
105
106
107 class InferenceRule(Base):
108
109 def __init__(self, client, prior_role, implied_role):
110 super(InferenceRule, self).__init__(client)
111 self.prior_role = prior_role
112 self.implied_role = implied_role
113
114 def setUp(self):
115 super(InferenceRule, self).setUp()
116
117 self.ref = {'prior_role': self.prior_role,
118 'implied_role': self.implied_role}
119 self.entity = self.client.inference_rules.create(**self.ref)
120 self.addCleanup(self.client.inference_rules.delete, self.prior_role,
121 self.implied_role)
122
123
124 class Service(Base):
125
126 def setUp(self):
127 super(Service, self).setUp()
128
129 self.ref = {'name': RESOURCE_NAME_PREFIX + uuid.uuid4().hex,
130 'type': uuid.uuid4().hex,
131 'enabled': True,
132 'description': uuid.uuid4().hex}
133 self.entity = self.client.services.create(**self.ref)
134 self.addCleanup(self.client.services.delete, self.entity)
135
136
137 class Policy(Base):
138
139 def setUp(self):
140 super(Policy, self).setUp()
141
142 self.ref = {'blob': uuid.uuid4().hex,
143 'type': uuid.uuid4().hex}
144 self.entity = self.client.policies.create(**self.ref)
145 self.addCleanup(self.client.policies.delete, self.entity)
146
147
148 class Region(Base):
149
150 def __init__(self, client, parent_region=None):
151 super(Region, self).__init__(client)
152 self.parent_region = parent_region
153
154 def setUp(self):
155 super(Region, self).setUp()
156
157 self.ref = {'description': uuid.uuid4().hex,
158 'parent_region': self.parent_region}
159 self.entity = self.client.regions.create(**self.ref)
160 self.addCleanup(self.client.regions.delete, self.entity)
161
162
163 class Endpoint(Base):
164
165 def __init__(self, client, service, interface, region=None):
166 super(Endpoint, self).__init__(client)
167 self.service = service
168 self.interface = interface
169 self.region = region
170
171 def setUp(self):
172 super(Endpoint, self).setUp()
173
174 self.ref = {'service': self.service,
175 'url': 'http://' + uuid.uuid4().hex,
176 'enabled': True,
177 'interface': self.interface,
178 'region': self.region}
179 self.entity = self.client.endpoints.create(**self.ref)
180 self.addCleanup(self.client.endpoints.delete, self.entity)
181
182
183 class EndpointGroup(Base):
184
185 def setUp(self):
186 super(EndpointGroup, self).setUp()
187
188 self.ref = {'name': RESOURCE_NAME_PREFIX + uuid.uuid4().hex,
189 'filters': {'interface': 'public'},
190 'description': uuid.uuid4().hex}
191 self.entity = self.client.endpoint_groups.create(**self.ref)
192 self.addCleanup(self.client.endpoint_groups.delete, self.entity)
193
194
195 class Credential(Base):
196
197 def __init__(self, client, user, type, project=None):
198 super(Credential, self).__init__(client)
199 self.user = user
200 self.type = type
201 self.project = project
202
203 if type == 'ec2':
204 self.blob = ("{\"access\":\"" + uuid.uuid4().hex +
205 "\",\"secret\":\"secretKey\"}")
206 else:
207 self.blob = uuid.uuid4().hex
208
209 def setUp(self):
210 super(Credential, self).setUp()
211
212 self.ref = {'user': self.user,
213 'type': self.type,
214 'blob': self.blob,
215 'project': self.project}
216 self.entity = self.client.credentials.create(**self.ref)
217 self.addCleanup(self.client.credentials.delete, self.entity)
218
219
220 class EC2(Base):
221
222 def __init__(self, client, user_id, project_id):
223 super(EC2, self).__init__(client)
224 self.user_id = user_id
225 self.project_id = project_id
226
227 def setUp(self):
228 super(EC2, self).setUp()
229
230 self.ref = {'user_id': self.user_id,
231 'project_id': self.project_id}
232 self.entity = self.client.ec2.create(**self.ref)
233 self.addCleanup(self.client.ec2.delete,
234 self.user_id,
235 self.entity.access)
236
237
238 class DomainConfig(Base):
239
240 def __init__(self, client, domain_id):
241 super(DomainConfig, self).__init__(client, domain_id=domain_id)
242 self.domain_id = domain_id
243
244 def setUp(self):
245 super(DomainConfig, self).setUp()
246
247 self.ref = {'identity': {'driver': uuid.uuid4().hex},
248 'ldap': {'url': uuid.uuid4().hex}}
249 self.entity = self.client.domain_configs.create(
250 self.domain_id, self.ref)
251 self.addCleanup(self.client.domain_configs.delete,
252 self.domain_id)