示例#1
0
def test_get_insight_with_unknown_id(requests_mock):
    from Cognni import Client, get_insight_command

    mock_response = util_load_json(
        'test_data/get_insight_with_unknown_id.json')
    requests_mock.post('https://localhost/intelligence/data/graphql',
                       json=mock_response)

    client = Client(base_url='https://localhost',
                    verify=False,
                    headers={'Authorization': 'Bearer some_api_key'})

    insight_id = '1234'
    args = {"insight_id": insight_id}
    response = get_insight_command(client, args)

    assert response.raw_response['id'] is None
示例#2
0
def test_get_event_with_unknown_id(requests_mock):
    from Cognni import Client, get_event_command

    mock_response = util_load_json('test_data/get_event_with_unknown_id.json')
    requests_mock.post('https://localhost/intelligence/data/graphql',
                       json=mock_response)

    client = Client(base_url='https://localhost',
                    verify=False,
                    headers={'Authorization': 'Bearer some_api_key'})

    event_id = 'df247df1-dd27-4bba-ac04-bc7d5dbf414d'
    args = {"event_id": event_id}
    response = get_event_command(client, args)

    # assert response.outputs[0] == mock_response
    assert response.raw_response is None
示例#3
0
def test_fetch_insight_with_large_severity(requests_mock):
    from Cognni import Client, fetch_insights_command

    mock_response = util_load_json(
        'test_data/fetch_insights_with_large_severity.json')
    requests_mock.post('https://localhost/intelligence/data/graphql',
                       json=mock_response)

    client = Client(base_url='https://localhost',
                    verify=False,
                    headers={'Authorization': 'Bearer some_api_key'})

    min_severity = 10
    args = {"min_severity": min_severity}
    response = fetch_insights_command(client, args)

    assert response.outputs_prefix == 'Cognni.insights'
    assert len(response.raw_response) == 0
示例#4
0
def test_get_event_with_whitespace(requests_mock):
    """Tests the get event command when event id contains whitespaces
    """
    from Cognni import Client, get_event_command

    mock_response = util_load_json('test_data/get_event_with_whitespace.json')
    requests_mock.post('https://localhost/intelligence/data/graphql',
                       json=mock_response)

    client = Client(base_url='https://localhost',
                    verify=False,
                    headers={'Authorization': 'Bearer some_api_key'})

    event_id = 'Test with whitespaces'
    args = {"event_id": event_id}
    response = get_event_command(client, args)

    # assert response.outputs[0] == mock_response
    assert response.raw_response is None
示例#5
0
def test_get_insight_with_special_characters(requests_mock):
    """Tests the get insight command with unexist insight id
      """
    from Cognni import Client, get_insight_command

    mock_response = util_load_json(
        'test_data/get_insight_with_special_characters.json')
    requests_mock.post('https://localhost/intelligence/data/graphql',
                       json=mock_response)

    client = Client(base_url='https://localhost',
                    verify=False,
                    headers={'Authorization': 'Bearer some_api_key'})

    insight_id = 'a!@#$%^&*()1'
    args = {"insight_id": insight_id}
    response = get_insight_command(client, args)

    assert response.raw_response['id'] is None
示例#6
0
def test_get_insight(requests_mock):
    """Tests the get insight command
    """
    from Cognni import Client, get_insight_command

    mock_response = util_load_json('test_data/get_insight.json')
    requests_mock.post('https://localhost/intelligence/data/graphql',
                       json=mock_response)

    client = Client(base_url='https://localhost',
                    verify=False,
                    headers={'Authorization': 'Bearer some_api_key'})

    insight_id = '740b5296-6d62-41e5-b0d7-1a7d5081f9cb'
    args = {"insight_id": insight_id}
    response = get_insight_command(client, args)

    # assert response.outputs[0] == mock_response
    assert response.outputs_prefix == 'Cognni.insight'
    assert response.raw_response['id'] == insight_id
示例#7
0
def test_fetch_incidents(requests_mock):
    """Tests the fetch-incidents function
    """
    from Cognni import Client, fetch_incidents

    mock_response = util_load_json('test_data/fetch_incidents.json')
    requests_mock.post('https://localhost/intelligence/data/graphql',
                       json=mock_response)

    client = Client(base_url='https://localhost',
                    verify=False,
                    headers={'Authorization': 'Bearer some_api_key'})

    first_fetch_time = 1600000000
    last_run = {}
    min_severity = 0
    next_run, incidents = fetch_incidents(client=client,
                                          events_limit=10,
                                          first_fetch_time=first_fetch_time,
                                          last_run=last_run,
                                          min_severity=min_severity)

    assert next_run['last_fetch'] > first_fetch_time
    assert len(incidents) == 8