@@ -52,7 +52,7 @@ def test_list(self, mocker):
5252 # Verify the make_request calls
5353 assert SyncHttpClient .make_request .call_count == 2
5454
55- # Create expected endpoint with modified URL template (orgIdentifier and projectIdentifier removed)
55+ # Create expected endpoint with modified URL template (orgIdentifier, projectIdentifier, and filterType removed)
5656 expected_endpoint = HarnessGroupMicroClient ._endpoint ['all_items' ].copy ()
5757 expected_endpoint ['url_template' ] = '/ng/api/user-groups?accountIdentifier={accountIdentifier}&pageIndex={pageIndex}&pageSize=100'
5858
@@ -245,3 +245,169 @@ def test_delete(self, mocker):
245245
246246 # Verify the result
247247 assert result is True
248+
249+ def test_list_with_filter_type (self , mocker ):
250+ '''
251+ Test listing groups with filterType parameter
252+ '''
253+ mocker .patch ('splitapiclient.http_clients.sync_client.SyncHttpClient.make_request' )
254+ sc = SyncHttpClient ('abc' , 'abc' )
255+ gmc = HarnessGroupMicroClient (sc , 'test_account' )
256+
257+ # Mock the API response for the first page
258+ first_page_data = {
259+ 'data' : {
260+ 'content' : [
261+ {
262+ 'identifier' : 'group1' ,
263+ 'name' : 'Group 1' ,
264+ 'accountIdentifier' : 'test_account' ,
265+ 'users' : []
266+ }
267+ ]
268+ }
269+ }
270+
271+ # Mock the API response for the second page (empty to end pagination)
272+ second_page_data = {
273+ 'data' : {
274+ 'content' : []
275+ }
276+ }
277+
278+ # Set up the mock to return different responses for different calls
279+ SyncHttpClient .make_request .side_effect = [first_page_data , second_page_data ]
280+
281+ # Call the method being tested with filterType
282+ result = gmc .list (filterType = 'EXCLUDE_INHERITED_GROUPS' )
283+
284+ # Verify the make_request calls
285+ assert SyncHttpClient .make_request .call_count == 2
286+
287+ # Create expected endpoint with filterType included, but orgIdentifier and projectIdentifier removed
288+ expected_endpoint = HarnessGroupMicroClient ._endpoint ['all_items' ].copy ()
289+ expected_endpoint ['url_template' ] = '/ng/api/user-groups?accountIdentifier={accountIdentifier}&pageIndex={pageIndex}&pageSize=100&filterType={filterType}'
290+
291+ SyncHttpClient .make_request .assert_any_call (
292+ expected_endpoint ,
293+ pageIndex = 0 ,
294+ accountIdentifier = 'test_account' ,
295+ filterType = 'EXCLUDE_INHERITED_GROUPS'
296+ )
297+ SyncHttpClient .make_request .assert_any_call (
298+ expected_endpoint ,
299+ pageIndex = 1 ,
300+ accountIdentifier = 'test_account' ,
301+ filterType = 'EXCLUDE_INHERITED_GROUPS'
302+ )
303+
304+ # Verify the result
305+ assert len (result ) == 1
306+ assert isinstance (result [0 ], HarnessGroup )
307+ assert result [0 ]._identifier == 'group1'
308+
309+ def test_list_with_filter_type_and_org_identifier (self , mocker ):
310+ '''
311+ Test listing groups with filterType and org_identifier parameters
312+ '''
313+ mocker .patch ('splitapiclient.http_clients.sync_client.SyncHttpClient.make_request' )
314+ sc = SyncHttpClient ('abc' , 'abc' )
315+ gmc = HarnessGroupMicroClient (sc , 'test_account' , org_identifier = 'test_org' )
316+
317+ # Mock the API response for the first page
318+ first_page_data = {
319+ 'data' : {
320+ 'content' : [
321+ {
322+ 'identifier' : 'group1' ,
323+ 'name' : 'Group 1' ,
324+ 'accountIdentifier' : 'test_account' ,
325+ 'users' : []
326+ }
327+ ]
328+ }
329+ }
330+
331+ # Mock the API response for the second page (empty to end pagination)
332+ second_page_data = {
333+ 'data' : {
334+ 'content' : []
335+ }
336+ }
337+
338+ # Set up the mock to return different responses for different calls
339+ SyncHttpClient .make_request .side_effect = [first_page_data , second_page_data ]
340+
341+ # Call the method being tested with filterType
342+ result = gmc .list (filterType = 'INCLUDE_INHERITED_GROUPS' )
343+
344+ # Verify the make_request calls
345+ assert SyncHttpClient .make_request .call_count == 2
346+
347+ # Create expected endpoint with filterType and orgIdentifier included, but projectIdentifier removed
348+ expected_endpoint = HarnessGroupMicroClient ._endpoint ['all_items' ].copy ()
349+ expected_endpoint ['url_template' ] = '/ng/api/user-groups?accountIdentifier={accountIdentifier}&orgIdentifier={orgIdentifier}&pageIndex={pageIndex}&pageSize=100&filterType={filterType}'
350+
351+ SyncHttpClient .make_request .assert_any_call (
352+ expected_endpoint ,
353+ pageIndex = 0 ,
354+ accountIdentifier = 'test_account' ,
355+ orgIdentifier = 'test_org' ,
356+ filterType = 'INCLUDE_INHERITED_GROUPS'
357+ )
358+
359+ # Verify the result
360+ assert len (result ) == 1
361+ assert isinstance (result [0 ], HarnessGroup )
362+
363+ def test_list_with_filter_type_none (self , mocker ):
364+ '''
365+ Test listing groups with filterType=None (should be omitted from URL)
366+ '''
367+ mocker .patch ('splitapiclient.http_clients.sync_client.SyncHttpClient.make_request' )
368+ sc = SyncHttpClient ('abc' , 'abc' )
369+ gmc = HarnessGroupMicroClient (sc , 'test_account' )
370+
371+ # Mock the API response for the first page
372+ first_page_data = {
373+ 'data' : {
374+ 'content' : [
375+ {
376+ 'identifier' : 'group1' ,
377+ 'name' : 'Group 1' ,
378+ 'accountIdentifier' : 'test_account' ,
379+ 'users' : []
380+ }
381+ ]
382+ }
383+ }
384+
385+ # Mock the API response for the second page (empty to end pagination)
386+ second_page_data = {
387+ 'data' : {
388+ 'content' : []
389+ }
390+ }
391+
392+ # Set up the mock to return different responses for different calls
393+ SyncHttpClient .make_request .side_effect = [first_page_data , second_page_data ]
394+
395+ # Call the method being tested with filterType=None (explicit)
396+ result = gmc .list (filterType = None )
397+
398+ # Verify the make_request calls
399+ assert SyncHttpClient .make_request .call_count == 2
400+
401+ # Create expected endpoint with filterType removed (since it's None)
402+ expected_endpoint = HarnessGroupMicroClient ._endpoint ['all_items' ].copy ()
403+ expected_endpoint ['url_template' ] = '/ng/api/user-groups?accountIdentifier={accountIdentifier}&pageIndex={pageIndex}&pageSize=100'
404+
405+ SyncHttpClient .make_request .assert_any_call (
406+ expected_endpoint ,
407+ pageIndex = 0 ,
408+ accountIdentifier = 'test_account'
409+ )
410+
411+ # Verify the result
412+ assert len (result ) == 1
413+ assert isinstance (result [0 ], HarnessGroup )
0 commit comments