From 07c70f0292f9212f0c968cd5c9206e8b0409c0da Mon Sep 17 00:00:00 2001 From: HemangChothani <50404902+HemangChothani@users.noreply.github.com> Date: Tue, 13 Oct 2020 02:53:19 -0400 Subject: [PATCH] feat: add method api_repr for table list item (#299) --- google/cloud/bigquery/table.py | 8 ++++++++ tests/unit/test_table.py | 11 +++++++++++ 2 files changed, 19 insertions(+) diff --git a/google/cloud/bigquery/table.py b/google/cloud/bigquery/table.py index 01e8815da..2214d0172 100644 --- a/google/cloud/bigquery/table.py +++ b/google/cloud/bigquery/table.py @@ -1071,6 +1071,14 @@ def to_bqstorage(self): """ return self.reference.to_bqstorage() + def to_api_repr(self): + """Constructs the API resource of this table + + Returns: + Dict[str, object]: Table represented as an API resource + """ + return copy.deepcopy(self._properties) + def _row_from_mapping(mapping, schema): """Convert a mapping to a row tuple using the schema. diff --git a/tests/unit/test_table.py b/tests/unit/test_table.py index fe17d2852..376605521 100644 --- a/tests/unit/test_table.py +++ b/tests/unit/test_table.py @@ -1433,6 +1433,17 @@ def test_labels_update_in_place(self): labels["foo"] = "bar" # update in place self.assertEqual(table.labels, {"foo": "bar"}) + def test_to_api_repr(self): + resource = { + "tableReference": { + "projectId": "testproject", + "datasetId": "testdataset", + "tableId": "testtable", + } + } + table = self._make_one(resource) + self.assertEqual(table.to_api_repr(), resource) + class TestRow(unittest.TestCase): def test_row(self):