Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementing Bigtable ColumnFamily.delete(). #1323

Merged
merged 1 commit into from
Dec 23, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()

This comment was marked as spam.

This comment was marked as spam.


# 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)