From 1698c52740c6429c1acfdf3f040a817afc2ff73f Mon Sep 17 00:00:00 2001 From: Cesar Alvernaz Date: Tue, 14 Jun 2022 11:07:30 +0100 Subject: [PATCH] APIGateway - add request parameters to integration model (#5224) --- moto/apigateway/models.py | 6 ++++++ moto/apigateway/responses.py | 2 ++ tests/test_apigateway/test_apigateway.py | 4 ++++ tests/test_apigateway/test_apigateway_integration.py | 1 + 4 files changed, 13 insertions(+) diff --git a/moto/apigateway/models.py b/moto/apigateway/models.py index 064b9c214..1d14262f1 100644 --- a/moto/apigateway/models.py +++ b/moto/apigateway/models.py @@ -131,6 +131,7 @@ class Integration(BaseModel, dict): tls_config=None, cache_namespace=None, timeout_in_millis=None, + request_parameters=None, ): super().__init__() self["type"] = integration_type @@ -146,6 +147,7 @@ class Integration(BaseModel, dict): self["tlsConfig"] = tls_config self["cacheNamespace"] = cache_namespace self["timeoutInMillis"] = timeout_in_millis + self["requestParameters"] = request_parameters def create_integration_response( self, status_code, selection_pattern, response_templates, content_handling @@ -378,6 +380,7 @@ class Resource(CloudFormationModel): tls_config=None, cache_namespace=None, timeout_in_millis=None, + request_parameters=None, ): integration_method = integration_method or method_type integration = Integration( @@ -389,6 +392,7 @@ class Resource(CloudFormationModel): tls_config=tls_config, cache_namespace=cache_namespace, timeout_in_millis=timeout_in_millis, + request_parameters=request_parameters, ) self.resource_methods[method_type]["methodIntegration"] = integration return integration @@ -1568,6 +1572,7 @@ class APIGatewayBackend(BaseBackend): tls_config=None, cache_namespace=None, timeout_in_millis=None, + request_parameters=None, ): resource = self.get_resource(function_id, resource_id) if credentials and not re.match( @@ -1609,6 +1614,7 @@ class APIGatewayBackend(BaseBackend): tls_config=tls_config, cache_namespace=cache_namespace, timeout_in_millis=timeout_in_millis, + request_parameters=request_parameters, ) return integration diff --git a/moto/apigateway/responses.py b/moto/apigateway/responses.py index cff28e84e..501c209e8 100644 --- a/moto/apigateway/responses.py +++ b/moto/apigateway/responses.py @@ -446,6 +446,7 @@ class APIGatewayResponse(BaseResponse): tls_config = self._get_param("tlsConfig") cache_namespace = self._get_param("cacheNamespace") timeout_in_millis = self._get_param("timeoutInMillis") + request_parameters = self._get_param("requestParameters") self.backend.get_method(function_id, resource_id, method_type) integration_http_method = self._get_param( @@ -465,6 +466,7 @@ class APIGatewayResponse(BaseResponse): tls_config=tls_config, cache_namespace=cache_namespace, timeout_in_millis=timeout_in_millis, + request_parameters=request_parameters, ) elif self.method == "DELETE": integration_response = self.backend.delete_integration( diff --git a/tests/test_apigateway/test_apigateway.py b/tests/test_apigateway/test_apigateway.py index 5fa38f383..647a7e1ef 100644 --- a/tests/test_apigateway/test_apigateway.py +++ b/tests/test_apigateway/test_apigateway.py @@ -520,6 +520,7 @@ def test_integrations(): passthroughBehavior="WHEN_NO_TEMPLATES", uri="http://httpbin.org/robots.txt", integrationHttpMethod="POST", + requestParameters={"integration.request.header.X-Custom": "'Custom'"}, ) # this is hard to match against, so remove it response["ResponseMetadata"].pop("HTTPHeaders", None) @@ -532,6 +533,7 @@ def test_integrations(): "uri": "http://httpbin.org/robots.txt", "passthroughBehavior": "WHEN_NO_TEMPLATES", "cacheKeyParameters": [], + "requestParameters": {"integration.request.header.X-Custom": "'Custom'"}, } ) @@ -549,6 +551,7 @@ def test_integrations(): "uri": "http://httpbin.org/robots.txt", "passthroughBehavior": "WHEN_NO_TEMPLATES", "cacheKeyParameters": [], + "requestParameters": {"integration.request.header.X-Custom": "'Custom'"}, } ) @@ -565,6 +568,7 @@ def test_integrations(): "uri": "http://httpbin.org/robots.txt", "cacheKeyParameters": [], "passthroughBehavior": "WHEN_NO_TEMPLATES", + "requestParameters": {"integration.request.header.X-Custom": "'Custom'"}, } ) diff --git a/tests/test_apigateway/test_apigateway_integration.py b/tests/test_apigateway/test_apigateway_integration.py index d58b87738..e9ec6033a 100644 --- a/tests/test_apigateway/test_apigateway_integration.py +++ b/tests/test_apigateway/test_apigateway_integration.py @@ -41,6 +41,7 @@ def test_http_integration(): type="HTTP", uri="http://httpbin.org/robots.txt", integrationHttpMethod="GET", + requestParameters={"integration.request.header.X-Custom": "'Custom'"}, ) stage_name = "staging"