Skip to content

Commit 9e47688

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Update Fakes.py and unit tests for commands in identity V2.0"
2 parents e38a6e3 + a9da912 commit 9e47688

6 files changed

Lines changed: 319 additions & 383 deletions

File tree

openstackclient/tests/identity/v2_0/fakes.py

Lines changed: 57 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,19 @@
7676
}
7777

7878
token_expires = '2014-01-01T00:00:00Z'
79-
token_id = 'tttttttt-tttt-tttt-tttt-tttttttttttt'
79+
token_id = 'token-id-' + uuid.uuid4().hex
8080

8181
TOKEN = {
8282
'expires': token_expires,
8383
'id': token_id,
84-
'tenant_id': project_id,
85-
'user_id': user_id,
84+
'tenant_id': 'project-id',
85+
'user_id': 'user-id',
8686
}
8787

8888
UNSCOPED_TOKEN = {
8989
'expires': token_expires,
9090
'id': token_id,
91-
'user_id': user_id,
91+
'user_id': 'user-id',
9292
}
9393

9494
endpoint_name = service_name
@@ -110,8 +110,6 @@
110110
'publicurl': endpoint_publicurl,
111111
'service_id': endpoint_service_id,
112112
}
113-
SERVICE_NAME = 'service-name-' + uuid.uuid4().hex
114-
SERVICE_ID = 'service-id-' + uuid.uuid4().hex
115113

116114

117115
def fake_auth_ref(fake_token, fake_service=None):
@@ -244,7 +242,7 @@ def create_catalog(attrs=None):
244242

245243
# Set default attributes.
246244
catalog_info = {
247-
'id': SERVICE_ID,
245+
'id': 'service-id-' + uuid.uuid4().hex,
248246
'type': 'compute',
249247
'name': 'supernova',
250248
'endpoints': [
@@ -295,8 +293,8 @@ def create_one_project(attrs=None):
295293

296294
# set default attributes.
297295
project_info = {
298-
'id': 'project-id' + uuid.uuid4().hex,
299-
'name': 'project-name' + uuid.uuid4().hex,
296+
'id': 'project-id-' + uuid.uuid4().hex,
297+
'name': 'project-name-' + uuid.uuid4().hex,
300298
'description': 'project_description',
301299
'enabled': True,
302300
}
@@ -341,14 +339,14 @@ def create_one_endpoint(attrs=None):
341339

342340
# set default attributes.
343341
endpoint_info = {
344-
'service_name': SERVICE_NAME,
342+
'service_name': 'service-name-' + uuid.uuid4().hex,
345343
'adminurl': 'http://endpoint_adminurl',
346344
'region': 'endpoint_region',
347345
'internalurl': 'http://endpoint_internalurl',
348346
'service_type': 'service_type',
349347
'id': 'endpoint-id-' + uuid.uuid4().hex,
350348
'publicurl': 'http://endpoint_publicurl',
351-
'service_id': SERVICE_ID,
349+
'service_id': 'service-name-' + uuid.uuid4().hex,
352350

353351
}
354352
endpoint_info.update(attrs)
@@ -392,8 +390,8 @@ def create_one_service(attrs=None):
392390

393391
# set default attributes.
394392
service_info = {
395-
'id': SERVICE_ID,
396-
'name': SERVICE_NAME,
393+
'id': 'service-id-' + uuid.uuid4().hex,
394+
'name': 'service-name-' + uuid.uuid4().hex,
397395
'description': 'service_description',
398396
'type': 'service_type',
399397

@@ -464,3 +462,49 @@ def create_roles(attrs=None, count=2):
464462
roles.append(FakeRole.create_one_role(attrs))
465463

466464
return roles
465+
466+
467+
class FakeUser(object):
468+
"""Fake one or more user."""
469+
470+
@staticmethod
471+
def create_one_user(attrs=None):
472+
"""Create a fake user.
473+
474+
:param Dictionary attrs:
475+
A dictionary with all attributes
476+
:return:
477+
A FakeResource object, with id, name, and so on
478+
"""
479+
attrs = attrs or {}
480+
481+
# set default attributes.
482+
user_info = {
483+
'id': 'user-id-' + uuid.uuid4().hex,
484+
'name': 'user-name-' + uuid.uuid4().hex,
485+
'tenantId': 'project-id-' + uuid.uuid4().hex,
486+
'email': 'admin@openstack.org',
487+
'enabled': True,
488+
}
489+
user_info.update(attrs)
490+
491+
user = fakes.FakeResource(info=copy.deepcopy(user_info),
492+
loaded=True)
493+
return user
494+
495+
@staticmethod
496+
def create_users(attrs=None, count=2):
497+
"""Create multiple fake users.
498+
499+
:param Dictionary attrs:
500+
A dictionary with all attributes
501+
:param int count:
502+
The number of users to fake
503+
:return:
504+
A list of FakeResource objects faking the users
505+
"""
506+
users = []
507+
for i in range(0, count):
508+
users.append(FakeUser.create_one_user(attrs))
509+
510+
return users

openstackclient/tests/identity/v2_0/test_endpoint.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@
1717

1818
class TestEndpoint(identity_fakes.TestIdentityv2):
1919

20-
fake_endpoint = identity_fakes.FakeEndpoint.create_one_endpoint()
2120
fake_service = identity_fakes.FakeService.create_one_service()
21+
attr = {
22+
'service_name': fake_service.name,
23+
'service_id': fake_service.id,
24+
}
25+
fake_endpoint = identity_fakes.FakeEndpoint.create_one_endpoint(attr)
2226

2327
def setUp(self):
2428
super(TestEndpoint, self).setUp()

0 commit comments

Comments
 (0)