def test_handler_success(
        sm_describe_endpoint_config_params, sm_create_endpoint_config_params,
        sm_create_endpoint_config_response, cp_expected_params,
        sm_describe_endpoint_params, sm_create_endpoint_params,
        sm_create_endpoint_response, sm_describe_endpoint_response_2, event):

    sm_client = get_client("sagemaker")
    cp_client = get_client("codepipeline")

    sm_stubber = Stubber(sm_client)
    cp_stubber = Stubber(cp_client)

    # endpoint config creation
    sm_describe_endpoint_config_response = {}

    cp_response = {}

    sm_stubber.add_client_error(
        "describe_endpoint_config",
        service_error_code="EndpointConfigExists",
        service_message="Could not find endpoint configuration",
        http_status_code=400,
        expected_params=sm_describe_endpoint_config_params,
    )
    sm_stubber.add_response(
        "create_endpoint_config",
        sm_create_endpoint_config_response,
        sm_create_endpoint_config_params,
    )

    # endpoint creation
    sm_stubber.add_client_error(
        "describe_endpoint",
        service_error_code="EndpointExists",
        service_message="Could not find endpoint",
        http_status_code=400,
        expected_params=sm_describe_endpoint_params,
    )

    sm_stubber.add_response("create_endpoint", sm_create_endpoint_response,
                            sm_create_endpoint_params)

    sm_stubber.add_response(
        "describe_endpoint",
        sm_describe_endpoint_response_2,
        sm_describe_endpoint_params,
    )

    cp_stubber.add_response("put_job_success_result", cp_response,
                            cp_expected_params)

    expected_log_message = (
        "Sent success message back to codepipeline with job_id: test_job_id")
    with sm_stubber:
        with cp_stubber:
            handler(event, {})
            cp_stubber.assert_no_pending_responses()
            reset_client()
示例#2
0
def test_handler_success(sm_expected_params, sm_response_200, event):
    sm_client = get_client("sagemaker")
    sm_stubber = Stubber(sm_client)

    # success path
    sm_stubber.add_response("create_transform_job", sm_response_200,
                            sm_expected_params)

    with sm_stubber:
        handler(event, {})
        reset_client()
示例#3
0
def test_handler_fail(sm_expected_params, sm_response_500, event):
    sm_client = get_client("sagemaker")
    sm_stubber = Stubber(sm_client)

    # fail path
    sm_stubber.add_response("create_transform_job", sm_response_500,
                            sm_expected_params)

    with pytest.raises(Exception):
        handler(event, {})

    reset_client()
def test_handler_success(
    sm_create_baseline_expected_params,
    sm_create_job_response_200,
    event,
):

    sm_client = get_client("sagemaker")
    sm_stubber = Stubber(sm_client)

    # success path
    sm_stubber.add_response("create_processing_job", sm_create_job_response_200, sm_create_baseline_expected_params)

    with sm_stubber:
        handler(event, {})
        reset_client()
示例#5
0
def test_handler_success(
    sm_create_monitoring_expected_params,
    sm_create_monitoring_response_200,
    sm_describe_monitoring_schedule_response,
    cp_expected_params_success,
    sm_describe_monitoring_scheduale_params,
    event,
):

    sm_client = get_client("sagemaker")
    cp_client = get_client("codepipeline")

    sm_stubber = Stubber(sm_client)
    cp_stubber = Stubber(cp_client)

    cp_response = {}

    # job creation
    sm_stubber.add_client_error(
        "describe_monitoring_schedule",
        service_error_code="MonitorJobExists",
        service_message="Could not find requested job with name",
        http_status_code=400,
        expected_params=sm_describe_monitoring_scheduale_params,
    )

    # success path
    sm_stubber.add_response("create_monitoring_schedule",
                            sm_create_monitoring_response_200,
                            sm_create_monitoring_expected_params)

    sm_stubber.add_response(
        "describe_monitoring_schedule",
        sm_describe_monitoring_schedule_response,
        sm_describe_monitoring_scheduale_params,
    )

    cp_stubber.add_response("put_job_success_result", cp_response,
                            cp_expected_params_success)

    with sm_stubber:
        with cp_stubber:
            handler(event, {})
            cp_stubber.assert_no_pending_responses()
            reset_client()
示例#6
0
def test_handler_failure(lm_expected_params, lm_response_500,
                         cp_expected_params_failure, event):
    lm_client = get_client("lambda")
    lm_stubber = Stubber(lm_client)
    cp_client = get_client("codepipeline")
    cp_stubber = Stubber(cp_client)

    cp_response = {}

    lm_stubber.add_response("update_function_configuration", lm_response_500,
                            lm_expected_params)
    cp_stubber.add_response("put_job_failure_result", cp_response,
                            cp_expected_params_failure)

    with lm_stubber:
        with cp_stubber:
            handler(event, {})
            cp_stubber.assert_no_pending_responses()
            reset_client()
def test_handler_fail(sm_expected_params, sm_response_500,
                      cp_expected_params_failure, event):
    sm_client = get_client("sagemaker")
    cp_client = get_client("codepipeline")

    sm_stubber = Stubber(sm_client)
    cp_stubber = Stubber(cp_client)

    cp_response = {}
    # fail path
    sm_stubber.add_response("create_transform_job", sm_response_500,
                            sm_expected_params)
    cp_stubber.add_response("put_job_failure_result", cp_response,
                            cp_expected_params_failure)

    with sm_stubber:
        with cp_stubber:
            handler(event, {})
            cp_stubber.assert_no_pending_responses()
            reset_client()
def test_handler_success(
    sm_describe_model_expected_params,
    sm_describe_model_response,
    sm_delete_model_expected_params,
    sm_create_model_expected_params,
    sm_create_model_response,
    cp_expected_params,
    event,
):

    sm_client = get_client("sagemaker")
    cp_client = get_client("codepipeline")

    sm_stubber = Stubber(sm_client)
    cp_stubber = Stubber(cp_client)

    # describe model

    sm_stubber.add_response("describe_model", sm_describe_model_response, sm_describe_model_expected_params)

    # delete model
    sm_delete_model_response = {}
    sm_stubber.add_response("delete_model", sm_delete_model_response, sm_delete_model_expected_params)

    # create model
    sm_stubber.add_response("create_model", sm_create_model_response, sm_create_model_expected_params)

    # codepipeline
    cp_response = {}
    cp_stubber.add_response("put_job_success_result", cp_response, cp_expected_params)

    with sm_stubber:
        with cp_stubber:
            handler(event, {})
            cp_stubber.assert_no_pending_responses()
            reset_client()
示例#9
0
def test_reset_client(service):
    get_client(service)
    reset_client()
    assert _helpers_service_clients == dict()
def test_handler_exception(event):
    with patch("boto3.client"):
        handler(event, context={})
        reset_client()