8000 Making bigtable tests run successfully (#1764) · di/python-docs-samples@8122224 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8122224

Browse files
authored
Making bigtable tests run successfully (GoogleCloudPlatform#1764)
* Making bigtable tests run successfully * Fixed missing import * Renamed noxfile for new environment * Moving the nox name back
1 parent 8d79fd1 commit 8122224

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

bigtable/hello/main.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def main(project_id, instance_id, table_id):
5959
print('Writing some greetings to the table.')
6060
greetings = ['Hello World!', 'Hello Cloud Bigtable!', 'Hello Python!']
6161
rows = []
62-
column = 'greeting'
62+
column = 'greeting'.encode()
6363
for i, value in enumerate(greetings):
6464
# Note: This example uses sequential numeric IDs for simplicity,
6565
# but this can result in poor performance in a production
@@ -71,7 +71,7 @@ def main(project_id, instance_id, table_id):
7171
# the best performance, see the documentation:
7272
#
7373
# https://cloud.google.com/bigtable/docs/schema-design
74-
row_key = 'greeting{}'.format(i)
74+
row_key = 'greeting{}'.format(i).encode()
7575
row = table.row(row_key)
7676
row.set_cell(column_family_id,
7777
column,
@@ -83,7 +83,7 @@ def main(project_id, instance_id, table_id):
8383

8484
# [START getting_a_row]
8585
print('Getting a single greeting by row key.')
86-
key = 'greeting0'
86+
key = 'greeting0'.encode()
8787

8888
# Only retrieve the most recent version of the cell.
8989
row_filter = row_filters.CellsColumnLimitFilter(1)

bigtable/tableadmin/tableadmin.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
from google.cloud.bigtable import column_family
3838

3939

40-
def run_table_operations(project_id, instance_id, table_id):
41-
''' Create a Bigtable table and perform basic table operations
40+
def create_table(project_id, instance_id, table_id):
41+
''' Create a Bigtable table
4242
4343
:type project_id: str
4444
:param project_id: Project id of the client.
@@ -64,6 +64,24 @@ def run_table_operations(project_id, instance_id, table_id):
6464
table.create()
6565
print('Created table {}.'.format(table_id))
6666

67+
return client, instance, table
68+
69+
70+
def run_table_operations(project_id, instance_id, table_id):
71+
''' 8000 Create a Bigtable table and perform basic operations on it
72+
73+
:type project_id: str
74+
:param project_id: Project id of the client.
75+
76+
:type instance_id: str
77+
:param instance_id: Instance of the client.
78+
79+
:type table_id: str
80+
:param table_id: Table id to create table.
81+
'''
82+
83+
client, instance, table = create_table(project_id, instance_id, table_id)
84+
6785
# [START bigtable_list_tables]
6886
tables = instance.list_tables()
6987
print('Listing tables in current project...')

bigtable/tableadmin/tableadmin_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import os
1717
import random
1818

19+
from tableadmin import create_table
1920
from tableadmin import delete_table
2021
from tableadmin import run_table_operations
2122

@@ -53,6 +54,7 @@ def test_run_table_operations(capsys):
5354
def test_delete_table(capsys):
5455
table_name = TABLE_NAME_FORMAT.format(
5556
random.randrange(TABLE_NAME_RANGE))
57+
create_table(PROJECT, BIGTABLE_CLUSTER, table_name)
5658

5759
delete_table(PROJECT, BIGTABLE_CLUSTER, table_name)
5860
out, _ = capsys.readouterr()

0 commit comments

Comments
 (0)
0