Skip to content

Commit

Permalink
[iam] testing: use uniqueId instead of email (#4094)
Browse files Browse the repository at this point in the history
* [iam] bigger entropy for unique id

* [iam] testing: use uniqueId instead of email

fixes #4087

* lint fix
  • Loading branch information
Takashi Matsuo authored Jun 15, 2020
1 parent 2bc61a2 commit 4b91143
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions iam/api-client/service_accounts_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,23 @@

def test_service_accounts(capsys):
project_id = os.environ['GOOGLE_CLOUD_PROJECT']
name = 'python-test-{}'.format(str(uuid.uuid4()).split('-')[0])
email = name + '@' + project_id + '.iam.gserviceaccount.com'
name = f'test-{uuid.uuid4().hex[:25]}'

try:
service_accounts.create_service_account(
acct = service_accounts.create_service_account(
project_id, name, 'Py Test Account')
assert('uniqueId' in acct)

unique_id = acct['uniqueId']
service_accounts.list_service_accounts(project_id)
service_accounts.rename_service_account(
email, 'Updated Py Test Account')
service_accounts.disable_service_account(email)
service_accounts.enable_service_account(email)
service_accounts.delete_service_account(email)
unique_id, 'Updated Py Test Account')
service_accounts.disable_service_account(unique_id)
service_accounts.enable_service_account(unique_id)
service_accounts.delete_service_account(unique_id)
finally:
try:
service_accounts.delete_service_account(email)
service_accounts.delete_service_account(unique_id)
except HttpError as e:
# When the service account doesn't exist, the service returns 403.
if '403' in str(e):
Expand Down

0 comments on commit 4b91143

Please sign in to comment.