APIGateway: add guard against no integration when adding a new response (#5416)
This commit is contained in:
parent
5519597a68
commit
3e6394e641
@ -1381,8 +1381,7 @@ class APIGatewayBackend(BaseBackend):
|
|||||||
api = self.get_rest_api(function_id)
|
api = self.get_rest_api(function_id)
|
||||||
if resource_id not in api.resources:
|
if resource_id not in api.resources:
|
||||||
raise ResourceIdNotFoundException
|
raise ResourceIdNotFoundException
|
||||||
resource = api.resources[resource_id]
|
return api.resources[resource_id]
|
||||||
return resource
|
|
||||||
|
|
||||||
def create_resource(self, function_id, parent_resource_id, path_part):
|
def create_resource(self, function_id, parent_resource_id, path_part):
|
||||||
api = self.get_rest_api(function_id)
|
api = self.get_rest_api(function_id)
|
||||||
@ -1643,10 +1642,11 @@ class APIGatewayBackend(BaseBackend):
|
|||||||
content_handling,
|
content_handling,
|
||||||
):
|
):
|
||||||
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(
|
if integration:
|
||||||
status_code, selection_pattern, response_templates, content_handling
|
return integration.create_integration_response(
|
||||||
)
|
status_code, selection_pattern, response_templates, content_handling
|
||||||
return integration_response
|
)
|
||||||
|
raise NoIntegrationResponseDefined()
|
||||||
|
|
||||||
def get_integration_response(
|
def get_integration_response(
|
||||||
self, function_id, resource_id, method_type, status_code
|
self, function_id, resource_id, method_type, status_code
|
||||||
|
@ -1055,6 +1055,36 @@ def test_put_integration_response_with_response_template():
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@mock_apigateway
|
||||||
|
def test_put_integration_response_but_integration_not_found():
|
||||||
|
client = boto3.client("apigateway", region_name="us-west-2")
|
||||||
|
response = client.create_rest_api(name="my_api", description="this is my api")
|
||||||
|
api_id = response["id"]
|
||||||
|
resources = client.get_resources(restApiId=api_id)
|
||||||
|
root_id = [resource for resource in resources["items"] if resource["path"] == "/"][
|
||||||
|
0
|
||||||
|
]["id"]
|
||||||
|
|
||||||
|
client.put_method(
|
||||||
|
restApiId=api_id, resourceId=root_id, httpMethod="GET", authorizationType="NONE"
|
||||||
|
)
|
||||||
|
client.put_method_response(
|
||||||
|
restApiId=api_id, resourceId=root_id, httpMethod="GET", statusCode="200"
|
||||||
|
)
|
||||||
|
|
||||||
|
with pytest.raises(ClientError) as ex:
|
||||||
|
client.put_integration_response(
|
||||||
|
restApiId=api_id,
|
||||||
|
resourceId=root_id,
|
||||||
|
httpMethod="GET",
|
||||||
|
statusCode="200",
|
||||||
|
selectionPattern="foobar",
|
||||||
|
responseTemplates={"application/json": json.dumps({"data": "test"})},
|
||||||
|
)
|
||||||
|
ex.value.response["Error"]["Code"].should.equal("NotFoundException")
|
||||||
|
ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(404)
|
||||||
|
|
||||||
|
|
||||||
@mock_apigateway
|
@mock_apigateway
|
||||||
def test_put_integration_validation():
|
def test_put_integration_validation():
|
||||||
client = boto3.client("apigateway", region_name="us-west-2")
|
client = boto3.client("apigateway", region_name="us-west-2")
|
||||||
|
Loading…
Reference in New Issue
Block a user