-
Notifications
You must be signed in to change notification settings - Fork 316
fix: ensure AccessEntry equality and repr uses the correct entity_type
#2182
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -613,6 +613,15 @@ def test_equality_and_hash_without_condition(self): | |
assert hash(entry1) == hash(entry2) | ||
assert hash(entry1) != hash(entry3) # Usually true | ||
|
||
def test_equality_and_hash_from_api_repr(self): | ||
"""Compare equal entries where one was created via from_api_repr.""" | ||
entry1 = AccessEntry("OWNER", "specialGroup", "projectOwners") | ||
entry2 = AccessEntry.from_api_repr( | ||
{"role": "OWNER", "specialGroup": "projectOwners"} | ||
) | ||
assert entry1 == entry2 | ||
assert hash(entry1) == hash(entry2) | ||
|
||
def test_equality_and_hash_with_condition(self, condition_1, condition_2): | ||
cond1a = Condition( | ||
condition_1.expression, condition_1.title, condition_1.description | ||
|
@@ -746,6 +755,13 @@ def test_dataset_property_with_condition(self, condition_1): | |
assert "dataset" in entry._properties | ||
assert "condition" in entry._properties | ||
|
||
def test_repr_from_api_repr(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please check the array of AccessEntry works too? The g3 failed tests show the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in 0cfa704 Also verified that the added test fails until the changes in |
||
"""Check that repr() includes the correct entity_type when the object is initialized from a dictionary.""" | ||
api_repr = {"role": "OWNER", "userByEmail": "[email protected]"} | ||
entry = AccessEntry.from_api_repr(api_repr) | ||
entry_str = repr(entry) | ||
assert entry_str == "<AccessEntry: role=OWNER, [email protected]>" | ||
|
||
|
||
class TestDatasetReference(unittest.TestCase): | ||
@staticmethod | ||
|
@@ -1097,6 +1113,34 @@ def test_ctor_explicit(self): | |
self.assertIsNone(dataset.location) | ||
self.assertEqual(dataset.is_case_insensitive, False) | ||
|
||
def test_access_entries_getter_from_api_repr(self): | ||
"""Check that `in` works correctly when Dataset is made via from_api_repr().""" | ||
from google.cloud.bigquery.dataset import AccessEntry | ||
|
||
dataset = self._get_target_class().from_api_repr( | ||
{ | ||
"datasetReference": {"projectId": "my-proj", "datasetId": "my_dset"}, | ||
"access": [ | ||
{ | ||
"role": "OWNER", | ||
"userByEmail": "[email protected]", | ||
}, | ||
{ | ||
"role": "READER", | ||
"groupByEmail": "[email protected]", | ||
}, | ||
], | ||
} | ||
) | ||
assert ( | ||
AccessEntry("OWNER", "userByEmail", "[email protected]") | ||
in dataset.access_entries | ||
) | ||
assert ( | ||
AccessEntry("READER", "groupByEmail", "[email protected]") | ||
in dataset.access_entries | ||
) | ||
|
||
def test_access_entries_setter_non_list(self): | ||
dataset = self._make_one(self.DS_REF) | ||
with self.assertRaises(TypeError): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI: I did a mini-TDD for this. Both of these tests fail without the changes in
dataset.py
.