Skip to content

Commit 42fc722

Browse files
committed
Merge pull request #1525 from dhermes/bigtable-sys-test-tables
Adding system tests for Bigtable Table API.
2 parents 932f346 + e2016e2 commit 42fc722

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

system_tests/bigtable.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import operator
1516
import time
1617

1718
import unittest2
@@ -25,6 +26,7 @@
2526
CENTRAL_1C_ZONE = 'us-central1-c'
2627
NOW_MILLIS = int(1000 * time.time())
2728
CLUSTER_ID = 'gcloud-python-%d' % (NOW_MILLIS,)
29+
TABLE_ID = 'gcloud-python-test-table'
2830
EXISTING_CLUSTERS = []
2931
EXPECTED_ZONES = (
3032
'asia-east1-b',
@@ -163,3 +165,65 @@ def test_update(self):
163165

164166
# We want to make sure the operation completes.
165167
self.assertTrue(_operation_wait(operation))
168+
169+
170+
class TestTableAdminAPI(unittest2.TestCase):
171+
172+
@classmethod
173+
def setUpClass(cls):
174+
cls._table = Config.CLUSTER.table(TABLE_ID)
175+
cls._table.create()
176+
177+
@classmethod
178+
def tearDownClass(cls):
179+
cls._table.delete()
180+
181+
def setUp(self):
182+
self.tables_to_delete = []
183+
184+
def tearDown(self):
185+
for table in self.tables_to_delete:
186+
table.delete()
187+
188+
def test_list_tables(self):
189+
# Since `Config.CLUSTER` is newly created in `setUpModule`, the table
190+
# created in `setUpClass` here will be the only one.
191+
tables = Config.CLUSTER.list_tables()
192+
self.assertEqual(tables, [self._table])
193+
194+
def test_create_table(self):
195+
temp_table_id = 'foo-bar-baz-table'
196+
temp_table = Config.CLUSTER.table(temp_table_id)
197+
temp_table.create()
198+
self.tables_to_delete.append(temp_table)
199+
200+
# First, create a sorted version of our expected result.
201+
name_attr = operator.attrgetter('name')
202+
expected_tables = sorted([temp_table, self._table], key=name_attr)
203+
204+
# Then query for the tables in the cluster and sort them by
205+
# name as well.
206+
tables = Config.CLUSTER.list_tables()
207+
sorted_tables = sorted(tables, key=name_attr)
208+
self.assertEqual(sorted_tables, expected_tables)
209+
210+
def test_rename_table(self):
211+
# pylint: disable=no-name-in-module
212+
from grpc.beta import interfaces
213+
from grpc.framework.interfaces.face import face
214+
# pylint: enable=no-name-in-module
215+
216+
temp_table_id = 'foo-bar-baz-table'
217+
temp_table = Config.CLUSTER.table(temp_table_id)
218+
temp_table.create()
219+
self.tables_to_delete.append(temp_table)
220+
221+
with self.assertRaises(face.LocalError) as exc_manager:
222+
temp_table.rename(temp_table_id + '-alt')
223+
exc_caught = exc_manager.exception
224+
self.assertNotEqual(exc_caught, None)
225+
self.assertEqual(exc_caught.code,
226+
interfaces.StatusCode.UNIMPLEMENTED)
227+
self.assertEqual(
228+
exc_caught.details,
229+
'BigtableTableService.RenameTable is not yet implemented')

0 commit comments

Comments
 (0)