Enhancement : API-Gateway Put Integration Response - Adding support f… (#3058)
* Enhancement : API-Gateway Put Integration Response - Adding support for contentHandling. * Added tests where the contentHandling is None also gets tested. * Linting Co-authored-by: usmankb <usman@krazybee.com> Co-authored-by: Bert Blommers <info@bertblommers.nl>
This commit is contained in:
parent
e32a60185f
commit
b1d515c929
@ -56,13 +56,21 @@ class Deployment(BaseModel, dict):
|
|||||||
|
|
||||||
|
|
||||||
class IntegrationResponse(BaseModel, dict):
|
class IntegrationResponse(BaseModel, dict):
|
||||||
def __init__(self, status_code, selection_pattern=None, response_templates=None):
|
def __init__(
|
||||||
|
self,
|
||||||
|
status_code,
|
||||||
|
selection_pattern=None,
|
||||||
|
response_templates=None,
|
||||||
|
content_handling=None,
|
||||||
|
):
|
||||||
if response_templates is None:
|
if response_templates is None:
|
||||||
response_templates = {"application/json": None}
|
response_templates = {"application/json": None}
|
||||||
self["responseTemplates"] = response_templates
|
self["responseTemplates"] = response_templates
|
||||||
self["statusCode"] = status_code
|
self["statusCode"] = status_code
|
||||||
if selection_pattern:
|
if selection_pattern:
|
||||||
self["selectionPattern"] = selection_pattern
|
self["selectionPattern"] = selection_pattern
|
||||||
|
if content_handling:
|
||||||
|
self["contentHandling"] = content_handling
|
||||||
|
|
||||||
|
|
||||||
class Integration(BaseModel, dict):
|
class Integration(BaseModel, dict):
|
||||||
@ -75,12 +83,12 @@ class Integration(BaseModel, dict):
|
|||||||
self["integrationResponses"] = {"200": IntegrationResponse(200)}
|
self["integrationResponses"] = {"200": IntegrationResponse(200)}
|
||||||
|
|
||||||
def create_integration_response(
|
def create_integration_response(
|
||||||
self, status_code, selection_pattern, response_templates
|
self, status_code, selection_pattern, response_templates, content_handling
|
||||||
):
|
):
|
||||||
if response_templates == {}:
|
if response_templates == {}:
|
||||||
response_templates = None
|
response_templates = None
|
||||||
integration_response = IntegrationResponse(
|
integration_response = IntegrationResponse(
|
||||||
status_code, selection_pattern, response_templates
|
status_code, selection_pattern, response_templates, content_handling
|
||||||
)
|
)
|
||||||
self["integrationResponses"][status_code] = integration_response
|
self["integrationResponses"][status_code] = integration_response
|
||||||
return integration_response
|
return integration_response
|
||||||
@ -959,12 +967,13 @@ class APIGatewayBackend(BaseBackend):
|
|||||||
status_code,
|
status_code,
|
||||||
selection_pattern,
|
selection_pattern,
|
||||||
response_templates,
|
response_templates,
|
||||||
|
content_handling,
|
||||||
):
|
):
|
||||||
if response_templates is None:
|
if response_templates is None:
|
||||||
raise InvalidRequestInput()
|
raise InvalidRequestInput()
|
||||||
integration = self.get_integration(function_id, resource_id, method_type)
|
integration = self.get_integration(function_id, resource_id, method_type)
|
||||||
integration_response = integration.create_integration_response(
|
integration_response = integration.create_integration_response(
|
||||||
status_code, selection_pattern, response_templates
|
status_code, selection_pattern, response_templates, content_handling
|
||||||
)
|
)
|
||||||
return integration_response
|
return integration_response
|
||||||
|
|
||||||
|
@ -387,6 +387,7 @@ class APIGatewayResponse(BaseResponse):
|
|||||||
elif self.method == "PUT":
|
elif self.method == "PUT":
|
||||||
selection_pattern = self._get_param("selectionPattern")
|
selection_pattern = self._get_param("selectionPattern")
|
||||||
response_templates = self._get_param("responseTemplates")
|
response_templates = self._get_param("responseTemplates")
|
||||||
|
content_handling = self._get_param("contentHandling")
|
||||||
integration_response = self.backend.create_integration_response(
|
integration_response = self.backend.create_integration_response(
|
||||||
function_id,
|
function_id,
|
||||||
resource_id,
|
resource_id,
|
||||||
@ -394,6 +395,7 @@ class APIGatewayResponse(BaseResponse):
|
|||||||
status_code,
|
status_code,
|
||||||
selection_pattern,
|
selection_pattern,
|
||||||
response_templates,
|
response_templates,
|
||||||
|
content_handling,
|
||||||
)
|
)
|
||||||
elif self.method == "DELETE":
|
elif self.method == "DELETE":
|
||||||
integration_response = self.backend.delete_integration_response(
|
integration_response = self.backend.delete_integration_response(
|
||||||
|
@ -544,6 +544,7 @@ def test_integration_response():
|
|||||||
selectionPattern="foobar",
|
selectionPattern="foobar",
|
||||||
responseTemplates={},
|
responseTemplates={},
|
||||||
)
|
)
|
||||||
|
|
||||||
# this is hard to match against, so remove it
|
# this is hard to match against, so remove it
|
||||||
response["ResponseMetadata"].pop("HTTPHeaders", None)
|
response["ResponseMetadata"].pop("HTTPHeaders", None)
|
||||||
response["ResponseMetadata"].pop("RetryAttempts", None)
|
response["ResponseMetadata"].pop("RetryAttempts", None)
|
||||||
@ -592,6 +593,63 @@ def test_integration_response():
|
|||||||
response = client.get_method(restApiId=api_id, resourceId=root_id, httpMethod="GET")
|
response = client.get_method(restApiId=api_id, resourceId=root_id, httpMethod="GET")
|
||||||
response["methodIntegration"]["integrationResponses"].should.equal({})
|
response["methodIntegration"]["integrationResponses"].should.equal({})
|
||||||
|
|
||||||
|
# adding a new method and perfomring put intergration with contentHandling as CONVERT_TO_BINARY
|
||||||
|
client.put_method(
|
||||||
|
restApiId=api_id, resourceId=root_id, httpMethod="PUT", authorizationType="none"
|
||||||
|
)
|
||||||
|
|
||||||
|
client.put_method_response(
|
||||||
|
restApiId=api_id, resourceId=root_id, httpMethod="PUT", statusCode="200"
|
||||||
|
)
|
||||||
|
|
||||||
|
client.put_integration(
|
||||||
|
restApiId=api_id,
|
||||||
|
resourceId=root_id,
|
||||||
|
httpMethod="PUT",
|
||||||
|
type="HTTP",
|
||||||
|
uri="http://httpbin.org/robots.txt",
|
||||||
|
integrationHttpMethod="POST",
|
||||||
|
)
|
||||||
|
|
||||||
|
response = client.put_integration_response(
|
||||||
|
restApiId=api_id,
|
||||||
|
resourceId=root_id,
|
||||||
|
httpMethod="PUT",
|
||||||
|
statusCode="200",
|
||||||
|
selectionPattern="foobar",
|
||||||
|
responseTemplates={},
|
||||||
|
contentHandling="CONVERT_TO_BINARY",
|
||||||
|
)
|
||||||
|
|
||||||
|
# this is hard to match against, so remove it
|
||||||
|
response["ResponseMetadata"].pop("HTTPHeaders", None)
|
||||||
|
response["ResponseMetadata"].pop("RetryAttempts", None)
|
||||||
|
response.should.equal(
|
||||||
|
{
|
||||||
|
"statusCode": "200",
|
||||||
|
"selectionPattern": "foobar",
|
||||||
|
"ResponseMetadata": {"HTTPStatusCode": 200},
|
||||||
|
"responseTemplates": {"application/json": None},
|
||||||
|
"contentHandling": "CONVERT_TO_BINARY",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
response = client.get_integration_response(
|
||||||
|
restApiId=api_id, resourceId=root_id, httpMethod="PUT", statusCode="200"
|
||||||
|
)
|
||||||
|
# this is hard to match against, so remove it
|
||||||
|
response["ResponseMetadata"].pop("HTTPHeaders", None)
|
||||||
|
response["ResponseMetadata"].pop("RetryAttempts", None)
|
||||||
|
response.should.equal(
|
||||||
|
{
|
||||||
|
"statusCode": "200",
|
||||||
|
"selectionPattern": "foobar",
|
||||||
|
"ResponseMetadata": {"HTTPStatusCode": 200},
|
||||||
|
"responseTemplates": {"application/json": None},
|
||||||
|
"contentHandling": "CONVERT_TO_BINARY",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@mock_apigateway
|
@mock_apigateway
|
||||||
@mock_cognitoidp
|
@mock_cognitoidp
|
||||||
|
Loading…
x
Reference in New Issue
Block a user