IsListExist

Check if list exist in demisto lists.

python · Common Scripts

Details

IDIsListExist
Languagepython
From Version5.0.0
Docker Imagedemisto/python3:3.12.13.10404775
TagsCondition

README

Checks if a list exists in the Cortex XSOAR lists.

Script Data


Name Description
Script Type python3
Tags Condition

Inputs


Argument Name Description
listName The list name to check.

Outputs


There are no outputs for this script.

import demistomock as demisto
import pytest
from IsListExist import main


@pytest.mark.parametrize(
    "list_name,get_list_res,expected",
    [
        (
            "list1",
            [
                {
                    "Type": 1,
                    "Contents": "list content",
                }
            ],
            "yes",
        ),
        (
            "list2",
            [
                {
                    "Type": 4,
                    "Contents": "Item not found",
                }
            ],
            "no",
        ),
    ],
)
def test_is_list_exist(mocker, list_name, get_list_res, expected):
    """
    Given:
        - Case A: List named list1 and getList response which include the list
        - Case A: List named list2 and getList response which contains an error that list was not found

    When:
        - Running IsListExist

    Then:
        - Case A: Ensure yes is returned
        - Case B: Ensure no is returned
    """
    mocker.patch.object(
        demisto,
        "args",
        return_value={
            "listName": list_name,
        },
    )
    mocker.patch.object(demisto, "executeCommand", return_value=get_list_res)
    mocker.patch.object(demisto, "results")
    main()
    demisto.results.assert_called_with(expected)