|
22 | 22 |
|
23 | 23 | def test_service_accounts(capsys):
|
24 | 24 | project_id = os.environ['GOOGLE_CLOUD_PROJECT']
|
25 |
| - name = 'python-test-{}'.format(str(uuid.uuid4()).split('-')[0]) |
26 |
| - email = name + '@' + project_id + '.iam.gserviceaccount.com' |
| 25 | + name = f'test-{uuid.uuid4().hex[:25]}' |
27 | 26 |
|
28 | 27 | try:
|
29 |
| - service_accounts.create_service_account( |
| 28 | + acct = service_accounts.create_service_account( |
30 | 29 | project_id, name, 'Py Test Account')
|
| 30 | + assert('uniqueId' in acct) |
| 31 | + |
| 32 | + unique_id = acct['uniqueId'] |
31 | 33 | service_accounts.list_service_accounts(project_id)
|
32 | 34 | service_accounts.rename_service_account(
|
33 |
| - email, 'Updated Py Test Account') |
34 |
| - service_accounts.disable_service_account(email) |
35 |
| - service_accounts.enable_service_account(email) |
36 |
| - service_accounts.delete_service_account(email) |
| 35 | + unique_id, 'Updated Py Test Account') |
| 36 | + service_accounts.disable_service_account(unique_id) |
| 37 | + service_accounts.enable_service_account(unique_id) |
| 38 | + service_accounts.delete_service_account(unique_id) |
37 | 39 | finally:
|
38 | 40 | try:
|
39 |
| - service_accounts.delete_service_account(email) |
| 41 | + service_accounts.delete_service_account(unique_id) |
40 | 42 | except HttpError as e:
|
41 | 43 | # When the service account doesn't exist, the service returns 403.
|
42 | 44 | if '403' in str(e):
|
|
0 commit comments