Esempio n. 1
0
    def test_service_response(self, flask_response_patch):
        flask_response_mock = Mock()

        flask_response_patch.return_value = flask_response_mock

        body = "this is the body"
        status_code = 200
        headers = {"Content-Type": "application/json"}

        actual_response = BaseLocalService.service_response(
            body, headers, status_code)

        flask_response_patch.assert_called_once_with("this is the body")

        self.assertEqual(actual_response.status_code, 200)
        self.assertEqual(actual_response.headers,
                         {"Content-Type": "application/json"})
Esempio n. 2
0
    def not_implemented_locally(message):
        """
        Creates a Lambda Service NotImplementedLocally Response

        Parameters
        ----------
        message str
            Message to be added to the body of the response

        Returns
        -------
        Flask.Response
            A response object representing the NotImplementedLocally Error
        """
        exception_tuple = LambdaErrorResponses.NotImplementedException

        return BaseLocalService.service_response(
            LambdaErrorResponses._construct_error_response_body(LambdaErrorResponses.LOCAL_SERVICE_ERROR, message),
            LambdaErrorResponses._construct_headers(exception_tuple[0]),
            exception_tuple[1],
        )
Esempio n. 3
0
    def invalid_request_content(message):
        """
        Creates a Lambda Service InvalidRequestContent Response

        Parameters
        ----------
        message str
            Message to be added to the body of the response

        Returns
        -------
        Flask.Response
            A response object representing the InvalidRequestContent Error
        """
        exception_tuple = LambdaErrorResponses.InvalidRequestContentException

        return BaseLocalService.service_response(
            LambdaErrorResponses._construct_error_response_body(LambdaErrorResponses.USER_ERROR, message),
            LambdaErrorResponses._construct_headers(exception_tuple[0]),
            exception_tuple[1],
        )
    def invalid_request_content(message):
        """
        Creates a Lambda Service InvalidRequestContent Response

        Parameters
        ----------
        message str
            Message to be added to the body of the response

        Returns
        -------
        Flask.Response
            A response object representing the InvalidRequestContent Error
        """
        exception_tuple = LambdaErrorResponses.InvalidRequestContentException

        return BaseLocalService.service_response(
            LambdaErrorResponses._construct_error_response_body(LambdaErrorResponses.USER_ERROR, message),
            LambdaErrorResponses._construct_headers(exception_tuple[0]),
            exception_tuple[1]
        )
Esempio n. 5
0
    def generic_service_exception(*args):
        """
        Creates a Lambda Service Generic ServiceException Response

        Parameters
        ----------
        args list
            List of arguments Flask passes to the method

        Returns
        -------
        Flask.Response
            A response object representing the GenericServiceException Error
        """
        exception_tuple = LambdaErrorResponses.ServiceException

        return BaseLocalService.service_response(
            LambdaErrorResponses._construct_error_response_body(LambdaErrorResponses.SERVICE_ERROR, "ServiceException"),
            LambdaErrorResponses._construct_headers(exception_tuple[0]),
            exception_tuple[1],
        )
    def not_implemented_locally(message):
        """
        Creates a Lambda Service NotImplementedLocally Response

        Parameters
        ----------
        message str
            Message to be added to the body of the response

        Returns
        -------
        Flask.Response
            A response object representing the NotImplementedLocally Error
        """
        exception_tuple = LambdaErrorResponses.NotImplementedException

        return BaseLocalService.service_response(
            LambdaErrorResponses._construct_error_response_body(LambdaErrorResponses.LOCAL_SERVICE_ERROR, message),
            LambdaErrorResponses._construct_headers(exception_tuple[0]),
            exception_tuple[1]
        )
    def generic_service_exception(*args):
        """
        Creates a Lambda Service Generic ServiceException Response

        Parameters
        ----------
        args list
            List of arguments Flask passes to the method

        Returns
        -------
        Flask.Response
            A response object representing the GenericServiceException Error
        """
        exception_tuple = LambdaErrorResponses.ServiceException

        return BaseLocalService.service_response(
            LambdaErrorResponses._construct_error_response_body(LambdaErrorResponses.SERVICE_ERROR, "ServiceException"),
            LambdaErrorResponses._construct_headers(exception_tuple[0]),
            exception_tuple[1]
        )
