Skip to content

Commit

Permalink
Merge pull request #1390 from dhermes/happybase-check-string-prefix
Browse files Browse the repository at this point in the history
Requiring that prefixes are strings in HappyBase.
  • Loading branch information
dhermes committed Jan 20, 2016
2 parents 5a20f3d + 614be5e commit b13d03d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
13 changes: 13 additions & 0 deletions gcloud/bigtable/happybase/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
"""Google Cloud Bigtable HappyBase connection module."""


import six


# Constants reproduced here for HappyBase compatibility, though values
# are all null.
COMPAT_MODES = None
Expand Down Expand Up @@ -97,6 +100,16 @@ def __init__(self, host=DEFAULT_HOST, port=DEFAULT_PORT, timeout=None,
raise ValueError('Protocol cannot be set for gcloud '
'HappyBase module')

if table_prefix is not None:
if not isinstance(table_prefix, six.string_types):
raise TypeError('table_prefix must be a string', 'received',
table_prefix, type(table_prefix))

if not isinstance(table_prefix_separator, six.string_types):
raise TypeError('table_prefix_separator must be a string',
'received', table_prefix_separator,
type(table_prefix_separator))

self.timeout = timeout
self.autoconnect = autoconnect
self.table_prefix = table_prefix
Expand Down
14 changes: 14 additions & 0 deletions gcloud/bigtable/happybase/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,17 @@ def test_constructor_with_transport(self):
def test_constructor_with_protocol(self):
with self.assertRaises(ValueError):
self._makeOne(protocol=object())

def test_constructor_non_string_prefix(self):
table_prefix = object()

with self.assertRaises(TypeError):
self._makeOne(autoconnect=False,
table_prefix=table_prefix)

def test_constructor_non_string_prefix_separator(self):
table_prefix_separator = object()

with self.assertRaises(TypeError):
self._makeOne(autoconnect=False,
table_prefix_separator=table_prefix_separator)

0 comments on commit b13d03d

Please sign in to comment.