@@ -613,6 +613,15 @@ def test_equality_and_hash_without_condition(self):
613
613
assert hash (entry1 ) == hash (entry2 )
614
614
assert hash (entry1 ) != hash (entry3 ) # Usually true
615
615
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
+
616
625
def test_equality_and_hash_with_condition (self , condition_1 , condition_2 ):
617
626
cond1a = Condition (
618
627
condition_1 .expression , condition_1 .title , condition_1 .description
@@ -746,6 +755,13 @@ def test_dataset_property_with_condition(self, condition_1):
746
755
assert "dataset" in entry ._properties
747
756
assert "condition" in entry ._properties
748
757
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" : "owner@example.com" }
761
+ entry = AccessEntry .from_api_repr (api_repr )
762
+ entry_str = repr (entry )
763
+ assert entry_str == "<AccessEntry: role=OWNER, userByEmail=owner@example.com>"
764
+
749
765
750
766
class TestDatasetReference (unittest .TestCase ):
751
767
@staticmethod
@@ -1097,6 +1113,34 @@ def test_ctor_explicit(self):
1097
1113
self .assertIsNone (dataset .location )
1098
1114
self .assertEqual (dataset .is_case_insensitive , False )
1099
1115
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" : "uilma@example.com" ,
1127
+ },
1128
+ {
1129
+ "role" : "READER" ,
1130
+ "groupByEmail" : "rhubbles@example.com" ,
1131
+ },
1132
+ ],
1133
+ }
1134
+ )
1135
+ assert (
1136
+ AccessEntry ("OWNER" , "userByEmail" , "uilma@example.com" )
1137
+ in dataset .access_entries
1138
+ )
1139
+ assert (
1140
+ AccessEntry ("READER" , "groupByEmail" , "rhubbles@example.com" )
1141
+ in dataset .access_entries
1142
+ )
1143
+
1100
1144
def test_access_entries_setter_non_list (self ):
1101
1145
dataset = self ._make_one (self .DS_REF )
1102
1146
with self .assertRaises (TypeError ):
0 commit comments