@@ -613,6 +613,15 @@ def test_equality_and_hash_without_condition(self):
613613 assert hash (entry1 ) == hash (entry2 )
614614 assert hash (entry1 ) != hash (entry3 ) # Usually true
615615
616+ def test_equality_and_hash_from_api_repr (self ):
617+ """Compare equal entries where one was created via from_api_repr."""
618+ entry1 = AccessEntry ("OWNER" , "specialGroup" , "projectOwners" )
619+ entry2 = AccessEntry .from_api_repr (
620+ {"role" : "OWNER" , "specialGroup" : "projectOwners" }
621+ )
622+ assert entry1 == entry2
623+ assert hash (entry1 ) == hash (entry2 )
624+
616625 def test_equality_and_hash_with_condition (self , condition_1 , condition_2 ):
617626 cond1a = Condition (
618627 condition_1 .expression , condition_1 .title , condition_1 .description
@@ -746,6 +755,13 @@ def test_dataset_property_with_condition(self, condition_1):
746755 assert "dataset" in entry ._properties
747756 assert "condition" in entry ._properties
748757
758+ def test_repr_from_api_repr (self ):
759+ """Check that repr() includes the correct entity_type when the object is initialized from a dictionary."""
760+ api_repr = {
"role" :
"OWNER" ,
"userByEmail" :
"[email protected] " }
761+ entry = AccessEntry .from_api_repr (api_repr )
762+ entry_str = repr (entry )
763+ assert entry_str == "<AccessEntry: role=OWNER, [email protected] >" 764+
749765
750766class TestDatasetReference (unittest .TestCase ):
751767 @staticmethod
@@ -1097,6 +1113,34 @@ def test_ctor_explicit(self):
10971113 self .assertIsNone (dataset .location )
10981114 self .assertEqual (dataset .is_case_insensitive , False )
10991115
1116+ def test_access_entries_getter_from_api_repr (self ):
1117+ """Check that `in` works correctly when Dataset is made via from_api_repr()."""
1118+ from google .cloud .bigquery .dataset import AccessEntry
1119+
1120+ dataset = self ._get_target_class ().from_api_repr (
1121+ {
1122+ "datasetReference" : {"projectId" : "my-proj" , "datasetId" : "my_dset" },
1123+ "access" : [
1124+ {
1125+ "role" : "OWNER" ,
1126+ "userByEmail" :
"[email protected] " ,
1127+ },
1128+ {
1129+ "role" : "READER" ,
1130+ "groupByEmail" :
"[email protected] " ,
1131+ },
1132+ ],
1133+ }
1134+ )
1135+ assert (
1136+ AccessEntry (
"OWNER" ,
"userByEmail" ,
"[email protected] " )
1137+ in dataset .access_entries
1138+ )
1139+ assert (
1140+ AccessEntry (
"READER" ,
"groupByEmail" ,
"[email protected] " )
1141+ in dataset .access_entries
1142+ )
1143+
11001144 def test_access_entries_setter_non_list (self ):
11011145 dataset = self ._make_one (self .DS_REF )
11021146 with self .assertRaises (TypeError ):
0 commit comments