Skip to content

Commit adeec1d

Browse files
Cleanup bigtable python examples [(#2692)](GoogleCloudPlatform/python-docs-samples#2692)
* Cleanup bigtable python: Use new row types for mutations Update bigtable version in requirements Delete table after tests * Change bigtable cluster variable to bigtable instance for consistency Create and delete quickstart table during test * Fixing step size for metric scaler Create unique tables for quickstart tests * Creating fixtures for quickstart tests Fixing hb quickstart test output * Fix quickstart extra delete table Update happybase to use direct row * Use clearer instance names for tests Create unique instances for metric scaler tests * Linting * remove core dep Co-authored-by: Leah E. Cole <[email protected]>
1 parent 89bb033 commit adeec1d

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

samples/quickstart/main_test.py

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

1515
import os
16+
import random
17+
import pytest
1618

1719
from main import main
20+
from google.cloud import bigtable
1821

1922
PROJECT = os.environ['GCLOUD_PROJECT']
20-
BIGTABLE_CLUSTER = os.environ['BIGTABLE_CLUSTER']
21-
TABLE_NAME = 'my-table'
23+
BIGTABLE_INSTANCE = os.environ['BIGTABLE_INSTANCE']
24+
TABLE_ID_FORMAT = 'quickstart-test-{}'
25+
TABLE_ID_RANGE = 10000
2226

2327

24-
def test_main(capsys):
25-
main(PROJECT, BIGTABLE_CLUSTER, TABLE_NAME)
28+
@pytest.fixture()
29+
def table():
30+
table_id = TABLE_ID_FORMAT.format(
31+
random.randrange(TABLE_ID_RANGE))
32+
client = bigtable.Client(project=PROJECT, admin=True)
33+
instance = client.instance(BIGTABLE_INSTANCE)
34+
table = instance.table(table_id)
35+
column_family_id = 'cf1'
36+
column_families = {column_family_id: None}
37+
table.create(column_families=column_families)
38+
39+
row = table.direct_row("r1")
40+
row.set_cell(column_family_id, "c1", "test-value")
41+
row.commit()
42+
43+
yield table_id
44+
45+
table.delete()
46+
47+
48+
def test_main(capsys, table):
49+
table_id = table
50+
main(PROJECT, BIGTABLE_INSTANCE, table_id)
2651

2752
out, _ = capsys.readouterr()
2853
assert 'Row key: r1\nData: test-value\n' in out

samples/quickstart/requirements.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
google-cloud-bigtable==1.0.0
2-
google-cloud-core==1.0.3
1+
google-cloud-bigtable==1.2.1

0 commit comments

Comments
 (0)