@@ -211,3 +211,100 @@ def test_check(self):
211
211
verify = True ,
212
212
timeout = DEFAULT_TIMEOUT_SECONDS ,
213
213
)
214
+
215
+ def test_load_resources_details_success (self ):
216
+ client = DescopeClient (
217
+ self .dummy_project_id ,
218
+ self .public_key_dict ,
219
+ False ,
220
+ self .dummy_management_key ,
221
+ )
222
+ response_body = {
223
+ "resourcesDetails" : [
224
+ {"resourceId" : "r1" , "resourceType" : "type1" , "displayName" : "Name1" },
225
+ {"resourceId" : "r2" , "resourceType" : "type2" , "displayName" : "Name2" },
226
+ ]
227
+ }
228
+ with patch ("requests.post" ) as mock_post :
229
+ mock_post .return_value .ok = True
230
+ mock_post .return_value .json .return_value = response_body
231
+ ids = [
232
+ {"resourceId" : "r1" , "resourceType" : "type1" },
233
+ {"resourceId" : "r2" , "resourceType" : "type2" },
234
+ ]
235
+ details = client .mgmt .fga .load_resources_details (ids )
236
+ self .assertEqual (details , response_body ["resourcesDetails" ])
237
+ mock_post .assert_called_with (
238
+ f"{ common .DEFAULT_BASE_URL } { MgmtV1 .fga_resources_load } " ,
239
+ headers = {
240
+ ** common .default_headers ,
241
+ "Authorization" : f"Bearer { self .dummy_project_id } :{ self .dummy_management_key } " ,
242
+ "x-descope-project-id" : self .dummy_project_id ,
243
+ },
244
+ params = None ,
245
+ json = {"resourceIdentifiers" : ids },
246
+ allow_redirects = False ,
247
+ verify = True ,
248
+ timeout = DEFAULT_TIMEOUT_SECONDS ,
249
+ )
250
+
251
+ def test_load_resources_details_error (self ):
252
+ client = DescopeClient (
253
+ self .dummy_project_id ,
254
+ self .public_key_dict ,
255
+ False ,
256
+ self .dummy_management_key ,
257
+ )
258
+ with patch ("requests.post" ) as mock_post :
259
+ mock_post .return_value .ok = False
260
+ ids = [{"resourceId" : "r1" , "resourceType" : "type1" }]
261
+ self .assertRaises (
262
+ AuthException ,
263
+ client .mgmt .fga .load_resources_details ,
264
+ ids ,
265
+ )
266
+
267
+ def test_save_resources_details_success (self ):
268
+ client = DescopeClient (
269
+ self .dummy_project_id ,
270
+ self .public_key_dict ,
271
+ False ,
272
+ self .dummy_management_key ,
273
+ )
274
+ details = [
275
+ {"resourceId" : "r1" , "resourceType" : "type1" , "displayName" : "Name1" }
276
+ ]
277
+ with patch ("requests.post" ) as mock_post :
278
+ mock_post .return_value .ok = True
279
+ client .mgmt .fga .save_resources_details (details )
280
+ mock_post .assert_called_with (
281
+ f"{ common .DEFAULT_BASE_URL } { MgmtV1 .fga_resources_save } " ,
282
+ headers = {
283
+ ** common .default_headers ,
284
+ "Authorization" : f"Bearer { self .dummy_project_id } :{ self .dummy_management_key } " ,
285
+ "x-descope-project-id" : self .dummy_project_id ,
286
+ },
287
+ params = None ,
288
+ json = {"resourcesDetails" : details },
289
+ allow_redirects = False ,
290
+ verify = True ,
291
+ timeout = DEFAULT_TIMEOUT_SECONDS ,
292
+ )
293
+
294
+ def test_save_resources_details_error (self ):
295
+ client = DescopeClient (
296
+ self .dummy_project_id ,
297
+ self .public_key_dict ,
298
+ False ,
299
+ self .dummy_management_key ,
300
+ )
301
+ details = [
302
+ {"resourceId" : "r1" , "resourceType" : "type1" , "displayName" : "Name1" }
303
+ ]
304
+ with patch ("requests.post" ) as mock_post :
305
+ mock_post .return_value .ok = False
306
+ self .assertRaises (
307
+ AuthException ,
308
+ client .mgmt .fga .save_resources_details ,
309
+ details ,
310
+ )
0 commit comments