Skip to content

Commit

Permalink
Implementing Bigtable ColumnFamily.delete().
Browse files Browse the repository at this point in the history
  • Loading branch information
dhermes committed Dec 22, 2015
1 parent 9e2b07d commit 281620d
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
14 changes: 14 additions & 0 deletions gcloud/bigtable/column_family.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

from gcloud._helpers import _total_seconds
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._generated import duration_pb2


Expand Down Expand Up @@ -193,6 +195,10 @@ def to_pb(self):
class ColumnFamily(object):
"""Representation of a Google Cloud Bigtable Column Family.
We can use a :class:`ColumnFamily` to:
* :meth:`delete` itself
:type column_family_id: str
:param column_family_id: The ID of the column family. Must be of the
form ``[_a-zA-Z0-9][-_.a-zA-Z0-9]*``.
Expand Down Expand Up @@ -238,6 +244,14 @@ def __eq__(self, other):
def __ne__(self, other):
return not self.__eq__(other)

def delete(self):
"""Delete this column family."""
request_pb = messages_pb2.DeleteColumnFamilyRequest(name=self.name)
client = self._table._cluster._client
# We expect a `._generated.empty_pb2.Empty`
client._table_stub.DeleteColumnFamily(request_pb,
client.timeout_seconds)


def _gc_rule_from_pb(gc_rule_pb):
"""Convert a protobuf GC rule to a native object.
Expand Down
59 changes: 58 additions & 1 deletion gcloud/bigtable/test_column_family.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,50 @@ def test___ne__(self):
column_family2 = self._makeOne('column_family_id2', None)
self.assertNotEqual(column_family1, column_family2)

def test_delete(self):
from gcloud.bigtable._generated import (
bigtable_table_service_messages_pb2 as messages_pb2)
from gcloud.bigtable._generated import empty_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 = 7
table_name = ('projects/' + project_id + '/zones/' + zone +
'/clusters/' + cluster_id + '/tables/' + table_id)
column_family_name = table_name + '/columnFamilies/' + column_family_id

client = _Client(timeout_seconds=timeout_seconds)
table = _Table(table_name, client=client)
column_family = self._makeOne(column_family_id, table)

# Create request_pb
request_pb = messages_pb2.DeleteColumnFamilyRequest(
name=column_family_name)

# Create response_pb
response_pb = empty_pb2.Empty()

# Patch the stub used by the API method.
client._table_stub = stub = _FakeStub(response_pb)

# Create expected_result.
expected_result = None # delete() has no return value.

# Perform the method and check the result.
self.assertEqual(stub.results, (response_pb,))
result = column_family.delete()
self.assertEqual(stub.results, ())
self.assertEqual(result, expected_result)
self.assertEqual(stub.method_calls, [(
'DeleteColumnFamily',
(request_pb, timeout_seconds),
{},
)])


class Test__gc_rule_from_pb(unittest2.TestCase):

Expand Down Expand Up @@ -471,7 +515,20 @@ def WhichOneof(cls, name):
self.assertEqual(MockProto.names, ['rule'])


class _Cluster(object):

def __init__(self, client=None):
self._client = client


class _Client(object):

def __init__(self, timeout_seconds=None):
self.timeout_seconds = timeout_seconds


class _Table(object):

def __init__(self, name):
def __init__(self, name, client=None):
self.name = name
self._cluster = _Cluster(client)

0 comments on commit 281620d

Please sign in to comment.