@@ -100,6 +100,10 @@ def test_user_group_color_values(self):
100
100
101
101
class TestUserGroup :
102
102
def setup_method (self ):
103
+ # Reset the global roles cache before each test
104
+ import labelbox .schema .role as role_module
105
+ role_module ._ROLES = None
106
+
103
107
self .client = MagicMock (Client )
104
108
self .client .get_roles .return_value = {
105
109
"LABELER" : Role (self .client , {"id" : "role_id" , "name" : "LABELER" }),
@@ -167,26 +171,36 @@ def test_get(self):
167
171
"orgRole" : {"id" : "role_id_2" , "name" : "LABELER" },
168
172
},
169
173
]
170
- self .client .execute .return_value = {
171
- "userGroupV2" : {
172
- "id" : "group_id" ,
173
- "name" : "Test Group" ,
174
- "color" : "4ED2F9" ,
175
- "description" : "" ,
176
- "projects" : {
177
- "nodes" : projects ,
178
- "totalCount" : 2 ,
179
- },
180
- "members" : {
181
- "nodes" : group_members ,
182
- "totalCount" : 2 ,
183
- "userGroupRoles" : [
184
- {"userId" : "user_id_1" , "roleId" : "role_id_1" },
185
- {"userId" : "user_id_2" , "roleId" : "role_id_2" },
186
- ],
187
- },
174
+ self .client .execute .side_effect = [
175
+ # Mock get_roles query response first
176
+ {
177
+ "roles" : [
178
+ {"id" : "role_id_1" , "name" : "LABELER" },
179
+ {"id" : "role_id_2" , "name" : "LABELER" },
180
+ ]
181
+ },
182
+ # Mock userGroupV2 query response
183
+ {
184
+ "userGroupV2" : {
185
+ "id" : "group_id" ,
186
+ "name" : "Test Group" ,
187
+ "color" : "4ED2F9" ,
188
+ "description" : "" ,
189
+ "projects" : {
190
+ "nodes" : projects ,
191
+ "totalCount" : 2 ,
192
+ },
193
+ "members" : {
194
+ "nodes" : group_members ,
195
+ "totalCount" : 2 ,
196
+ "userGroupRoles" : [
197
+ {"userId" : "user_id_1" , "roleId" : "role_id_1" },
198
+ {"userId" : "user_id_2" , "roleId" : "role_id_2" },
199
+ ],
200
+ },
201
+ }
188
202
}
189
- }
203
+ ]
190
204
group = UserGroup (self .client )
191
205
assert group .id == ""
192
206
assert group .name == ""
@@ -244,6 +258,12 @@ def test_update(self, group_user, group_project, mock_role):
244
258
}
245
259
}
246
260
},
261
+ # Mock get_roles query response
262
+ {
263
+ "roles" : [
264
+ {"id" : "role_id" , "name" : "LABELER" },
265
+ ]
266
+ },
247
267
# Mock get query response after update
248
268
{
249
269
"userGroupV2" : {
@@ -297,6 +317,10 @@ def test_update_without_members_should_work(self, group_project):
297
317
}
298
318
}
299
319
},
320
+ # Mock get_roles query response (even though no members, _get_members_set is still called)
321
+ {
322
+ "roles" : []
323
+ },
300
324
# Mock get query response
301
325
{
302
326
"userGroupV2" : {
@@ -356,42 +380,51 @@ def test_user_groups_empty(self):
356
380
assert len (user_groups ) == 0
357
381
358
382
def test_user_groups (self ):
359
- self .client .execute .return_value = {
360
- "userGroupsV2" : {
361
- "totalCount" : 2 ,
362
- "nextCursor" : None ,
363
- "nodes" : [
364
- {
365
- "id" : "group_id_1" ,
366
- "name" : "Group 1" ,
367
- "color" : "9EC5FF" ,
368
- "description" : "" ,
369
- "projects" : {
370
- "nodes" : [],
371
- "totalCount" : 0 ,
372
- },
373
- "members" : {
374
- "nodes" : [],
375
- "totalCount" : 0 ,
376
- },
377
- },
378
- {
379
- "id" : "group_id_2" ,
380
- "name" : "Group 2" ,
381
- "color" : "CEB8FF" ,
382
- "description" : "" ,
383
- "projects" : {
384
- "nodes" : [],
385
- "totalCount" : 0 ,
383
+ # Mock get_roles and get_user_groups responses
384
+ # get_roles will be called once (cached for subsequent calls)
385
+ self .client .execute .side_effect = [
386
+ # get_roles query (called once, then cached)
387
+ {"roles" : []},
388
+ # get_user_groups query
389
+ {
390
+ "userGroupsV2" : {
391
+ "totalCount" : 2 ,
392
+ "nextCursor" : None ,
393
+ "nodes" : [
394
+ {
395
+ "id" : "group_id_1" ,
396
+ "name" : "Group 1" ,
397
+ "color" : "9EC5FF" ,
398
+ "description" : "" ,
399
+ "projects" : {
400
+ "nodes" : [],
401
+ "totalCount" : 0 ,
402
+ },
403
+ "members" : {
404
+ "nodes" : [],
405
+ "totalCount" : 0 ,
406
+ "userGroupRoles" : [],
407
+ },
386
408
},
387
- "members" : {
388
- "nodes" : [],
389
- "totalCount" : 0 ,
409
+ {
410
+ "id" : "group_id_2" ,
411
+ "name" : "Group 2" ,
412
+ "color" : "CEB8FF" ,
413
+ "description" : "" ,
414
+ "projects" : {
415
+ "nodes" : [],
416
+ "totalCount" : 0 ,
417
+ },
418
+ "members" : {
419
+ "nodes" : [],
420
+ "totalCount" : 0 ,
421
+ "userGroupRoles" : [],
422
+ },
390
423
},
391
- } ,
392
- ],
424
+ ] ,
425
+ }
393
426
}
394
- }
427
+ ]
395
428
user_groups = list (UserGroup .get_user_groups (self .client ))
396
429
assert len (user_groups ) == 2
397
430
assert user_groups [0 ].name == "Group 1"
@@ -448,6 +481,12 @@ def test_create(self, group_user, group_project, mock_role):
448
481
}
449
482
}
450
483
},
484
+ # Mock get_roles query response
485
+ {
486
+ "roles" : [
487
+ {"id" : "role_id" , "name" : "LABELER" },
488
+ ]
489
+ },
451
490
# Mock get query response after create
452
491
{
453
492
"userGroupV2" : {
@@ -501,6 +540,10 @@ def test_create_without_members_should_work(self, group_project):
501
540
}
502
541
}
503
542
},
543
+ # Mock get_roles query response (even though no members, _get_members_set is still called)
544
+ {
545
+ "roles" : []
546
+ },
504
547
# Mock get query response
505
548
{
506
549
"userGroupV2" : {
@@ -588,7 +631,11 @@ def test_create_mutation():
588
631
}
589
632
}
590
633
},
591
- # Second call: get query
634
+ # Second call: get_roles query
635
+ {
636
+ "roles" : []
637
+ },
638
+ # Third call: get query
592
639
{
593
640
"userGroupV2" : {
594
641
"id" : "group_id" ,
@@ -646,7 +693,11 @@ def test_update_mutation():
646
693
}
647
694
}
648
695
},
649
- # Second call: get query
696
+ # Second call: get_roles query
697
+ {
698
+ "roles" : []
699
+ },
700
+ # Third call: get query
650
701
{
651
702
"userGroupV2" : {
652
703
"id" : "group_id" ,
0 commit comments