Skip to content

Commit 9fb1745

Browse files
samples: update tests to use uuid for bigtable table ids (#304)
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly: - [ ] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/python-bigtable/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [ ] Ensure the tests and linter pass - [ ] Code coverage does not decrease (if any source code was changed) - [ ] Appropriate docs were updated (if necessary) Fixes #195 🦕
1 parent 176ea7e commit 9fb1745

File tree

3 files changed

+16
-23
lines changed

3 files changed

+16
-23
lines changed

packages/google-cloud-bigtable/samples/quickstart/main_test.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515
import os
16-
import random
16+
import uuid
1717

1818
from google.cloud import bigtable
1919
import pytest
@@ -24,13 +24,11 @@
2424
PROJECT = os.environ['GOOGLE_CLOUD_PROJECT']
2525
BIGTABLE_INSTANCE = os.environ['BIGTABLE_INSTANCE']
2626
TABLE_ID_FORMAT = 'quickstart-test-{}'
27-
TABLE_ID_RANGE = 10000
2827

2928

3029
@pytest.fixture()
3130
def table():
32-
table_id = TABLE_ID_FORMAT.format(
33-
random.randrange(TABLE_ID_RANGE))
31+
table_id = TABLE_ID_FORMAT.format(uuid.uuid4().hex[:8])
3432
client = bigtable.Client(project=PROJECT, admin=True)
3533
instance = client.instance(BIGTABLE_INSTANCE)
3634
table = instance.table(table_id)

packages/google-cloud-bigtable/samples/quickstart_happybase/main_test.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515
import os
16-
import random
16+
import uuid
1717

1818
from google.cloud import bigtable
1919
import pytest
@@ -24,13 +24,11 @@
2424
PROJECT = os.environ['GOOGLE_CLOUD_PROJECT']
2525
BIGTABLE_INSTANCE = os.environ['BIGTABLE_INSTANCE']
2626
TABLE_ID_FORMAT = 'quickstart-hb-test-{}'
27-
TABLE_ID_RANGE = 10000
2827

2928

3029
@pytest.fixture()
3130
def table():
32-
table_id = TABLE_ID_FORMAT.format(
33-
random.randrange(TABLE_ID_RANGE))
31+
table_id = TABLE_ID_FORMAT.format(uuid.uuid4().hex[:8])
3432
client = bigtable.Client(project=PROJECT, admin=True)
3533
instance = client.instance(BIGTABLE_INSTANCE)
3634
table = instance.table(table_id)

packages/google-cloud-bigtable/samples/tableadmin/tableadmin_test.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,24 @@
1414
# limitations under the License.
1515

1616
import os
17-
import random
17+
import uuid
1818

1919
from tableadmin import create_table
2020
from tableadmin import delete_table
2121
from tableadmin import run_table_operations
2222

2323
PROJECT = os.environ['GOOGLE_CLOUD_PROJECT']
2424
BIGTABLE_INSTANCE = os.environ['BIGTABLE_INSTANCE']
25-
TABLE_NAME_FORMAT = 'tableadmin-test-{}'
26-
TABLE_NAME_RANGE = 10000
25+
TABLE_ID_FORMAT = 'tableadmin-test-{}'
2726

2827

2928
def test_run_table_operations(capsys):
30-
table_name = TABLE_NAME_FORMAT.format(
31-
random.randrange(TABLE_NAME_RANGE))
29+
table_id = TABLE_ID_FORMAT.format(uuid.uuid4().hex[:8])
3230

33-
run_table_operations(PROJECT, BIGTABLE_INSTANCE, table_name)
31+
run_table_operations(PROJECT, BIGTABLE_INSTANCE, table_id)
3432
out, _ = capsys.readouterr()
3533

36-
assert 'Creating the ' + table_name + ' table.' in out
34+
assert 'Creating the ' + table_id + ' table.' in out
3735
assert 'Listing tables in current project.' in out
3836
assert 'Creating column family cf1 with with MaxAge GC Rule' in out
3937
assert 'Created column family cf1 with MaxAge GC Rule.' in out
@@ -50,17 +48,16 @@ def test_run_table_operations(capsys):
5048
assert 'Delete a column family cf2...' in out
5149
assert 'Column family cf2 deleted successfully.' in out
5250

53-
delete_table(PROJECT, BIGTABLE_INSTANCE, table_name)
51+
delete_table(PROJECT, BIGTABLE_INSTANCE, table_id)
5452

5553

5654
def test_delete_table(capsys):
57-
table_name = TABLE_NAME_FORMAT.format(
58-
random.randrange(TABLE_NAME_RANGE))
59-
create_table(PROJECT, BIGTABLE_INSTANCE, table_name)
55+
table_id = TABLE_ID_FORMAT.format(uuid.uuid4().hex[:8])
56+
create_table(PROJECT, BIGTABLE_INSTANCE, table_id)
6057

61-
delete_table(PROJECT, BIGTABLE_INSTANCE, table_name)
58+
delete_table(PROJECT, BIGTABLE_INSTANCE, table_id)
6259
out, _ = capsys.readouterr()
6360

64-
assert 'Table ' + table_name + ' exists.' in out
65-
assert 'Deleting ' + table_name + ' table.' in out
66-
assert 'Deleted ' + table_name + ' table.' in out
61+
assert 'Table ' + table_id + ' exists.' in out
62+
assert 'Deleting ' + table_id + ' table.' in out
63+
assert 'Deleted ' + table_id + ' table.' in out

0 commit comments

Comments
 (0)