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)