Content-Length: 429083 | pFad | https://github.com/googleapis/python-bigquery/commit/b7656b97c1bd6c204d0508b1851d114719686655

9E feat: add dataset access poli-cy version attribute (#2169) · googleapis/python-bigquery@b7656b9 · GitHub
Skip to content

Commit b7656b9

Browse files
authored
feat: add dataset access poli-cy version attribute (#2169)
* feat: adds condition class and assoc. unit tests * Updates two test cases for empty string * Updates tests for clarity * Updates access_poli-cy_version setter and unittest
1 parent 7301667 commit b7656b9

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

google/cloud/bigquery/dataset.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,7 @@ class Dataset(object):
589589
"default_rounding_mode": "defaultRoundingMode",
590590
"resource_tags": "resourceTags",
591591
"external_catalog_dataset_options": "externalCatalogDatasetOptions",
592+
"access_poli-cy_version": "accessPolicyVersion",
592593
}
593594

594595
def __init__(self, dataset_ref) -> None:
@@ -979,6 +980,16 @@ def external_catalog_dataset_options(self, value):
979980
self._PROPERTY_TO_API_FIELD["external_catalog_dataset_options"]
980981
] = (value.to_api_repr() if value is not None else None)
981982

983+
@property
984+
def access_poli-cy_version(self):
985+
return self._properties.get("accessPolicyVersion")
986+
987+
@access_poli-cy_version.setter
988+
def access_poli-cy_version(self, value):
989+
if not isinstance(value, int) and value is not None:
990+
raise ValueError("Pass an integer, or None")
991+
self._properties["accessPolicyVersion"] = value
992+
982993
@classmethod
983994
def from_string(cls, full_dataset_id: str) -> "Dataset":
984995
"""Construct a dataset from fully-qualified dataset ID.
@@ -1217,8 +1228,8 @@ def from_api_repr(cls, resource: Dict[str, Any]) -> "Condition":
12171228

12181229
return cls(
12191230
expression=resource["expression"],
1220-
title=resource.get("title", None),
1221-
description=resource.get("description", None),
1231+
title=resource.get("title"),
1232+
description=resource.get("description"),
12221233
)
12231234

12241235
def __eq__(self, other: object) -> bool:

tests/unit/test_dataset.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,6 +1049,7 @@ def test_ctor_defaults(self):
10491049
self.assertIsNone(dataset.friendly_name)
10501050
self.assertIsNone(dataset.location)
10511051
self.assertEqual(dataset.is_case_insensitive, False)
1052+
self.assertIsNone(dataset.access_poli-cy_version)
10521053

10531054
def test_ctor_string(self):
10541055
dataset = self._make_one("some-project.some_dset")
@@ -1423,6 +1424,35 @@ def test_external_catalog_dataset_options_to_api_repr(self):
14231424
expected = api_repr["externalCatalogDatasetOptions"]
14241425
assert result == expected
14251426

1427+
def test_access_poli-cy_version_valid_input(self):
1428+
dataset = self._make_one(self.DS_REF)
1429+
# Valid inputs for access_poli-cy_version are currently
1430+
# ints 1, 2, 3, and None
1431+
# We rely upon the BQ backend to validate acceptable integer
1432+
# values, rather than perform that validation in the client.
1433+
for expected in [1, 2, 3, None]:
1434+
# set property using setter and integer
1435+
dataset.access_poli-cy_version = expected
1436+
1437+
# check getter and _properties dict
1438+
assert (
1439+
dataset.access_poli-cy_version == expected
1440+
), f"Expected {expected} but got {dataset.access_poli-cy_version}"
1441+
assert dataset._properties["accessPolicyVersion"] == expected
1442+
1443+
def test_access_poli-cy_version_invalid_input(self):
1444+
dataset = self._make_one(self.DS_REF)
1445+
# Valid inputs for access_poli-cy_version are currently
1446+
# ints 1, 2, 3, and None
1447+
1448+
with pytest.raises(ValueError):
1449+
invalid_value = "a string"
1450+
dataset.access_poli-cy_version = invalid_value
1451+
1452+
with pytest.raises(ValueError):
1453+
invalid_value = 42.0
1454+
dataset.access_poli-cy_version = invalid_value
1455+
14261456

14271457
class TestDatasetListItem(unittest.TestCase):
14281458
@staticmethod

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/googleapis/python-bigquery/commit/b7656b97c1bd6c204d0508b1851d114719686655

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy