Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit536c2ca

Browse files
authored
fix: save empty IAM policy bindings (#155)
1 parentb4860fe commit536c2ca

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

‎google/api_core/iam.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,10 @@ def __getitem__(self, key):
136136
forbinself._bindings:
137137
ifb["role"]==key:
138138
returnb["members"]
139-
returnset()
139+
# binding does not yet exist, create one
140+
new_binding= {"role":key,"members":set()}
141+
self._bindings.append(new_binding)
142+
returnnew_binding["members"]
140143

141144
def__setitem__(self,key,value):
142145
self.__check_version__()

‎tests/unit/test_iam.py‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ def test_ctor_defaults(self):
3232
policy=self._make_one()
3333
assertpolicy.etagisNone
3434
assertpolicy.versionisNone
35+
assertlen(policy)==0
36+
assertdict(policy)== {}
3537
assertpolicy.owners==empty
3638
assertpolicy.editors==empty
3739
assertpolicy.viewers==empty
38-
assertlen(policy)==0
39-
assertdict(policy)== {}
4040

4141
deftest_ctor_explicit(self):
4242
VERSION=1
@@ -45,16 +45,24 @@ def test_ctor_explicit(self):
4545
policy=self._make_one(ETAG,VERSION)
4646
assertpolicy.etag==ETAG
4747
assertpolicy.version==VERSION
48+
assertlen(policy)==0
49+
assertdict(policy)== {}
4850
assertpolicy.owners==empty
4951
assertpolicy.editors==empty
5052
assertpolicy.viewers==empty
51-
assertlen(policy)==0
52-
assertdict(policy)== {}
5353

5454
deftest___getitem___miss(self):
5555
policy=self._make_one()
5656
assertpolicy["nonesuch"]==set()
5757

58+
deftest__getitem___and_set(self):
59+
fromgoogle.api_core.iamimportOWNER_ROLE
60+
policy=self._make_one()
61+
62+
# get the policy using the getter and then modify it
63+
policy[OWNER_ROLE].add("user:phred@example.com")
64+
assertdict(policy)== {OWNER_ROLE: {"user:phred@example.com"}}
65+
5866
deftest___getitem___version3(self):
5967
policy=self._make_one("DEADBEEF",3)
6068
withpytest.raises(InvalidOperationException,match=_DICT_ACCESS_MSG):
@@ -293,10 +301,10 @@ def test_from_api_repr_only_etag(self):
293301
policy=klass.from_api_repr(RESOURCE)
294302
assertpolicy.etag=="ACAB"
295303
assertpolicy.versionisNone
304+
assertdict(policy)== {}
296305
assertpolicy.owners==empty
297306
assertpolicy.editors==empty
298307
assertpolicy.viewers==empty
299-
assertdict(policy)== {}
300308

301309
deftest_from_api_repr_complete(self):
302310
fromgoogle.api_core.iamimportOWNER_ROLE,EDITOR_ROLE,VIEWER_ROLE

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp