Skip to content

Commit c2e2b6e

Browse files
committed
Fix test following change to role name
1 parent d138c45 commit c2e2b6e

File tree

1 file changed

+105
-54
lines changed

1 file changed

+105
-54
lines changed

libs/labelbox/tests/unit/schema/test_user_group.py

Lines changed: 105 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ def test_user_group_color_values(self):
100100

101101
class TestUserGroup:
102102
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+
103107
self.client = MagicMock(Client)
104108
self.client.get_roles.return_value = {
105109
"LABELER": Role(self.client, {"id": "role_id", "name": "LABELER"}),
@@ -167,26 +171,36 @@ def test_get(self):
167171
"orgRole": {"id": "role_id_2", "name": "LABELER"},
168172
},
169173
]
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+
}
188202
}
189-
}
203+
]
190204
group = UserGroup(self.client)
191205
assert group.id == ""
192206
assert group.name == ""
@@ -244,6 +258,12 @@ def test_update(self, group_user, group_project, mock_role):
244258
}
245259
}
246260
},
261+
# Mock get_roles query response
262+
{
263+
"roles": [
264+
{"id": "role_id", "name": "LABELER"},
265+
]
266+
},
247267
# Mock get query response after update
248268
{
249269
"userGroupV2": {
@@ -297,6 +317,10 @@ def test_update_without_members_should_work(self, group_project):
297317
}
298318
}
299319
},
320+
# Mock get_roles query response (even though no members, _get_members_set is still called)
321+
{
322+
"roles": []
323+
},
300324
# Mock get query response
301325
{
302326
"userGroupV2": {
@@ -356,42 +380,51 @@ def test_user_groups_empty(self):
356380
assert len(user_groups) == 0
357381

358382
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+
},
386408
},
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+
},
390423
},
391-
},
392-
],
424+
],
425+
}
393426
}
394-
}
427+
]
395428
user_groups = list(UserGroup.get_user_groups(self.client))
396429
assert len(user_groups) == 2
397430
assert user_groups[0].name == "Group 1"
@@ -448,6 +481,12 @@ def test_create(self, group_user, group_project, mock_role):
448481
}
449482
}
450483
},
484+
# Mock get_roles query response
485+
{
486+
"roles": [
487+
{"id": "role_id", "name": "LABELER"},
488+
]
489+
},
451490
# Mock get query response after create
452491
{
453492
"userGroupV2": {
@@ -501,6 +540,10 @@ def test_create_without_members_should_work(self, group_project):
501540
}
502541
}
503542
},
543+
# Mock get_roles query response (even though no members, _get_members_set is still called)
544+
{
545+
"roles": []
546+
},
504547
# Mock get query response
505548
{
506549
"userGroupV2": {
@@ -588,7 +631,11 @@ def test_create_mutation():
588631
}
589632
}
590633
},
591-
# Second call: get query
634+
# Second call: get_roles query
635+
{
636+
"roles": []
637+
},
638+
# Third call: get query
592639
{
593640
"userGroupV2": {
594641
"id": "group_id",
@@ -646,7 +693,11 @@ def test_update_mutation():
646693
}
647694
}
648695
},
649-
# Second call: get query
696+
# Second call: get_roles query
697+
{
698+
"roles": []
699+
},
700+
# Third call: get query
650701
{
651702
"userGroupV2": {
652703
"id": "group_id",

0 commit comments

Comments
 (0)