|
12 | 12 | # See the License for the specific language governing permissions and |
13 | 13 | # limitations under the License. |
14 | 14 |
|
| 15 | +import operator |
15 | 16 | import time |
16 | 17 |
|
17 | 18 | import unittest2 |
|
25 | 26 | CENTRAL_1C_ZONE = 'us-central1-c' |
26 | 27 | NOW_MILLIS = int(1000 * time.time()) |
27 | 28 | CLUSTER_ID = 'gcloud-python-%d' % (NOW_MILLIS,) |
| 29 | +TABLE_ID = 'gcloud-python-test-table' |
28 | 30 | EXISTING_CLUSTERS = [] |
29 | 31 | EXPECTED_ZONES = ( |
30 | 32 | 'asia-east1-b', |
@@ -163,3 +165,65 @@ def test_update(self): |
163 | 165 |
|
164 | 166 | # We want to make sure the operation completes. |
165 | 167 | 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