Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add to_api_repr method to TableListItem #299

Merged
merged 4 commits into from Oct 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions google/cloud/bigquery/table.py
Expand Up @@ -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.
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/test_table.py
Expand Up @@ -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):
Expand Down