From ecd4da4fd8797b7eaad2fb1cf44b8a9a85d6a285 Mon Sep 17 00:00:00 2001 From: Dima Timofeev Date: Fri, 12 May 2017 21:57:48 +0100 Subject: [PATCH] Add getters for Bigtable Row.row_key and Row.table (#3408) --- bigtable/google/cloud/bigtable/row.py | 18 ++++++++++++++++++ bigtable/tests/unit/test_row.py | 19 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/bigtable/google/cloud/bigtable/row.py b/bigtable/google/cloud/bigtable/row.py index 5e9075ef8eec..09d12377a49c 100644 --- a/bigtable/google/cloud/bigtable/row.py +++ b/bigtable/google/cloud/bigtable/row.py @@ -55,6 +55,24 @@ def __init__(self, row_key, table): self._row_key = _to_bytes(row_key) self._table = table + @property + def row_key(self): + """Row key. + + :rtype: bytes + :returns: The key for the current row. + """ + return self._row_key + + @property + def table(self): + """Row table. + + :rtype: table: :class:`Table ` + :returns: table: The table that owns the row. + """ + return self._table + class _SetDeleteRow(Row): """Row helper for setting or deleting cell values. diff --git a/bigtable/tests/unit/test_row.py b/bigtable/tests/unit/test_row.py index 3e2d4fd60e0f..046934ca1f27 100644 --- a/bigtable/tests/unit/test_row.py +++ b/bigtable/tests/unit/test_row.py @@ -16,6 +16,25 @@ import unittest +class TestRow(unittest.TestCase): + + @staticmethod + def _get_target_class(): + from google.cloud.bigtable.row import Row + return Row + + def _make_one(self, *args, **kwargs): + return self._get_target_class()(*args, **kwargs) + + def test_row_key_getter(self): + row = self._make_one(row_key=b'row_key', table='table') + self.assertEqual(b'row_key', row.row_key) + + def test_row_table_getter(self): + row = self._make_one(row_key=b'row_key', table='table') + self.assertEqual('table', row.table) + + class Test_SetDeleteRow(unittest.TestCase): @staticmethod