@@ -117,19 +117,37 @@ def test_get_groups_and_users(get_mock):
117117 'displayName' : 'test-group-2' ,
118118 'members' : [
119119 {'objectId' : 'user-id3' },
120- {'objectId' : 'user-id4 ' },
120+ {'objectId' : 'user-id1 ' },
121121 ],
122122 },
123+ {'displayName' : 'test-group-3' , 'members' : [],},
123124 ]
124125 }
125126 response_mock .json = Mock (return_value = return_value )
126127 get_mock .return_value = response_mock
127128
128129 expected_result = [
129130 ('test-group-1' , ['user-id1' , 'user-id2' ]),
130- ('test-group-2' , ['user-id3' , 'user-id4' ]),
131+ ('test-group-2' , ['user-id3' , 'user-id1' ]),
132+ ('test-group-3' , []),
131133 ]
132134
133135 azure_connection = AzureConnection ()
134136
135137 assert azure_connection .get_groups_and_users () == expected_result
138+
139+
140+ @patch ('utils.azure_users.AzureConnection.get_msal_client' , Mock ())
141+ @patch ('utils.azure_users.AzureConnection.get_token' , Mock ())
142+ @patch ('utils.azure_users.AzureConnection.get_groups_and_users' )
143+ def test_get_groups_by_user_id (get_groups_and_users_mock ):
144+ get_groups_and_users_mock .return_value = [
145+ ('test-group-1' , ['user-id1' , 'user-id2' ]),
146+ ('test-group-2' , ['user-id3' , 'user-id1' ]),
147+ ]
148+
149+ azure_connection = AzureConnection ()
150+ user_id = 'user-id1'
151+ expected_result = ['test-group-1' , 'test-group-2' ]
152+ groups = azure_connection .get_groups_by_user_id ('user-id1' )
153+ assert groups == expected_result
0 commit comments