feat: add dataset access policy version attribute by chalmerlowe · Pull Request #2169 · googleapis/python-bigquery · GitHub | Latest TMZ Celebrity News & Gossip | Watch TMZ Live
Skip to content

feat: add dataset access policy version attribute #2169

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

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions google/cloud/bigquery/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,7 @@ class Dataset(object):
"default_rounding_mode": "defaultRoundingMode",
"resource_tags": "resourceTags",
"external_catalog_dataset_options": "externalCatalogDatasetOptions",
"access_policy_version": "accessPolicyVersion",
}

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

@property
def access_policy_version(self):
return self._properties.get("accessPolicyVersion")

@access_policy_version.setter
def access_policy_version(self, value):
if not isinstance(value, int) and value is not None:
raise ValueError("Pass an integer, or None")
self._properties["accessPolicyVersion"] = value

@classmethod
def from_string(cls, full_dataset_id: str) -> "Dataset":
"""Construct a dataset from fully-qualified dataset ID.
Expand Down Expand Up @@ -1217,8 +1228,8 @@ def from_api_repr(cls, resource: Dict[str, Any]) -> "Condition":

return cls(
expression=resource["expression"],
title=resource.get("title", None),
description=resource.get("description", None),
title=resource.get("title"),
description=resource.get("description"),
)

def __eq__(self, other: object) -> bool:
Expand Down
30 changes: 30 additions & 0 deletions tests/unit/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,7 @@ def test_ctor_defaults(self):
self.assertIsNone(dataset.friendly_name)
self.assertIsNone(dataset.location)
self.assertEqual(dataset.is_case_insensitive, False)
self.assertIsNone(dataset.access_policy_version)

def test_ctor_string(self):
dataset = self._make_one("some-project.some_dset")
Expand Down Expand Up @@ -1423,6 +1424,35 @@ def test_external_catalog_dataset_options_to_api_repr(self):
expected = api_repr["externalCatalogDatasetOptions"]
assert result == expected

def test_access_policy_version_valid_input(self):
dataset = self._make_one(self.DS_REF)
# Valid inputs for access_policy_version are currently
# ints 1, 2, 3, and None
# We rely upon the BQ backend to validate acceptable integer
# values, rather than perform that validation in the client.
for expected in [1, 2, 3, None]:
# set property using setter and integer
dataset.access_policy_version = expected

# check getter and _properties dict
assert (
dataset.access_policy_version == expected
), f"Expected {expected} but got {dataset.access_policy_version}"
assert dataset._properties["accessPolicyVersion"] == expected

def test_access_policy_version_invalid_input(self):
dataset = self._make_one(self.DS_REF)
# Valid inputs for access_policy_version are currently
# ints 1, 2, 3, and None

with pytest.raises(ValueError):
invalid_value = "a string"
dataset.access_policy_version = invalid_value

with pytest.raises(ValueError):
invalid_value = 42.0
dataset.access_policy_version = invalid_value


class TestDatasetListItem(unittest.TestCase):
@staticmethod
Expand Down

TMZ Celebrity News – Breaking Stories, Videos & Gossip

Looking for the latest TMZ celebrity news? You've come to the right place. From shocking Hollywood scandals to exclusive videos, TMZ delivers it all in real time.

Whether it’s a red carpet slip-up, a viral paparazzi moment, or a legal drama involving your favorite stars, TMZ news is always first to break the story. Stay in the loop with daily updates, insider tips, and jaw-dropping photos.

🎥 Watch TMZ Live

TMZ Live brings you daily celebrity news and interviews straight from the TMZ newsroom. Don’t miss a beat—watch now and see what’s trending in Hollywood.