APIGateway - delete_method() (#4320)

This commit is contained in:
Bert Blommers 2021-09-21 15:20:46 +00:00 committed by GitHub
parent d08ed937f3
commit b95d8aaebc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 3 deletions

View File

@ -215,5 +215,5 @@ class MethodNotFoundException(NotFoundException):
def __init__(self):
super(MethodNotFoundException, self).__init__(
"NotFoundException", "Invalid method properties specified"
"NotFoundException", "Invalid Method identifier specified"
)

View File

@ -343,6 +343,9 @@ class Resource(CloudFormationModel):
raise MethodNotFoundException()
return method
def delete_method(self, method_type):
self.resource_methods.pop(method_type)
def add_integration(
self,
method_type,
@ -1118,6 +1121,10 @@ class APIGatewayBackend(BaseBackend):
method = resource.get_method(method_type)
return method.apply_operations(patch_operations)
def delete_method(self, function_id, resource_id, method_type):
resource = self.get_resource(function_id, resource_id)
resource.delete_method(method_type)
def get_authorizer(self, restapi_id, authorizer_id):
api = self.get_rest_api(restapi_id)
authorizer = api.authorizers.get(authorizer_id)

View File

@ -180,8 +180,11 @@ class APIGatewayResponse(BaseResponse):
method_type = url_path_parts[6]
if self.method == "GET":
method = self.backend.get_method(function_id, resource_id, method_type)
return 200, {}, json.dumps(method)
try:
method = self.backend.get_method(function_id, resource_id, method_type)
return 200, {}, json.dumps(method)
except NotFoundException as nfe:
return self.error("NotFoundException", nfe.message)
elif self.method == "PUT":
authorization_type = self._get_param("authorizationType")
api_key_required = self._get_param("apiKeyRequired")

View File

@ -463,6 +463,32 @@ def test_create_method_response():
response.should.equal({"ResponseMetadata": {"HTTPStatusCode": 200}})
@mock_apigateway
def test_delete_method():
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.get_method(restApiId=api_id, resourceId=root_id, httpMethod="GET")
client.delete_method(restApiId=api_id, resourceId=root_id, httpMethod="GET")
with pytest.raises(ClientError) as ex:
client.get_method(restApiId=api_id, resourceId=root_id, httpMethod="GET")
err = ex.value.response["Error"]
err["Code"].should.equal("NotFoundException")
err["Message"].should.equal("Invalid Method identifier specified")
@mock_apigateway
def test_integrations():
client = boto3.client("apigateway", region_name="us-west-2")