@@ -4451,6 +4451,62 @@ def test_get_remote_detection_data_for_multiple_types(mocker, detection_type, in
4451
4451
}
4452
4452
4453
4453
4454
+ @pytest .mark .parametrize (
4455
+ "function_name, num_ids, expected_calls" ,
4456
+ [
4457
+ # These are two different functions - calling both of them to verify the call architecture applies to both.
4458
+ ("get_detections_entities" , 0 , 0 ), # Edge case: no IDs
4459
+ ("get_detections_entities" , 500 , 1 ), # Less than the limit
4460
+ ("get_detections_entities" , 1000 , 1 ), # Exactly the limit
4461
+ ("get_detections_entities" , 1001 , 2 ), # More than the limit (specific request)
4462
+ ("get_detections_entities" , 2500 , 3 ), # More than the limit (many calls)
4463
+ ("get_detection_entities" , 0 , 0 ),
4464
+ ("get_detection_entities" , 500 , 1 ),
4465
+ ("get_detection_entities" , 1000 , 1 ),
4466
+ ("get_detection_entities" , 1001 , 2 ),
4467
+ ("get_detection_entities" , 2500 , 3 ),
4468
+ ],
4469
+ )
4470
+ def test_get_detections_entities_batches_requests (mocker , function_name , num_ids , expected_calls ):
4471
+ """
4472
+ Given
4473
+ - Number of ID's to fetch from the CrowdStrike Falcon Entity API.
4474
+ When
4475
+ - Running fetch detections entities functions with the ID's list
4476
+ Then
4477
+ - Return the number of calls to http_request based on the number of IDs provided.
4478
+ - Return the number of resources based on the number of IDs provided.
4479
+ """
4480
+ import CrowdStrikeFalcon
4481
+
4482
+ mock_http_request = mocker .patch .object (CrowdStrikeFalcon , "http_request" )
4483
+
4484
+ # Configure a side effect to return responses with the correct number of resources
4485
+ def side_effect (method , url , data ):
4486
+ data_dict = json .loads (data )
4487
+ ids_in_batch = data_dict .get ("composite_ids" ) or data_dict .get ("ids" )
4488
+ return {"meta" : {"trace_id" : "test_trace" }, "resources" : [{"id" : i } for i in ids_in_batch ]}
4489
+
4490
+ mock_http_request .side_effect = side_effect
4491
+
4492
+ # Get the function to test dynamically
4493
+ function_to_test = getattr (CrowdStrikeFalcon , function_name )
4494
+
4495
+ # Load and slice the IDs list from the JSON file
4496
+ id_list_full = load_json ("./test_data/mock_detections_id_list.json" ).get ("Ids" , {})[:num_ids ]
4497
+ detections_ids = id_list_full [:num_ids ]
4498
+
4499
+ # Call the function with the mock IDs
4500
+ result = function_to_test (detections_ids )
4501
+
4502
+ # Check that the number of http_request calls matches the expectation
4503
+ assert mock_http_request .call_count == expected_calls
4504
+
4505
+ # Check that the number of resources returned matches the number of IDs
4506
+ if "resources" in result :
4507
+ assert len (result ["resources" ]) == num_ids
4508
+
4509
+
4454
4510
@pytest .mark .parametrize ("updated_object, entry_content, close_incident" , input_data .set_xsoar_incident_entries_args )
4455
4511
def test_set_xsoar_entries__incident (mocker , updated_object , entry_content , close_incident ):
4456
4512
"""
0 commit comments