Example #1
0
def test_try_create_search_with_retry__sad(mocker):
    """
    Create an event search with a connection error first, and succesful try after

    Given:
        - Event fetch is to be created via the qradar client
    When:
        - Search first returns ConnectionError
        - Search then returns search object
    Then:
        - Assert search is created with id and status
    """
    client = QRadarClient("", {}, {"identifier": "*", "password": "******"})
    events_query = ""
    offense = RAW_RESPONSES["fetch-incidents"]
    max_retries = 0
    exception_raised = False
    mocker.patch.object(
        client,
        "search",
        side_effect=[ConnectionError, RAW_RESPONSES["qradar-searches"]])

    try:
        try_create_search_with_retry(client, events_query, offense,
                                     max_retries)
    except DemistoException:
        exception_raised = True
    assert exception_raised
Example #2
0
def test_try_create_search_with_retry__semi_happy(mocker):
    """
    Create an event search with a connection error first, and succesful try after

    Given:
        - Event fetch is to be created via the qradar client
    When:
        - Search first returns ConnectionError
        - Search then returns search object
    Then:
        - Assert search is created with id and status
    """
    client = QRadarClient("", {}, {"identifier": "*", "password": "******"})
    events_query = ""
    offense = RAW_RESPONSES["fetch-incidents"]
    max_retries = 3

    mocker.patch.object(
        client,
        "search",
        side_effect=[ConnectionError, RAW_RESPONSES["qradar-searches"]])

    actual_status, actual_id = try_create_search_with_retry(
        client, events_query, offense, max_retries)
    assert actual_status == "EXECUTE"
    assert actual_id == "a135f4cb-c22a-4b3a-aa7d-83058c219d33"