Skip to content

Commit

Permalink
Implementing HappyBase Connection.delete_table().
Browse files Browse the repository at this point in the history
  • Loading branch information
dhermes committed Sep 5, 2015
1 parent ff3738d commit 7249de5
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 8 deletions.
18 changes: 13 additions & 5 deletions gcloud_bigtable/happybase/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

from gcloud_bigtable.client import Client
from gcloud_bigtable.happybase.table import Table
from gcloud_bigtable.table import Table as _LowLevelTable


# Constants reproduced here for compatibility, though values are
Expand Down Expand Up @@ -281,18 +282,25 @@ def delete_table(self, name, disable=False):
"""Delete the specified table.
:type name: str
:param name: The name of the table to be deleted.
:param name: The name of the table to be deleted. If ``table_prefix``
is set, a prefix will be added to the ``name``.
:type disable: bool
:param disable: Whether to first disable the table if needed. This
is provided for compatibility with happybase, but is
is provided for compatibility with HappyBase, but is
not relevant for Cloud Bigtable since it has no concept
of enabled / disabled tables.
:raises: :class:`NotImplementedError <exceptions.NotImplementedError>`
temporarily until the method is implemented.
:raises: :class:`ValueError <exceptions.ValueError>`
if ``disable=True``.
"""
raise NotImplementedError('Temporarily not implemented.')
if disable:
raise ValueError('The disable argument should not be used in '
'delete_table(). Cloud Bigtable has no concept '
'of enabled / disabled tables.')

name = self._table_name(name)
_LowLevelTable(name, self._cluster).delete()

def enable_table(self, name):
"""Enable the specified table.
Expand Down
34 changes: 31 additions & 3 deletions gcloud_bigtable/happybase/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,13 +306,41 @@ def test_create_table(self):
connection.create_table(name, families)

def test_delete_table(self):
from gcloud_bigtable._testing import _Monkey
from gcloud_bigtable.happybase import connection as MUT

cluster = _Cluster() # Avoid implicit environ check.
connection = self._makeOne(autoconnect=False, cluster=cluster)

class MockLowLevelTable(object):

_instances = []

def __init__(self, *args, **kwargs):
self._instances.append(self)
self.args = args
self.kwargs = kwargs
self.delete_calls = 0

def delete(self):
self.delete_calls += 1

name = 'table-name'
disable = True
with self.assertRaises(NotImplementedError):
connection.delete_table(name, disable=disable)
with _Monkey(MUT, _LowLevelTable=MockLowLevelTable):
connection.delete_table(name)

# Just one table would have been created.
table_instance, = MockLowLevelTable._instances
self.assertEqual(table_instance.args, ('table-name', cluster))
self.assertEqual(table_instance.kwargs, {})
self.assertEqual(table_instance.delete_calls, 1)

def test_delete_table_disable(self):
cluster = _Cluster() # Avoid implicit environ check.
connection = self._makeOne(autoconnect=False, cluster=cluster)
name = 'table-name'
with self.assertRaises(ValueError):
connection.delete_table(name, disable=True)

def test_enable_table(self):
cluster = _Cluster() # Avoid implicit environ check.
Expand Down

0 comments on commit 7249de5

Please sign in to comment.