1515
1616import time
1717from os import environ
18+ import uuid
1819
1920from google .api_core .exceptions import Aborted , GoogleAPICallError
2021from google .cloud import kms_v1
@@ -63,7 +64,7 @@ def setup_module(module):
6364
6465class TestKMSSnippets :
6566 project_id = environ ['GCLOUD_PROJECT' ]
66- keyring_id = 'kms-samples'
67+ keyring_id = 'kms-samples-{}' . format ( uuid . uuid4 (). hex )
6768 location = 'global'
6869 parent = 'projects/{}/locations/{}' .format (project_id , location )
6970 keyring_path = '{}/keyRings/{}' .format (parent , keyring_id )
@@ -83,7 +84,7 @@ class TestKMSSnippets:
8384 @pytest .mark .skip (reason = "There's currently no method to delete keyrings, \
8485 so we should avoid creating resources" )
8586 def test_create_key_ring (self ):
86- ring_id = self .keyring_id + '-testcreate' + str ( int ( time . time ()) )
87+ ring_id = self .keyring_id + '-test-create-{}' . format ( uuid . uuid4 (). hex )
8788 snippets .create_key_ring (self .project_id , self .location , ring_id )
8889 client = kms_v1 .KeyManagementServiceClient ()
8990 result = client .get_key_ring (client .key_ring_path (self .project_id ,
@@ -94,7 +95,7 @@ def test_create_key_ring(self):
9495 @pytest .mark .skip (reason = "Deleting keys isn't instant, so we should avoid \
9596 creating a large number of them in our tests" )
9697 def test_create_crypto_key (self ):
97- key_id = self .sym_id + '-test' + str ( int ( time . time ()) )
98+ key_id = self .sym_id + '-test-{}' . format ( uuid . uuid4 (). hex )
9899 snippets .create_crypto_key (self .project_id , self .location ,
99100 self .keyring_id , key_id )
100101 c = kms_v1 .KeyManagementServiceClient ()
0 commit comments