Esempio n. 1
0
def test_offset_cyble_vision_fetch_detail(requests_mock, capfd):
    """
    Tests the cyble_vision_fetch_detail command for failure

    Configures requests_mock instance to generate the appropriate cyble_vision_fetch_detail
    API response when the correct cyble_vision_fetch_detail API request is performed. Checks
    the output of the command function with the expected output.

    :param requests_mock:
    :return:
    """
    from CybleEvents import Client, fetch_alert_details

    mock_response_1 = load_json_file("dummy_fetch_detail.json")

    requests_mock.post('https://test.com/api/v2/events/eType/eID',
                       json=mock_response_1)

    client = Client(base_url='https://test.com', verify=False)

    args = {
        'token': 'some_random_token',
        'event_type': 'eType',
        'event_id': 'eID',
        'from': '-1',
        'limit': 1
    }

    with capfd.disabled():
        with pytest.raises(ValueError,
                           match="Parameter having negative value, from: -1'"):
            fetch_alert_details(client=client, args=args)
Esempio n. 2
0
def test_cyble_vision_fetch_detail(requests_mock, eID, eType):
    """
    Tests the cyble_vision_fetch_detail command

    Configures requests_mock instance to generate the appropriate cyble_vision_fetch_detail
    API response when the correct cyble_vision_fetch_detail API request is performed. Checks
    the output of the command function with the expected output.

    :param requests_mock:
    :return:
    """
    from CybleEvents import Client, fetch_alert_details

    mock_response_1 = load_json_file("dummy_fetch_detail.json")

    requests_mock.post('https://test.com/api/v2/events/{}/{}'.format(
        eType, eID),
                       json=mock_response_1)

    client = Client(base_url='https://test.com', verify=False)

    args = {'token': 'some_random_token', 'event_type': eType, 'event_id': eID}

    response = fetch_alert_details(client=client, args=args).outputs

    assert isinstance(response, dict)
    assert isinstance(response['events'], list)

    for i, el in enumerate(response['events']):
        assert el['id'] == i + 1
        assert el['eventtitle'] == 'some_event_title_{0}'.format(i + 1)
        assert el['createdat'] == '2020-06-15T07:34:20.062000'
        assert el['modified'] == 'Mar 01 2022'
        assert el['type'] == 'some_type_{0}'.format(i + 1)
        assert el['indicator'] == 'some_indicator_{0}'.format(i + 1)
        assert el['references'] == ''
        assert el['lastseenon'] == '2022-03-02'