Skip to content

Commit 614be5e

Browse files
committed
Requiring that prefixes are strings in HappyBase.
1 parent 3f18953 commit 614be5e

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

gcloud/bigtable/happybase/connection.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
"""Google Cloud Bigtable HappyBase connection module."""
1616

1717

18+
import six
19+
20+
1821
# Constants reproduced here for HappyBase compatibility, though values
1922
# are all null.
2023
COMPAT_MODES = None
@@ -97,6 +100,16 @@ def __init__(self, host=DEFAULT_HOST, port=DEFAULT_PORT, timeout=None,
97100
raise ValueError('Protocol cannot be set for gcloud '
98101
'HappyBase module')
99102

103+
if table_prefix is not None:
104+
if not isinstance(table_prefix, six.string_types):
105+
raise TypeError('table_prefix must be a string', 'received',
106+
table_prefix, type(table_prefix))
107+
108+
if not isinstance(table_prefix_separator, six.string_types):
109+
raise TypeError('table_prefix_separator must be a string',
110+
'received', table_prefix_separator,
111+
type(table_prefix_separator))
112+
100113
self.timeout = timeout
101114
self.autoconnect = autoconnect
102115
self.table_prefix = table_prefix

gcloud/bigtable/happybase/test_connection.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,17 @@ def test_constructor_with_transport(self):
6868
def test_constructor_with_protocol(self):
6969
with self.assertRaises(ValueError):
7070
self._makeOne(protocol=object())
71+
72+
def test_constructor_non_string_prefix(self):
73+
table_prefix = object()
74+
75+
with self.assertRaises(TypeError):
76+
self._makeOne(autoconnect=False,
77+
table_prefix=table_prefix)
78+
79+
def test_constructor_non_string_prefix_separator(self):
80+
table_prefix_separator = object()
81+
82+
with self.assertRaises(TypeError):
83+
self._makeOne(autoconnect=False,
84+
table_prefix_separator=table_prefix_separator)

0 commit comments

Comments
 (0)