|
76 | 76 | } |
77 | 77 |
|
78 | 78 | token_expires = '2014-01-01T00:00:00Z' |
79 | | -token_id = 'tttttttt-tttt-tttt-tttt-tttttttttttt' |
| 79 | +token_id = 'token-id-' + uuid.uuid4().hex |
80 | 80 |
|
81 | 81 | TOKEN = { |
82 | 82 | 'expires': token_expires, |
83 | 83 | 'id': token_id, |
84 | | - 'tenant_id': project_id, |
85 | | - 'user_id': user_id, |
| 84 | + 'tenant_id': 'project-id', |
| 85 | + 'user_id': 'user-id', |
86 | 86 | } |
87 | 87 |
|
88 | 88 | UNSCOPED_TOKEN = { |
89 | 89 | 'expires': token_expires, |
90 | 90 | 'id': token_id, |
91 | | - 'user_id': user_id, |
| 91 | + 'user_id': 'user-id', |
92 | 92 | } |
93 | 93 |
|
94 | 94 | endpoint_name = service_name |
|
110 | 110 | 'publicurl': endpoint_publicurl, |
111 | 111 | 'service_id': endpoint_service_id, |
112 | 112 | } |
113 | | -SERVICE_NAME = 'service-name-' + uuid.uuid4().hex |
114 | | -SERVICE_ID = 'service-id-' + uuid.uuid4().hex |
115 | 113 |
|
116 | 114 |
|
117 | 115 | def fake_auth_ref(fake_token, fake_service=None): |
@@ -244,7 +242,7 @@ def create_catalog(attrs=None): |
244 | 242 |
|
245 | 243 | # Set default attributes. |
246 | 244 | catalog_info = { |
247 | | - 'id': SERVICE_ID, |
| 245 | + 'id': 'service-id-' + uuid.uuid4().hex, |
248 | 246 | 'type': 'compute', |
249 | 247 | 'name': 'supernova', |
250 | 248 | 'endpoints': [ |
@@ -295,8 +293,8 @@ def create_one_project(attrs=None): |
295 | 293 |
|
296 | 294 | # set default attributes. |
297 | 295 | 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, |
300 | 298 | 'description': 'project_description', |
301 | 299 | 'enabled': True, |
302 | 300 | } |
@@ -341,14 +339,14 @@ def create_one_endpoint(attrs=None): |
341 | 339 |
|
342 | 340 | # set default attributes. |
343 | 341 | endpoint_info = { |
344 | | - 'service_name': SERVICE_NAME, |
| 342 | + 'service_name': 'service-name-' + uuid.uuid4().hex, |
345 | 343 | 'adminurl': 'http://endpoint_adminurl', |
346 | 344 | 'region': 'endpoint_region', |
347 | 345 | 'internalurl': 'http://endpoint_internalurl', |
348 | 346 | 'service_type': 'service_type', |
349 | 347 | 'id': 'endpoint-id-' + uuid.uuid4().hex, |
350 | 348 | 'publicurl': 'http://endpoint_publicurl', |
351 | | - 'service_id': SERVICE_ID, |
| 349 | + 'service_id': 'service-name-' + uuid.uuid4().hex, |
352 | 350 |
|
353 | 351 | } |
354 | 352 | endpoint_info.update(attrs) |
@@ -392,8 +390,8 @@ def create_one_service(attrs=None): |
392 | 390 |
|
393 | 391 | # set default attributes. |
394 | 392 | service_info = { |
395 | | - 'id': SERVICE_ID, |
396 | | - 'name': SERVICE_NAME, |
| 393 | + 'id': 'service-id-' + uuid.uuid4().hex, |
| 394 | + 'name': 'service-name-' + uuid.uuid4().hex, |
397 | 395 | 'description': 'service_description', |
398 | 396 | 'type': 'service_type', |
399 | 397 |
|
@@ -464,3 +462,49 @@ def create_roles(attrs=None, count=2): |
464 | 462 | roles.append(FakeRole.create_one_role(attrs)) |
465 | 463 |
|
466 | 464 | 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 |
0 commit comments