@@ -90,9 +90,12 @@ def test_owners_setter(self):
90
90
MEMBER = "user:phred@example.com"
91
91
expected = set ([MEMBER ])
92
92
policy = self ._make_one ()
93
- with warnings . catch_warnings ():
94
- warnings .simplefilter ( "always" )
93
+
94
+ with warnings .catch_warnings ( record = True ) as warned :
95
95
policy .owners = [MEMBER ]
96
+
97
+ warning , = warned
98
+ assert warning .category is DeprecationWarning
96
99
assert policy [OWNER_ROLE ] == expected
97
100
98
101
def test_editors_getter (self ):
@@ -111,9 +114,12 @@ def test_editors_setter(self):
111
114
MEMBER = "user:phred@example.com"
112
115
expected = set ([MEMBER ])
113
116
policy = self ._make_one ()
114
- with warnings . catch_warnings ():
115
- warnings .simplefilter ( "always" )
117
+
118
+ with warnings .catch_warnings ( record = True ) as warned :
116
119
policy .editors = [MEMBER ]
120
+
121
+ warning , = warned
122
+ assert warning .category is DeprecationWarning
117
123
assert policy [EDITOR_ROLE ] == expected
118
124
119
125
def test_viewers_getter (self ):
@@ -132,9 +138,12 @@ def test_viewers_setter(self):
132
138
MEMBER = "user:phred@example.com"
133
139
expected = set ([MEMBER ])
134
140
policy = self ._make_one ()
135
- with warnings . catch_warnings ():
136
- warnings .simplefilter ( "always" )
141
+
142
+ with warnings .catch_warnings ( record = True ) as warned :
137
143
policy .viewers = [MEMBER ]
144
+
145
+ warning , = warned
146
+ assert warning .category is DeprecationWarning
138
147
assert policy [VIEWER_ROLE ] == expected
139
148
140
149
def test_user (self ):
@@ -240,17 +249,20 @@ def test_to_api_repr_binding_wo_members(self):
240
249
assert policy .to_api_repr () == {}
241
250
242
251
def test_to_api_repr_binding_w_duplicates (self ):
252
+ import warnings
243
253
from google .api_core .iam import OWNER_ROLE
244
254
245
255
OWNER = "group:cloud-logs@google.com"
246
256
policy = self ._make_one ()
247
- policy .owners = [OWNER , OWNER ]
257
+ with warnings .catch_warnings (record = True ):
258
+ policy .owners = [OWNER , OWNER ]
248
259
assert policy .to_api_repr () == {
249
260
"bindings" : [{"role" : OWNER_ROLE , "members" : [OWNER ]}]
250
261
}
251
262
252
263
def test_to_api_repr_full (self ):
253
264
import operator
265
+ import warnings
254
266
from google .api_core .iam import OWNER_ROLE , EDITOR_ROLE , VIEWER_ROLE
255
267
256
268
OWNER1 = "group:cloud-logs@google.com"
@@ -265,9 +277,10 @@ def test_to_api_repr_full(self):
265
277
{"role" : VIEWER_ROLE , "members" : [VIEWER1 , VIEWER2 ]},
266
278
]
267
279
policy = self ._make_one ("DEADBEEF" , 17 )
268
- policy .owners = [OWNER1 , OWNER2 ]
269
- policy .editors = [EDITOR1 , EDITOR2 ]
270
- policy .viewers = [VIEWER1 , VIEWER2 ]
280
+ with warnings .catch_warnings (record = True ):
281
+ policy .owners = [OWNER1 , OWNER2 ]
282
+ policy .editors = [EDITOR1 , EDITOR2 ]
283
+ policy .viewers = [VIEWER1 , VIEWER2 ]
271
284
resource = policy .to_api_repr ()
272
285
assert resource ["etag" ] == "DEADBEEF"
273
286
assert resource ["version" ] == 17
0 commit comments