|
21 | 21 |
|
22 | 22 | GCLOUD_PROJECT = os.environ["GCLOUD_PROJECT"]
|
23 | 23 |
|
24 |
| -CUSTOM_ROLE_NAME = "pythonTestCustomRole" + str(uuid.uuid1().int) |
| 24 | +CUSTOM_ROLE_NAME = "pythonTestCustomRole" |
25 | 25 | CUSTOM_ROLE_TITLE = "Python Test Custom Role"
|
26 | 26 | CUSTOM_ROLE_DESCRIPTION = "This is a python test custom role"
|
27 | 27 | CUSTOM_ROLE_PERMISSIONS = ["iam.roles.get"]
|
|
33 | 33 |
|
34 | 34 | @pytest.fixture(scope="module")
|
35 | 35 | def test_custom_role():
|
36 |
| - # section to create custom role to test policy updates. |
37 |
| - custom_roles.create_role( |
38 |
| - CUSTOM_ROLE_NAME, |
39 |
| - GCLOUD_PROJECT, |
40 |
| - CUSTOM_ROLE_TITLE, |
41 |
| - CUSTOM_ROLE_DESCRIPTION, |
42 |
| - CUSTOM_ROLE_PERMISSIONS, |
43 |
| - CUSTOM_ROLE_STAGE, |
44 |
| - ) |
45 |
| - yield CUSTOM_ROLE_NAME |
46 |
| - |
47 |
| - # Delete the custom role |
| 36 | + # This custom role is reused in read/update tests. |
48 | 37 | try:
|
49 |
| - custom_roles.delete_role(CUSTOM_ROLE_NAME, GCLOUD_PROJECT) |
50 |
| - except googleapiclient.errors.HttpError: |
51 |
| - print("Custom role already deleted.") |
| 38 | + custom_roles.create_role( |
| 39 | + CUSTOM_ROLE_NAME, |
| 40 | + GCLOUD_PROJECT, |
| 41 | + CUSTOM_ROLE_TITLE, |
| 42 | + CUSTOM_ROLE_DESCRIPTION, |
| 43 | + CUSTOM_ROLE_PERMISSIONS, |
| 44 | + CUSTOM_ROLE_STAGE, |
| 45 | + ) |
| 46 | + except googleapiclient.errors.HttpError as e: |
| 47 | + if "HttpError 409" not in str(e): |
| 48 | + raise e |
| 49 | + # Ignore error since we just reuse the same custom role. |
| 50 | + print('Re-using the custom role "{}".'.format(CUSTOM_ROLE_NAME)) |
| 51 | + yield CUSTOM_ROLE_NAME |
| 52 | + # we don't delete this custom role for future tests. |
52 | 53 |
|
53 | 54 |
|
54 | 55 | @pytest.fixture(scope="function")
|
|
0 commit comments