Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions iam/api-client/custom_roles_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

GCLOUD_PROJECT = os.environ["GCLOUD_PROJECT"]

CUSTOM_ROLE_NAME = "pythonTestCustomRole" + str(uuid.uuid1().int)
CUSTOM_ROLE_NAME = "pythonTestCustomRole"
CUSTOM_ROLE_TITLE = "Python Test Custom Role"
CUSTOM_ROLE_DESCRIPTION = "This is a python test custom role"
CUSTOM_ROLE_PERMISSIONS = ["iam.roles.get"]
Expand All @@ -33,22 +33,23 @@

@pytest.fixture(scope="module")
def test_custom_role():
# section to create custom role to test policy updates.
custom_roles.create_role(
CUSTOM_ROLE_NAME,
GCLOUD_PROJECT,
CUSTOM_ROLE_TITLE,
CUSTOM_ROLE_DESCRIPTION,
CUSTOM_ROLE_PERMISSIONS,
CUSTOM_ROLE_STAGE,
)
yield CUSTOM_ROLE_NAME

# Delete the custom role
# This custom role is reused in read/update tests.
try:
custom_roles.delete_role(CUSTOM_ROLE_NAME, GCLOUD_PROJECT)
except googleapiclient.errors.HttpError:
print("Custom role already deleted.")
custom_roles.create_role(
CUSTOM_ROLE_NAME,
GCLOUD_PROJECT,
CUSTOM_ROLE_TITLE,
CUSTOM_ROLE_DESCRIPTION,
CUSTOM_ROLE_PERMISSIONS,
CUSTOM_ROLE_STAGE,
)
except googleapiclient.errors.HttpError as e:
if "HttpError 409" not in str(e):
raise e
# Ignore error since we just reuse the same custom role.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make sure that we are ignoring the right error? Perhaps verify the message is correct and the snippet isn't failing for another reason?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! I'll make a change

print('Re-using the custom role "{}".'.format(CUSTOM_ROLE_NAME))
yield CUSTOM_ROLE_NAME
# we don't delete this custom role for future tests.


@pytest.fixture(scope="function")
Expand Down