APIGateway - delete_method() (#4320)
This commit is contained in:
parent
d08ed937f3
commit
b95d8aaebc
@ -215,5 +215,5 @@ class MethodNotFoundException(NotFoundException):
|
|||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(MethodNotFoundException, self).__init__(
|
super(MethodNotFoundException, self).__init__(
|
||||||
"NotFoundException", "Invalid method properties specified"
|
"NotFoundException", "Invalid Method identifier specified"
|
||||||
)
|
)
|
||||||
|
@ -343,6 +343,9 @@ class Resource(CloudFormationModel):
|
|||||||
raise MethodNotFoundException()
|
raise MethodNotFoundException()
|
||||||
return method
|
return method
|
||||||
|
|
||||||
|
def delete_method(self, method_type):
|
||||||
|
self.resource_methods.pop(method_type)
|
||||||
|
|
||||||
def add_integration(
|
def add_integration(
|
||||||
self,
|
self,
|
||||||
method_type,
|
method_type,
|
||||||
@ -1118,6 +1121,10 @@ class APIGatewayBackend(BaseBackend):
|
|||||||
method = resource.get_method(method_type)
|
method = resource.get_method(method_type)
|
||||||
return method.apply_operations(patch_operations)
|
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):
|
def get_authorizer(self, restapi_id, authorizer_id):
|
||||||
api = self.get_rest_api(restapi_id)
|
api = self.get_rest_api(restapi_id)
|
||||||
authorizer = api.authorizers.get(authorizer_id)
|
authorizer = api.authorizers.get(authorizer_id)
|
||||||
|
@ -180,8 +180,11 @@ class APIGatewayResponse(BaseResponse):
|
|||||||
method_type = url_path_parts[6]
|
method_type = url_path_parts[6]
|
||||||
|
|
||||||
if self.method == "GET":
|
if self.method == "GET":
|
||||||
method = self.backend.get_method(function_id, resource_id, method_type)
|
try:
|
||||||
return 200, {}, json.dumps(method)
|
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":
|
elif self.method == "PUT":
|
||||||
authorization_type = self._get_param("authorizationType")
|
authorization_type = self._get_param("authorizationType")
|
||||||
api_key_required = self._get_param("apiKeyRequired")
|
api_key_required = self._get_param("apiKeyRequired")
|
||||||
|
@ -463,6 +463,32 @@ def test_create_method_response():
|
|||||||
response.should.equal({"ResponseMetadata": {"HTTPStatusCode": 200}})
|
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
|
@mock_apigateway
|
||||||
def test_integrations():
|
def test_integrations():
|
||||||
client = boto3.client("apigateway", region_name="us-west-2")
|
client = boto3.client("apigateway", region_name="us-west-2")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user