Skip to content

Commit

Permalink
Fixing up mock _Client constructors.
Browse files Browse the repository at this point in the history
  • Loading branch information
dhermes committed Sep 5, 2015
1 parent 0e97263 commit ff3738d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
24 changes: 13 additions & 11 deletions gcloud_bigtable/happybase/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def _helper(self, timeout=None, clusters=(), failed_zones=()):
# there is exactly one cluster.
cluster, = clusters
self.assertEqual(result, cluster)
client = cluster._client
client = cluster.client
self.assertEqual(client.args, ())
expected_kwargs = {'admin': True}
if timeout is not None:
Expand Down Expand Up @@ -118,7 +118,7 @@ def test_constructor_explicit(self):
table_prefix = 'table-prefix'
table_prefix_separator = 'sep'
cluster_copy = _Cluster()
cluster = _Cluster(cluster_copy)
cluster = _Cluster(copies=[cluster_copy])

connection = self._makeOne(
autoconnect=False, timeout=timeout,
Expand Down Expand Up @@ -266,28 +266,30 @@ def test_table_factory_with_ignored_prefix(self):
def test_tables(self):
from gcloud_bigtable.table import Table

cluster = _Cluster() # Avoid implicit environ check.
table_name1 = 'table-name1'
table_name2 = 'table-name2'
cluster.list_tables_result = [Table(table_name1, None),
Table(table_name2, None)]
cluster = _Cluster(list_tables_result=[
Table(table_name1, None),
Table(table_name2, None),
])
connection = self._makeOne(autoconnect=False, cluster=cluster)
result = connection.tables()
self.assertEqual(result, [table_name1, table_name2])

def test_tables_with_prefix(self):
from gcloud_bigtable.table import Table

cluster = _Cluster() # Avoid implicit environ check.
table_prefix = 'prefix'
table_prefix_separator = '<>'
unprefixed_table_name1 = 'table-name1'

table_name1 = (table_prefix + table_prefix_separator +
unprefixed_table_name1)
table_name2 = 'table-name2'
cluster.list_tables_result = [Table(table_name1, None),
Table(table_name2, None)]
cluster = _Cluster(list_tables_result=[
Table(table_name1, None),
Table(table_name2, None),
])
connection = self._makeOne(
autoconnect=False, cluster=cluster, table_prefix=table_prefix,
table_prefix_separator=table_prefix_separator)
Expand Down Expand Up @@ -351,7 +353,7 @@ class _Client(object):
def __init__(self, *args, **kwargs):
self.clusters = kwargs.pop('clusters', [])
for cluster in self.clusters:
cluster._client = self
cluster.client = self
self.failed_zones = kwargs.pop('failed_zones', [])
self.args = args
self.kwargs = kwargs
Expand All @@ -370,11 +372,11 @@ def list_clusters(self):

class _Cluster(object):

def __init__(self, *copies):
def __init__(self, copies=(), list_tables_result=()):
self.copies = list(copies)
# Included to support Connection.__del__
self.client = _Client()
self.list_tables_result = []
self.list_tables_result = list_tables_result

def copy(self):
if self.copies:
Expand Down
9 changes: 5 additions & 4 deletions gcloud_bigtable/happybase/test_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_constructor_defaults(self):
size = 11
cluster_copy = _Cluster()
all_copies = [cluster_copy] * size
cluster = _Cluster(*all_copies) # Avoid implicit environ check.
cluster = _Cluster(copies=all_copies) # Avoid implicit environ check.
pool = self._makeOne(size, cluster=cluster)

self.assertTrue(isinstance(pool._lock, type(threading.Lock())))
Expand Down Expand Up @@ -80,7 +80,8 @@ def open(self):
cluster_copy1 = _Cluster()
cluster_copy2 = _Cluster()
cluster_copy3 = _Cluster()
cluster = _Cluster(cluster_copy1, cluster_copy2, cluster_copy3)
cluster = _Cluster(
copies=[cluster_copy1, cluster_copy2, cluster_copy3])
connection = ConnectionWithOpen(autoconnect=False, cluster=cluster)
self.assertFalse(connection._open_called)
self.assertTrue(connection._cluster is cluster_copy1)
Expand All @@ -107,7 +108,7 @@ def test_constructor_infers_cluster(self):
size = 1
cluster_copy = _Cluster()
all_copies = [cluster_copy] * size
cluster = _Cluster(*all_copies)
cluster = _Cluster(copies=all_copies)

timeout = object()
mock_get_cluster = _MockCalled(cluster)
Expand Down Expand Up @@ -155,7 +156,7 @@ def stop(self):

class _Cluster(object):

def __init__(self, *copies):
def __init__(self, copies=()):
self.copies = list(copies)
# Included to support Connection.__del__
self.client = _Client()
Expand Down

0 comments on commit ff3738d

Please sign in to comment.