Esempio n. 8
0
    def unsupported_media_type(content_type):
        """
        Creates a Lambda Service UnsupportedMediaType Response

        Parameters
        ----------
        content_type str
            Content Type of the request that was made

        Returns
        -------
        Flask.Response
            A response object representing the UnsupportedMediaType Error
        """
        exception_tuple = LambdaErrorResponses.UnsupportedMediaTypeException

        return BaseLocalService.service_response(
            LambdaErrorResponses._construct_error_response_body(
                LambdaErrorResponses.USER_ERROR,
                "Unsupported content type: {}".format(content_type)),
            LambdaErrorResponses._construct_headers(exception_tuple[0]),
            exception_tuple[1])
Esempio n. 9
0
    def generic_method_not_allowed(*args):
        """
        Creates a Lambda Service Generic MethodNotAllowed Response

        Parameters
        ----------
        args list
            List of arguments Flask passes to the method

        Returns
        -------
        Flask.Response
            A response object representing the GenericMethodNotAllowed Error
        """
        exception_tuple = LambdaErrorResponses.MethodNotAllowedException

        return BaseLocalService.service_response(
            LambdaErrorResponses._construct_error_response_body(
                LambdaErrorResponses.LOCAL_SERVICE_ERROR,
                "MethodNotAllowedException"),
            LambdaErrorResponses._construct_headers(exception_tuple[0]),
            exception_tuple[1])
    def unsupported_media_type(content_type):
        """
        Creates a Lambda Service UnsupportedMediaType Response

        Parameters
        ----------
        content_type str
            Content Type of the request that was made

        Returns
        -------
        Flask.Response
            A response object representing the UnsupportedMediaType Error
        """
        exception_tuple = LambdaErrorResponses.UnsupportedMediaTypeException

        return BaseLocalService.service_response(
            LambdaErrorResponses._construct_error_response_body(LambdaErrorResponses.USER_ERROR,
                                                                "Unsupported content type: {}".format(content_type)),
            LambdaErrorResponses._construct_headers(exception_tuple[0]),
            exception_tuple[1]
        )
Esempio n. 11
0
    def resource_not_found(function_name):
        """
        Creates a Lambda Service ResourceNotFound Response

        Parameters
        ----------
        function_name str
            Name of the function that was requested to invoke

        Returns
        -------
        Flask.Response
            A response object representing the ResourceNotFound Error
        """
        exception_tuple = LambdaErrorResponses.ResourceNotFoundException

        return BaseLocalService.service_response(
            LambdaErrorResponses._construct_error_response_body(
                LambdaErrorResponses.USER_ERROR,
                "Function not found: arn:aws:lambda:us-west-2:012345678901:function:{}"
                .format(function_name)),
            LambdaErrorResponses._construct_headers(exception_tuple[0]),
            exception_tuple[1])
    def resource_not_found(function_name):
        """
        Creates a Lambda Service ResourceNotFound Response

        Parameters
        ----------
        function_name str
            Name of the function that was requested to invoke

        Returns
        -------
        Flask.Response
            A response object representing the ResourceNotFound Error
        """
        exception_tuple = LambdaErrorResponses.ResourceNotFoundException

        return BaseLocalService.service_response(
            LambdaErrorResponses._construct_error_response_body(
                LambdaErrorResponses.USER_ERROR,
                "Function not found: arn:aws:lambda:us-west-2:012345678901:function:{}".format(function_name)
            ),
            LambdaErrorResponses._construct_headers(exception_tuple[0]),
            exception_tuple[1]
        )