def _list_tables_helper(self, table_id, table_name=None): from gcloud.bigtable._generated import ( bigtable_table_data_pb2 as table_data_pb2) from gcloud.bigtable._generated import ( bigtable_table_service_messages_pb2 as table_messages_pb2) from gcloud.bigtable._testing import _FakeStub project = 'PROJECT' zone = 'zone' cluster_id = 'cluster-id' timeout_seconds = 45 client = _Client(project, timeout_seconds=timeout_seconds) cluster = self._makeOne(zone, cluster_id, client) # Create request_ cluster_name = ('projects/' + project + '/zones/' + zone + '/clusters/' + cluster_id) request_pb = table_messages_pb2.ListTablesRequest(name=cluster_name) # Create response_pb table_name = table_name or (cluster_name + '/tables/' + table_id) response_pb = table_messages_pb2.ListTablesResponse( tables=[ table_data_pb2.Table(name=table_name), ], ) # Patch the stub used by the API method. client._table_stub = stub = _FakeStub(response_pb) # Create expected_result. expected_table = cluster.table(table_id) expected_result = [expected_table] # Perform the method and check the result. result = cluster.list_tables() self.assertEqual(result, expected_result) self.assertEqual(stub.method_calls, [( 'ListTables', (request_pb, timeout_seconds), {}, )])
def list_tables(self): """List the tables in this cluster. :rtype: list of :class:`Table <gcloud.bigtable.table.Table>` :returns: The list of tables owned by the cluster. :raises: :class:`ValueError <exceptions.ValueError>` if one of the returned tables has a name that is not of the expected format. """ request_pb = table_messages_pb2.ListTablesRequest(name=self.name) # We expect a `table_messages_pb2.ListTablesResponse` table_list_pb = self._client._table_stub.ListTables( request_pb, self._client.timeout_seconds) result = [] for table_pb in table_list_pb.tables: table_prefix = self.name + '/tables/' if not table_pb.name.startswith(table_prefix): raise ValueError('Table name %s not of expected format' % (table_pb.name, )) table_id = table_pb.name[len(table_prefix):] result.append(self.table(table_id)) return result