Skip to content

Commit

Permalink
fix(spanner): use uuid for unique id [(#4198)](GoogleCloudPlatform/py…
Browse files Browse the repository at this point in the history
…thon-docs-samples#4198)

fixes #4197
(possibly)
  • Loading branch information
Takashi Matsuo authored Jun 29, 2020
1 parent 8cb43c0 commit a54e210
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
12 changes: 4 additions & 8 deletions samples/samples/backup_sample_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import random
import string
import uuid

from google.cloud import spanner
import pytest
Expand All @@ -22,20 +21,17 @@

def unique_instance_id():
""" Creates a unique id for the database. """
return 'test-instance-{}'.format(''.join(random.choice(
string.ascii_lowercase + string.digits) for _ in range(5)))
return f'test-instance-{uuid.uuid4().hex[:10]}'


def unique_database_id():
""" Creates a unique id for the database. """
return 'test-db-{}'.format(''.join(random.choice(
string.ascii_lowercase + string.digits) for _ in range(5)))
return f'test-db-{uuid.uuid4().hex[:10]}'


def unique_backup_id():
""" Creates a unique id for the backup. """
return 'test-backup-{}'.format(''.join(random.choice(
string.ascii_lowercase + string.digits) for _ in range(5)))
return f'test-backup-{uuid.uuid4().hex[:10]}'


INSTANCE_ID = unique_instance_id()
Expand Down
6 changes: 2 additions & 4 deletions samples/samples/snippets_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@
# limitations under the License.

import os
import random
import string
import time
import uuid

from google.cloud import spanner
import pytest
Expand All @@ -25,8 +24,7 @@

def unique_database_id():
""" Creates a unique id for the database. """
return 'test-db-{}'.format(''.join(random.choice(
string.ascii_lowercase + string.digits) for _ in range(5)))
return f'test-db-{uuid.uuid4().hex[:10]}'


INSTANCE_ID = os.environ['SPANNER_INSTANCE']
Expand Down

0 comments on commit a54e210

Please sign in to comment.