Ejemplo n.º 1
0
def test_get_no_update_value(mocker):
    """
    Given
    - valid response with last_modified and etag headers.

    When
    - Running get_no_update_value method.

    Then
    - Ensure that the response is False
    - Ensure that the last run is saved as expected
    """
    mocker.patch.object(demisto, 'debug')
    mocker.patch.object(demisto, 'setLastRun')

    expected_last_run = {
        'lastRun': '2018-10-24T14:13:20+00:00',
        'feed_name': {
            'last_modified': 'Fri, 30 Jul 2021 00:24:13 GMT',
            'etag': 'd309ab6e51ed310cf869dab0dfd0d34b'}
    }

    class MockResponse:
        headers = {'Last-Modified': 'Fri, 30 Jul 2021 00:24:13 GMT',  # guardrails-disable-line
                   'ETag': 'd309ab6e51ed310cf869dab0dfd0d34b'}  # guardrails-disable-line
        status_code = 200
    no_update = get_no_update_value(MockResponse(), 'feed_name')
    assert not no_update
    assert demisto.debug.call_args[0][0] == 'New indicators fetched - the Last-Modified value has been updated,' \
                                            ' createIndicators will be executed with noUpdate=False.'
    assert demisto.setLastRun.call_args[0][0] == expected_last_run
Ejemplo n.º 2
0
def test_get_no_update_value_empty_context():
    """
    Given
    - response with last_modified and etag headers.

    When
    - Running get_no_update_value method with empty integration context.

    Then
    - Ensure that the response is True.
    """
    class MockResponse:
        headers = {'last_modified': 'Fri, 30 Jul 2021 00:24:13 GMT',  # guardrails-disable-line
                   'etag': 'd309ab6e51ed310cf869dab0dfd0d34b'}  # guardrails-disable-line
    no_update = get_no_update_value(MockResponse())
    assert no_update
Ejemplo n.º 3
0
def test_get_no_update_value(mocker):
    """
    Given
    - response with last_modified and etag headers with the same values like in the integration context.

    When
    - Running get_no_update_value method.

    Then
    - Ensure that the response is False
    """
    mocker.patch.object(demisto, 'getIntegrationContext',
                        return_value={'last_modified': 'Fri, 30 Jul 2021 00:24:13 GMT',  # guardrails-disable-line
                                      'etag': 'd309ab6e51ed310cf869dab0dfd0d34b'})  # guardrails-disable-line

    class MockResponse:
        headers = {'last_modified': 'Fri, 30 Jul 2021 00:24:13 GMT',  # guardrails-disable-line
                   'etag': 'd309ab6e51ed310cf869dab0dfd0d34b'}  # guardrails-disable-line
    no_update = get_no_update_value(MockResponse())
    assert not no_update
Ejemplo n.º 4
0
def test_get_no_update_value_without_headers(mocker):
    """
    Given
    - response without last_modified and etag headers.

    When
    - Running get_no_update_value.

    Then
    - Ensure that the response is False.
    """
    mocker.patch.object(demisto, 'debug')

    class MockResponse:
        headers = {}
        status_code = 200
    no_update = get_no_update_value(MockResponse(), 'feed_name')
    assert not no_update
    assert demisto.debug.call_args[0][0] == 'Last-Modified and Etag headers are not exists,' \
                                            'createIndicators will be executed with noUpdate=False.'