diff --git a/gcloud/bigtable/happybase/connection.py b/gcloud/bigtable/happybase/connection.py index 475d80bfb01c..7ef6b483bfce 100644 --- a/gcloud/bigtable/happybase/connection.py +++ b/gcloud/bigtable/happybase/connection.py @@ -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 @@ -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 diff --git a/gcloud/bigtable/happybase/test_connection.py b/gcloud/bigtable/happybase/test_connection.py index bc1c3467b355..5913ab2219c9 100644 --- a/gcloud/bigtable/happybase/test_connection.py +++ b/gcloud/bigtable/happybase/test_connection.py @@ -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)