def test_request_with_no_data(self, flask_request):
        flask_request.get_data.return_value = None
        flask_request.headers = {}
        flask_request.content_type = 'application/json'
        flask_request.args = {}

        response = LocalLambdaInvokeService.validate_request()

        self.assertIsNone(response)
    def test_request_with_no_data(self, flask_request):
        flask_request.get_data.return_value = None
        flask_request.headers = {}
        flask_request.content_type = 'application/json'
        flask_request.args = {}

        response = LocalLambdaInvokeService.validate_request()

        self.assertIsNone(response)
    def test_request_invocation_type_not_ResponseRequest(self, flask_request, lambda_error_responses_mock):
        flask_request.get_data.return_value = None
        flask_request.headers = {'X-Amz-Invocation-Type': 'DryRun'}
        flask_request.content_type = 'application/json'
        flask_request.args = {}

        lambda_error_responses_mock.not_implemented_locally.return_value = "NotImplementedLocally"

        response = LocalLambdaInvokeService.validate_request()

        self.assertEquals(response, "NotImplementedLocally")

        lambda_error_responses_mock.not_implemented_locally.assert_called_once_with(
            "invocation-type: DryRun is not supported. RequestResponse is only supported.")
    def test_request_with_content_type_not_application_json(self, flask_request, lambda_error_responses_mock):
        flask_request.get_data.return_value = None
        flask_request.headers = {}
        flask_request.content_type = 'image/gif'
        flask_request.args = {}

        lambda_error_responses_mock.unsupported_media_type.return_value = "UnsupportedMediaType"

        response = LocalLambdaInvokeService.validate_request()

        self.assertEquals(response, "UnsupportedMediaType")

        lambda_error_responses_mock.unsupported_media_type.assert_called_once_with(
            "image/gif")
    def test_request_with_query_strings(self, flask_request, lambda_error_responses_mock):
        flask_request.get_data.return_value = None
        flask_request.headers = {}
        flask_request.content_type = 'application/json'
        flask_request.args = {"key": "value"}

        lambda_error_responses_mock.invalid_request_content.return_value = "InvalidRequestContent"

        response = LocalLambdaInvokeService.validate_request()

        self.assertEquals(response, "InvalidRequestContent")

        lambda_error_responses_mock.invalid_request_content.assert_called_once_with(
            "Query Parameters are not supported")
    def test_request_invocation_type_not_ResponseRequest(self, flask_request, lambda_error_responses_mock):
        flask_request.get_data.return_value = None
        flask_request.headers = {'X-Amz-Invocation-Type': 'DryRun'}
        flask_request.content_type = 'application/json'
        flask_request.args = {}

        lambda_error_responses_mock.not_implemented_locally.return_value = "NotImplementedLocally"

        response = LocalLambdaInvokeService.validate_request()

        self.assertEquals(response, "NotImplementedLocally")

        lambda_error_responses_mock.not_implemented_locally.assert_called_once_with(
            "invocation-type: DryRun is not supported. RequestResponse is only supported.")
    def test_request_with_query_strings(self, flask_request, lambda_error_responses_mock):
        flask_request.get_data.return_value = None
        flask_request.headers = {}
        flask_request.content_type = 'application/json'
        flask_request.args = {"key": "value"}

        lambda_error_responses_mock.invalid_request_content.return_value = "InvalidRequestContent"

        response = LocalLambdaInvokeService.validate_request()

        self.assertEquals(response, "InvalidRequestContent")

        lambda_error_responses_mock.invalid_request_content.assert_called_once_with(
            "Query Parameters are not supported")
    def test_request_with_non_json_data(self, flask_request, lambda_error_responses_mock):
        flask_request.get_data.return_value = b'notat:asdfasdf'
        flask_request.headers = {}
        flask_request.content_type = 'application/json'
        flask_request.args = {}

        lambda_error_responses_mock.invalid_request_content.return_value = "InvalidRequestContent"

        response = LocalLambdaInvokeService.validate_request()

        self.assertEquals(response, "InvalidRequestContent")

        expected_called_with = "Could not parse request body into json: No JSON object could be decoded"

        lambda_error_responses_mock.invalid_request_content.assert_called_once_with(expected_called_with)
Exemplo n.º 9
0
    def test_request_log_type_not_None(self, flask_request,
                                       lambda_error_responses_mock):
        flask_request.get_data.return_value = None
        flask_request.headers = {"X-Amz-Log-Type": "Tail"}
        flask_request.content_type = "application/json"
        flask_request.args = {}

        lambda_error_responses_mock.not_implemented_locally.return_value = "NotImplementedLocally"

        response = LocalLambdaInvokeService.validate_request()

        self.assertEqual(response, "NotImplementedLocally")

        lambda_error_responses_mock.not_implemented_locally.assert_called_once_with(
            "log-type: Tail is not supported. None is only supported.")
    def test_request_with_non_json_data(self, flask_request, lambda_error_responses_mock):
        flask_request.get_data.return_value = b'notat:asdfasdf'
        flask_request.headers = {}
        flask_request.content_type = 'application/json'
        flask_request.args = {}

        lambda_error_responses_mock.invalid_request_content.return_value = "InvalidRequestContent"

        response = LocalLambdaInvokeService.validate_request()

        self.assertEquals(response, "InvalidRequestContent")

        expected_called_with = "Could not parse request body into json: No JSON object could be decoded"

        lambda_error_responses_mock.invalid_request_content.assert_called_once_with(expected_called_with)