diff --git a/gcloud/bigtable/happybase/test_table.py b/gcloud/bigtable/happybase/test_table.py index cf95896a76968..50b0ef175a2d9 100644 --- a/gcloud/bigtable/happybase/test_table.py +++ b/gcloud/bigtable/happybase/test_table.py @@ -1265,8 +1265,8 @@ def _column_helper(self, num_filters, versions=None, timestamp=None, # Relies on the fact that RowFilter instances can # only have one value set. - self.assertEqual(fam_filter.regex, col_fam) - self.assertEqual(qual_filter.regex, qual) + self.assertEqual(fam_filter.regex, col_fam.encode('utf-8')) + self.assertEqual(qual_filter.regex, qual.encode('utf-8')) return result @@ -1356,14 +1356,14 @@ def test_column_and_column_families(self): filter2 = result.filters[1] self.assertTrue(isinstance(filter1, FamilyNameRegexFilter)) - self.assertEqual(filter1.regex, col_fam1) + self.assertEqual(filter1.regex, col_fam1.encode('utf-8')) self.assertTrue(isinstance(filter2, RowFilterChain)) filter2a, filter2b = filter2.filters self.assertTrue(isinstance(filter2a, FamilyNameRegexFilter)) - self.assertEqual(filter2a.regex, col_fam2) + self.assertEqual(filter2a.regex, col_fam2.encode('utf-8')) self.assertTrue(isinstance(filter2b, ColumnQualifierRegexFilter)) - self.assertEqual(filter2b.regex, col_qual2) + self.assertEqual(filter2b.regex, col_qual2.encode('utf-8')) class Test__row_keys_filter_helper(unittest2.TestCase): diff --git a/gcloud/bigtable/row.py b/gcloud/bigtable/row.py index 276f009b7bb1e..c72940539d1be 100644 --- a/gcloud/bigtable/row.py +++ b/gcloud/bigtable/row.py @@ -870,7 +870,7 @@ class _RegexFilter(RowFilter): """ def __init__(self, regex): - self.regex = regex + self.regex = _to_bytes(regex) def __eq__(self, other): if not isinstance(other, self.__class__): diff --git a/gcloud/bigtable/test_row.py b/gcloud/bigtable/test_row.py index 4caa6668e2b29..e6b43ce163e4c 100644 --- a/gcloud/bigtable/test_row.py +++ b/gcloud/bigtable/test_row.py @@ -771,24 +771,29 @@ def _makeOne(self, *args, **kwargs): return self._getTargetClass()(*args, **kwargs) def test_constructor(self): - regex = object() + regex = b'abc' row_filter = self._makeOne(regex) self.assertTrue(row_filter.regex is regex) + def test_constructor_non_bytes(self): + regex = u'abc' + row_filter = self._makeOne(regex) + self.assertEqual(row_filter.regex, b'abc') + def test___eq__type_differ(self): - regex = object() + regex = b'def-rgx' row_filter1 = self._makeOne(regex) row_filter2 = object() self.assertNotEqual(row_filter1, row_filter2) def test___eq__same_value(self): - regex = object() + regex = b'trex-regex' row_filter1 = self._makeOne(regex) row_filter2 = self._makeOne(regex) self.assertEqual(row_filter1, row_filter2) def test___ne__same_value(self): - regex = object() + regex = b'abc' row_filter1 = self._makeOne(regex) row_filter2 = self._makeOne(regex) comparison_val = (row_filter1 != row_filter2) diff --git a/scripts/run_pylint.py b/scripts/run_pylint.py index 1e92422fc45cf..92db5f06583bd 100644 --- a/scripts/run_pylint.py +++ b/scripts/run_pylint.py @@ -66,7 +66,7 @@ } TEST_RC_REPLACEMENTS = { 'FORMAT': { - 'max-module-lines': 1825, + 'max-module-lines': 1830, }, } diff --git a/system_tests/bigtable_happybase.py b/system_tests/bigtable_happybase.py index 06f6dcf4d8b8a..556768263b016 100644 --- a/system_tests/bigtable_happybase.py +++ b/system_tests/bigtable_happybase.py @@ -13,6 +13,7 @@ # limitations under the License. +import struct import time import unittest2 @@ -23,6 +24,7 @@ from gcloud.environment_vars import TESTS_PROJECT +_PACK_I64 = struct.Struct('>q').pack _helpers.PROJECT = TESTS_PROJECT ZONE = 'us-central1-c' NOW_MILLIS = int(1000 * time.time()) @@ -38,6 +40,8 @@ COL_FAM2: {'max_versions': 1, 'time_to_live': TTL_FOR_TEST}, COL_FAM3: {}, # use defaults } +ROW_KEY1 = 'row-key1' +COL1 = COL_FAM1 + ':qual1' class Config(object): @@ -111,3 +115,77 @@ def test_create_table_failure(self): with self.assertRaises(ValueError): connection.create_table(ALT_TABLE_NAME, empty_families) self.assertFalse(ALT_TABLE_NAME in connection.tables()) + + +class BaseTableTest(unittest2.TestCase): + + def setUp(self): + self.rows_to_delete = [] + + def tearDown(self): + for row_key in self.rows_to_delete: + Config.TABLE.delete(row_key) + + +class TestTable_families(BaseTableTest): + + def test_families(self): + families = Config.TABLE.families() + + self.assertEqual(set(families.keys()), set(FAMILIES.keys())) + for col_fam, settings in FAMILIES.items(): + retrieved = families[col_fam] + for key, value in settings.items(): + self.assertEqual(retrieved[key], value) + + +class TestTableCounterMethods(BaseTableTest): + + def test_counter_get(self): + table = Config.TABLE + + # Need to clean-up row1 after. + self.rows_to_delete.append(ROW_KEY1) + + self.assertEqual(table.row(ROW_KEY1, columns=[COL1]), {}) + initial_counter = table.counter_get(ROW_KEY1, COL1) + self.assertEqual(initial_counter, 0) + + self.assertEqual(table.row(ROW_KEY1, columns=[COL1]), + {COL1: _PACK_I64(0)}) + + def test_counter_inc(self): + table = Config.TABLE + + # Need to clean-up row1 after. + self.rows_to_delete.append(ROW_KEY1) + + self.assertEqual(table.row(ROW_KEY1, columns=[COL1]), {}) + initial_counter = table.counter_get(ROW_KEY1, COL1) + self.assertEqual(initial_counter, 0) + + inc_value = 10 + updated_counter = table.counter_inc(ROW_KEY1, COL1, value=inc_value) + self.assertEqual(updated_counter, inc_value) + + # Check that the value is set (does not seem to occur on HBase). + self.assertEqual(table.row(ROW_KEY1, columns=[COL1]), + {COL1: _PACK_I64(inc_value)}) + + def test_counter_dec(self): + table = Config.TABLE + + # Need to clean-up row1 after. + self.rows_to_delete.append(ROW_KEY1) + + self.assertEqual(table.row(ROW_KEY1, columns=[COL1]), {}) + initial_counter = table.counter_get(ROW_KEY1, COL1) + self.assertEqual(initial_counter, 0) + + dec_value = 10 + updated_counter = table.counter_dec(ROW_KEY1, COL1, value=dec_value) + self.assertEqual(updated_counter, -dec_value) + + # Check that the value is set (does not seem to occur on HBase). + self.assertEqual(table.row(ROW_KEY1, columns=[COL1]), + {COL1: _PACK_I64(-dec_value)})