From 0cff5458afe7eafa36f843425dee40b1337e2a9f Mon Sep 17 00:00:00 2001 From: usmangani1 Date: Sat, 1 May 2021 20:15:06 +0530 Subject: [PATCH] Fix : Remove Invalid request error when response-template is not specified (#3885) * Fix : Remove Invalid request error * Fix test and review commanets * Remove duplicate put_integration_template * API Gateway - Body can be None or empty Co-authored-by: Bert Blommers --- moto/apigateway/models.py | 3 --- moto/apigateway/responses.py | 4 ++++ tests/test_apigateway/test_apigateway.py | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/moto/apigateway/models.py b/moto/apigateway/models.py index d520e50ae..eea3cbfeb 100644 --- a/moto/apigateway/models.py +++ b/moto/apigateway/models.py @@ -29,7 +29,6 @@ from .exceptions import ( InvalidIntegrationArn, InvalidHttpEndpoint, InvalidResourcePathException, - InvalidRequestInput, AuthorizerNotFoundException, StageNotFoundException, RoleNotSpecified, @@ -1099,8 +1098,6 @@ class APIGatewayBackend(BaseBackend): response_templates, content_handling, ): - if response_templates is None: - raise InvalidRequestInput() integration = self.get_integration(function_id, resource_id, method_type) integration_response = integration.create_integration_response( status_code, selection_pattern, response_templates, content_handling diff --git a/moto/apigateway/responses.py b/moto/apigateway/responses.py index 1f7effcea..563db98b7 100644 --- a/moto/apigateway/responses.py +++ b/moto/apigateway/responses.py @@ -19,6 +19,7 @@ from .exceptions import ( RestAPINotFound, ModelNotFound, ApiKeyValueMinLength, + InvalidRequestInput, ) API_KEY_SOURCES = ["AUTHORIZER", "HEADER"] @@ -369,6 +370,9 @@ class APIGatewayResponse(BaseResponse): function_id, resource_id, method_type, status_code ) elif self.method == "PUT": + if not self.body: + raise InvalidRequestInput() + selection_pattern = self._get_param("selectionPattern") response_templates = self._get_param("responseTemplates") content_handling = self._get_param("contentHandling") diff --git a/tests/test_apigateway/test_apigateway.py b/tests/test_apigateway/test_apigateway.py index 481c39bfb..090e30f9b 100644 --- a/tests/test_apigateway/test_apigateway.py +++ b/tests/test_apigateway/test_apigateway.py @@ -1279,6 +1279,7 @@ def test_put_integration_response_requires_responseTemplate(): ) ex.value.response["Error"]["Code"].should.equal("BadRequestException") ex.value.response["Error"]["Message"].should.equal("Invalid request input") + # Works fine if responseTemplate is defined client.put_integration_response( restApiId=api_id,