def side_effect(*args, **kwargs):
     err = mocker.MagicMock(spec=HTTPError)
     resp = mocker.MagicMock(spec=Response)
     resp.text = "TEST_ERR"
     err.response = resp
     err.response.request = mocker.MagicMock(spec=Request)
     raise Py42NotFoundError(err)
Esempio n. 2
0
def test_show_when_alert_not_found_output_expected_error_message(
        cli_state, runner, custom_error):
    cli_state.sdk.alerts.get_details.side_effect = Py42NotFoundError(
        custom_error)
    result = runner.invoke(cli, ["alerts", "show", "TEST-ALERT-ID"],
                           obj=cli_state)
    assert "No alert found with ID 'TEST-ALERT-ID'." in result.output
Esempio n. 3
0
def mock_post_not_found_session(mocker, mock_connection):
    response = mocker.MagicMock(spec=Response)
    response.status_code = 404
    exception = mocker.MagicMock(spec=HTTPError)
    exception.response = response
    mock_connection.post.side_effect = Py42NotFoundError(exception)
    return mock_connection
Esempio n. 4
0
def test_show_when_py42_raises_exception_prints_error_message(
        runner, cli_state, custom_error):
    cli_state.sdk.cases.file_events.get_all.side_effect = Py42NotFoundError(
        custom_error)
    result = runner.invoke(
        cli,
        ["cases", "show", "1", "--include-file-events"],
        obj=cli_state,
    )
    cli_state.sdk.cases.file_events.get_all.assert_called_once_with(1)
    assert "Invalid case-number 1." in result.output
Esempio n. 5
0
def mock_detection_list_post_failure_when_invalid_rule_id(
    mocker, mock_connection, py42_response
):
    response = mocker.MagicMock(spec=Response)
    response.status_code = 400
    exception = mocker.MagicMock(spec=Py42NotFoundError)
    exception.response = response
    mock_connection.post.side_effect = Py42NotFoundError(exception, "")
    detection_list_user_service = mocker.MagicMock(spec=DetectionListUserService)
    detection_list_user_service.get_by_id.return_value = py42_response
    return detection_list_user_service
Esempio n. 6
0
def test_file_events_remove_when_py42_raises_exception_returns_error_message(
        runner, cli_state, error):
    cli_state.sdk.cases.file_events.delete.side_effect = Py42NotFoundError(
        error)
    result = runner.invoke(
        cli,
        ["cases", "file-events", "remove", "1", "--event-id", "1"],
        obj=cli_state,
    )
    cli_state.sdk.cases.file_events.delete.assert_called_once_with(1, "1")
    assert "Invalid case-number or event-id." in result.output
Esempio n. 7
0
def test_rename_when_guid_not_found_py42_raises_exception_prints_error(
        runner, cli_state, custom_error):
    cli_state.sdk.devices.get_settings.side_effect = Py42NotFoundError(
        custom_error)

    result = runner.invoke(
        cli,
        [
            "devices",
            "rename",
            TEST_DEVICE_GUID,
            "--new-device-name",
            TEST_NEW_DEVICE_NAME,
        ],
        obj=cli_state,
    )
    cli_state.sdk.devices.get_settings.assert_called_once_with(
        TEST_DEVICE_GUID)
    assert result.exit_code == 1
    assert (f"Error: The device with GUID '{TEST_DEVICE_GUID}' was not found."
            in result.output)
Esempio n. 8
0
def deactivate_device_not_found_failure(cli_state):
    cli_state.sdk.devices.deactivate.side_effect = Py42NotFoundError(
        HTTPError())
Esempio n. 9
0
def reactivate_device_not_found_failure(cli_state, custom_error):
    cli_state.sdk.devices.reactivate.side_effect = Py42NotFoundError(
        custom_error)