@@ -79,6 +79,17 @@ def test___setitem__(self):
7979 assert len (policy ) == 1
8080 assert dict (policy ) == {"rolename" : PRINCIPALS }
8181
82+ def test__set_item__overwrite (self ):
83+ USER = "user:phred@example.com"
84+ ALL_USERS = "allUsers"
85+ MEMBERS = set ([ALL_USERS ])
86+ policy = self ._make_one ()
87+ policy ["rolename" ] = [USER ]
88+ policy ["rolename" ] = [ALL_USERS ]
89+ assert policy ["rolename" ] == MEMBERS
90+ assert len (policy ) == 1
91+ assert dict (policy ) == {"rolename" : MEMBERS }
92+
8293 def test___setitem___version3 (self ):
8394 policy = self ._make_one ("DEADBEEF" , 3 )
8495 with pytest .raises (InvalidOperationException , match = _DICT_ACCESS_MSG ):
@@ -89,17 +100,20 @@ def test___setitem___with_conditions(self):
89100 CONDITION = {"expression" : "2 > 1" }
90101 policy = self ._make_one ("DEADBEEF" , 1 )
91102 policy .bindings = [
92- {"role" : "role/reader" , "members" : [USER ], "condition" : CONDITION }
103+ {"role" : "role/reader" , "members" : set ( [USER ]) , "condition" : CONDITION }
93104 ]
94105 with pytest .raises (InvalidOperationException , match = _DICT_ACCESS_MSG ):
95106 policy ["role/reader" ] = ["user:phred@example.com" ]
96107
97108 def test___delitem___hit (self ):
98109 policy = self ._make_one ()
99- policy .bindings = [{"role" : "rolename" , "members" : ["phred@example.com" ]}]
100- del policy ["rolename" ]
101- assert len (policy ) == 0
102- assert dict (policy ) == {}
110+ policy .bindings = [
111+ {"role" : "to/keep" , "members" : set (["phred@example.com" ])},
112+ {"role" : "to/remove" , "members" : set (["phred@example.com" ])}
113+ ]
114+ del policy ["to/remove" ]
115+ assert len (policy ) == 1
116+ assert dict (policy ) == {"to/keep" : set (["phred@example.com" ])}
103117
104118 def test___delitem___miss (self ):
105119 policy = self ._make_one ()
@@ -116,7 +130,7 @@ def test___delitem___with_conditions(self):
116130 CONDITION = {"expression" : "2 > 1" }
117131 policy = self ._make_one ("DEADBEEF" , 1 )
118132 policy .bindings = [
119- {"role" : "role/reader" , "members" : [USER ], "condition" : CONDITION }
133+ {"role" : "role/reader" , "members" : set ( [USER ]) , "condition" : CONDITION }
120134 ]
121135 with pytest .raises (InvalidOperationException , match = _DICT_ACCESS_MSG ):
122136 del policy ["role/reader" ]
@@ -125,7 +139,7 @@ def test_bindings_property(self):
125139 USER = "user:phred@example.com"
126140 CONDITION = {"expression" : "2 > 1" }
127141 policy = self ._make_one ()
128- BINDINGS = [{"role" : "role/reader" , "members" : [USER ], "condition" : CONDITION }]
142+ BINDINGS = [{"role" : "role/reader" , "members" : set ( [USER ]) , "condition" : CONDITION }]
129143 policy .bindings = BINDINGS
130144 assert policy .bindings == BINDINGS
131145
0 commit comments