コード例 #1
0
def test_poll_missing_field_in_root(mocker):
    """ Unit test
    Given
        - An incident without the field named 'field_name' in the root
    When
        - mock the server response to demisto.incidents().
    Then
        Validate the script returns a false value
    """
    mocker.patch.object(demisto,
                        'incidents',
                        return_value=[incident_without_field])
    args = {
        'field': 'field_name',
    }

    result = poll_field(args)

    assert result[0] in "The field does not exist."
    assert result[2]['exists'] is False
コード例 #2
0
def test_poll_field_from_root_without_regex_success(mocker):
    """ Unit test
    Given
        - An incident with the field named 'field_name' with value 'Test' in root
        - No regex argument sent to the command
    When
        - mock the server response to demisto.incidents().
    Then
        Validate the script finds the field
    """
    mocker.patch.object(demisto,
                        'incidents',
                        return_value=[incident_contains_field_in_root])
    args = {
        'field': 'field_name',
    }

    result = poll_field(args)

    assert result[0] in "The field exists."
    assert result[2]['exists'] is True
コード例 #3
0
def test_poll_missing_field_in_custom_fields(mocker):
    """ Unit test
    Given
        - An incident with the field named 'field_name' in 'CustomFields' entry with an empty value
        - No regex argument sent to the command
    When
        - mock the server response to demisto.incidents().
    Then
        Validate the script finds the field
    """
    mocker.patch.object(
        demisto,
        'incidents',
        return_value=[incident_with_empty_field_in_custom_fields])
    args = {
        'field': 'field_name',
    }

    result = poll_field(args)

    assert result[0] in "The field does not exist."
    assert result[2]['exists'] is False
コード例 #4
0
def test_poll_field_from_root_with_regex_failure(mocker):
    """ Unit test
    Given
        - An incident with the field named 'field_name' with value 'Test' in the root
        - The regex sent does not match the field value
    When
        - mock the server response to demisto.incidents().
    Then
        Validate the script returns a false value
    """
    mocker.patch.object(demisto,
                        'incidents',
                        return_value=[incident_contains_field_in_root])
    args = {
        'field': 'field_name',
        'regex': '^Testing',
    }

    result = poll_field(args)

    assert result[0] in "The field does not exist."
    assert result[2]['exists'] is False
コード例 #5
0
def test_poll_field_from_root_with_regex_success(mocker):
    """ Unit test
    Given
        - An incident with the field named 'field_name' with value 'Test' in the root
        - The regex sent is matching the field value
    When
        - mock the server response to demisto.incidents().
    Then
        Validate the script finds the field
    """
    mocker.patch.object(demisto,
                        'incidents',
                        return_value=[incident_contains_field_in_root])
    args = {
        'field': 'field_name',
        'regex': '^Test',
    }

    result = poll_field(args)

    assert result.readable_output in "The field exists."
    assert result.outputs['exists'] is True
コード例 #6
0
def test_poll_field_from_custom_fields_with_regex_failure(mocker):
    """ Unit test
    Given
        - An incident with the field named 'field_name' with value 'Test' in the 'CustomFields' entry
        - The regex sent does not match the field value
    When
        - mock the server response to demisto.incidents().
    Then
        Validate the script returns a false value
    """
    mocker.patch.object(
        demisto,
        'incidents',
        return_value=[incident_contains_field_in_custom_fields])
    args = {
        'field': 'field_name',
        'regex': 'NOT',
    }

    result = poll_field(args)

    assert result.readable_output in "The field does not exist."
    assert result.outputs['exists'] is False