def _create_test_helper(self, gc_rule=None): from gcloud.bigtable._generated import (bigtable_table_data_pb2 as data_pb2) from gcloud.bigtable._generated import ( bigtable_table_service_messages_pb2 as messages_pb2) from gcloud.bigtable._testing import _FakeStub project_id = 'project-id' zone = 'zone' cluster_id = 'cluster-id' table_id = 'table-id' column_family_id = 'column-family-id' timeout_seconds = 4 table_name = ('projects/' + project_id + '/zones/' + zone + '/clusters/' + cluster_id + '/tables/' + table_id) client = _Client(timeout_seconds=timeout_seconds) table = _Table(table_name, client=client) column_family = self._makeOne(column_family_id, table, gc_rule=gc_rule) # Create request_pb if gc_rule is None: column_family_pb = data_pb2.ColumnFamily() else: column_family_pb = data_pb2.ColumnFamily(gc_rule=gc_rule.to_pb()) request_pb = messages_pb2.CreateColumnFamilyRequest( name=table_name, column_family_id=column_family_id, column_family=column_family_pb, ) # Create response_pb response_pb = data_pb2.ColumnFamily() # Patch the stub used by the API method. client._table_stub = stub = _FakeStub(response_pb) # Create expected_result. expected_result = None # create() has no return value. # Perform the method and check the result. self.assertEqual(stub.results, (response_pb, )) result = column_family.create() self.assertEqual(stub.results, ()) self.assertEqual(result, expected_result) self.assertEqual(stub.method_calls, [( 'CreateColumnFamily', (request_pb, timeout_seconds), {}, )])
def create(self): """Create this column family.""" if self.gc_rule is None: column_family = data_pb2.ColumnFamily() else: column_family = data_pb2.ColumnFamily(gc_rule=self.gc_rule.to_pb()) request_pb = messages_pb2.CreateColumnFamilyRequest( name=self._table.name, column_family_id=self.column_family_id, column_family=column_family, ) client = self._table._cluster._client # We expect a `.data_pb2.ColumnFamily`. We ignore it since the only # data it contains are the GC rule and the column family ID already # stored on this instance. client._table_stub.CreateColumnFamily(request_pb, client.timeout_seconds)
def _list_column_families_helper(self, column_family_name=None): from gcloud.bigtable._generated import ( bigtable_table_data_pb2 as data_pb2) from gcloud.bigtable._generated import ( bigtable_table_service_messages_pb2 as messages_pb2) from gcloud.bigtable._testing import _FakeStub project_id = 'project-id' zone = 'zone' cluster_id = 'cluster-id' table_id = 'table-id' timeout_seconds = 502 cluster_name = ('projects/' + project_id + '/zones/' + zone + '/clusters/' + cluster_id) client = _Client(timeout_seconds=timeout_seconds) cluster = _Cluster(cluster_name, client=client) table = self._makeOne(table_id, cluster) # Create request_pb table_name = cluster_name + '/tables/' + table_id request_pb = messages_pb2.GetTableRequest(name=table_name) # Create response_pb column_family_id = 'foo' if column_family_name is None: column_family_name = (table_name + '/columnFamilies/' + column_family_id) column_family = data_pb2.ColumnFamily(name=column_family_name) response_pb = data_pb2.Table( column_families={column_family_id: column_family}, ) # Patch the stub used by the API method. client._table_stub = stub = _FakeStub(response_pb) # Create expected_result. expected_result = { column_family_id: table.column_family(column_family_id), } # Perform the method and check the result. result = table.list_column_families() self.assertEqual(result, expected_result) self.assertEqual(stub.method_calls, [( 'GetTable', (request_pb, timeout_seconds), {}, )])
def update(self): """Update this column family. .. note:: Only the GC rule can be updated. By changing the column family ID, you will simply be referring to a different column family. """ request_kwargs = {'name': self.name} if self.gc_rule is not None: request_kwargs['gc_rule'] = self.gc_rule.to_pb() request_pb = data_pb2.ColumnFamily(**request_kwargs) client = self._table._cluster._client # We expect a `.data_pb2.ColumnFamily`. We ignore it since the only # data it contains are the GC rule and the column family ID already # stored on this instance. client._table_stub.UpdateColumnFamily(request_pb, client.timeout_seconds)