GetCampaignIncidentsIdsAsOptions
Get the campaign incident IDs as option values for Multi Select field.
python · Phishing Campaign
Details
| ID | GetCampaignIncidentsIdsAsOptions |
|---|---|
| Language | python |
| From Version | 5.0.0 |
| Docker Image | demisto/python3:3.12.13.10116658 |
| Tags | field-display |
README
Get the campaign incident IDs as option values for Multi Select field.
Script Data
| Name | Description |
|---|---|
| Script Type | python3 |
| Tags | field-display |
| Cortex XSOAR Version | 5.0.0 |
Inputs
There are no inputs for this script.
Outputs
There are no outputs for this script.
import GetCampaignIncidentsIdsAsOptions from GetCampaignIncidentsIdsAsOptions import * REQUIRED_KEYS = ["id", "name", "email_from", "recipients", "severity", "status", "created"] STR_VAL_KEYS = ["name", "email_from", "recipients", "created"] NUM_OF_INCIDENTS = 5 MOCKED_INCIDENTS = [ {key.replace("_", ""): f"test_{key}_{i}" if key in STR_VAL_KEYS else i for key in REQUIRED_KEYS} for i in range(NUM_OF_INCIDENTS, 0, -1) ] def test_get_incident_ids_as_options_happy_path(mocker): """ Given: - The "Select Incidents" multi select field try to populate the available ids When: - Get the incident ids as option for info Then: - Validate the ids returned as options format for multi select field and are sorted numerically """ # prepare mocker.patch.object(demisto, "results") mocker.patch("GetCampaignIncidentsIdsAsOptions.get_campaign_incidents", return_value=MOCKED_INCIDENTS) # run GetCampaignIncidentsIdsAsOptions.main() # validate options_dict = demisto.results.call_args[0][0] ids = options_dict["options"] hidden = options_dict["hidden"] MOCKED_INCIDENTS.sort(key=lambda incident: incident["id"]) # the original order was descending assert hidden is False assert ids.pop(0) == ALL_OPTION for i in range(NUM_OF_INCIDENTS): incident_id = str(MOCKED_INCIDENTS[i]["id"]) assert incident_id == ids[i] def test_get_ids_where_no_campaign_incidents_exist(mocker): """ Given - There is no campaign in the context When - Try to get the incident ids Then - Validate the options in the result is empty """ # prepare mocker.patch.object(demisto, "results") mocker.patch.object(demisto, "debug") mocker.patch("GetCampaignIncidentsIdsAsOptions.get_campaign_incidents", return_value={}) # run GetCampaignIncidentsIdsAsOptions.main() # validate assert demisto.results.call_args[0][0] == NO_CAMPAIGN_INCIDENTS_MSG def test_there_is_no_id_in_incident(mocker): """ Given - Incident in campaign in context doesn't have id When - Try to get the ids for the multi select field Then - Validate the """ # prepare mocker.patch.object(demisto, "results") no_ids_incidents = [{"name": f"test_{i}" for i in range(NUM_OF_INCIDENTS)}] mocker.patch("GetCampaignIncidentsIdsAsOptions.get_campaign_incidents", return_value=no_ids_incidents) # run try: GetCampaignIncidentsIdsAsOptions.main() except SystemExit: assert demisto.results.call_args[0][0]["Contents"] == NO_ID_IN_CONTEXT