Esempio n. 1
0
def test_start_xql_query_polling_not_supported(mocker):
    """
    Given:
    - A query that has a pending status.

    When:
    - Calling get_xql_query_results_polling_command function but polling is not supported.

    Then:
    - Ensure returned command results are correct.

    """
    query = 'MOCK_QUERY'
    mock_response = {'status': 'PENDING',
                     'execution_id': 'query_id_mock',
                     'results': None}
    mocker.patch.object(CLIENT, 'start_xql_query', return_value='1234')
    mocker.patch('XQLQueryingEngine.get_xql_query_results', return_value=(mock_response, None))
    mocker.patch('XQLQueryingEngine.is_demisto_version_ge', return_value=False)
    mocker.patch.object(demisto, 'command', return_value='xdr-xql-generic-query')
    command_results = XQLQueryingEngine.start_xql_query_polling_command(CLIENT, {'query': query, 'query_name': 'mock_name'})
    assert command_results.outputs == {'status': 'PENDING',
                                       'execution_id': 'query_id_mock',
                                       'results': None,
                                       'query_name': 'mock_name'}
Esempio n. 2
0
def test_start_xql_query_polling_command(mocker):
    """
    Given:
    - A query that has a successful status and the number of results is under 1000.

    When:
    - Calling get_xql_query_results_polling_command function.

    Then:
    - Ensure returned command results are correct and integration_context was cleared.

    """
    query = 'MOCK_QUERY'
    context = {
        'mock_id': {
            'query': 'mock_query',
            'time_frame': '3 days',
            'command_name': 'previous command',
            'query_name': 'mock_name',
        }
    }
    set_integration_context(context)
    mock_response = {'status': 'SUCCESS',
                     'number_of_results': 1,
                     'query_cost': {'376699223': 0.0031591666666666665},
                     'remaining_quota': 1000.0,
                     'results': [{'x': 'test1', 'y': None}],
                     'execution_id': 'query_id_mock'}
    mocker.patch.object(CLIENT, 'start_xql_query', return_value='1234')
    mocker.patch('XQLQueryingEngine.get_xql_query_results', return_value=(mock_response, None))
    mocker.patch.object(demisto, 'command', return_value='xdr-xql-generic-query')
    mocker.patch.object(demisto, 'getIntegrationContext', side_effect=get_integration_context)
    mocker.patch.object(demisto, 'setIntegrationContext', side_effect=set_integration_context)
    command_results = XQLQueryingEngine.start_xql_query_polling_command(CLIENT, {'query': query, 'query_name': 'mock_name'})
    assert command_results.outputs == {'status': 'SUCCESS', 'number_of_results': 1, 'query_name': 'mock_name',
                                       'query_cost': {'376699223': 0.0031591666666666665}, 'remaining_quota': 1000.0,
                                       'execution_id': 'query_id_mock', 'results': [{'x': 'test1'}]}
    assert '| query_id_mock | 1 | MOCK_QUERY | 376699223: 0.0031591666666666665 | mock_name | 1000.0 | SUCCESS |' in \
           command_results.readable_output
    assert 'y' in command_results.raw_response['results'][0]
    assert get_integration_context() == context