APIGateway - Implement delete_base_path_mapping (#4568)
This commit is contained in:
parent
3898124112
commit
b71b6904fd
@ -1780,6 +1780,16 @@ class APIGatewayBackend(BaseBackend):
|
|||||||
|
|
||||||
return self.base_path_mappings[domain_name][base_path]
|
return self.base_path_mappings[domain_name][base_path]
|
||||||
|
|
||||||
|
def delete_base_path_mapping(self, domain_name, base_path):
|
||||||
|
|
||||||
|
if domain_name not in self.domain_names:
|
||||||
|
raise DomainNameNotFound()
|
||||||
|
|
||||||
|
if base_path not in self.base_path_mappings[domain_name]:
|
||||||
|
raise BasePathNotFoundException()
|
||||||
|
|
||||||
|
self.base_path_mappings[domain_name].pop(base_path)
|
||||||
|
|
||||||
|
|
||||||
apigateway_backends = {}
|
apigateway_backends = {}
|
||||||
for region_name in Session().get_available_regions("apigateway"):
|
for region_name in Session().get_available_regions("apigateway"):
|
||||||
|
@ -893,7 +893,7 @@ class APIGatewayResponse(BaseResponse):
|
|||||||
)
|
)
|
||||||
return 200, {}, json.dumps(base_path_mapping)
|
return 200, {}, json.dumps(base_path_mapping)
|
||||||
elif self.method == "DELETE":
|
elif self.method == "DELETE":
|
||||||
# TODO Implements
|
self.backend.delete_base_path_mapping(domain_name, base_path)
|
||||||
pass
|
return 202, {}, ""
|
||||||
except NotFoundException as e:
|
except NotFoundException as e:
|
||||||
return self.error("NotFoundException", e.message, 404)
|
return self.error("NotFoundException", e.message, 404)
|
||||||
|
@ -2627,3 +2627,74 @@ def test_get_base_path_mapping_with_unknown_base_path():
|
|||||||
)
|
)
|
||||||
ex.value.response["Error"]["Code"].should.equal("NotFoundException")
|
ex.value.response["Error"]["Code"].should.equal("NotFoundException")
|
||||||
ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(404)
|
ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(404)
|
||||||
|
|
||||||
|
|
||||||
|
@mock_apigateway
|
||||||
|
def test_delete_base_path_mapping():
|
||||||
|
client = boto3.client("apigateway", region_name="us-west-2")
|
||||||
|
domain_name = "testDomain"
|
||||||
|
test_certificate_name = "test.certificate"
|
||||||
|
client.create_domain_name(
|
||||||
|
domainName=domain_name, certificateName=test_certificate_name
|
||||||
|
)
|
||||||
|
|
||||||
|
response = client.create_rest_api(name="my_api", description="this is my api")
|
||||||
|
api_id = response["id"]
|
||||||
|
base_path = "v1"
|
||||||
|
client.create_base_path_mapping(
|
||||||
|
domainName=domain_name, restApiId=api_id, basePath=base_path
|
||||||
|
)
|
||||||
|
|
||||||
|
client.get_base_path_mapping(domainName=domain_name, basePath=base_path)
|
||||||
|
response = client.delete_base_path_mapping(
|
||||||
|
domainName=domain_name, basePath=base_path
|
||||||
|
)
|
||||||
|
response["ResponseMetadata"]["HTTPStatusCode"].should.equal(202)
|
||||||
|
|
||||||
|
with pytest.raises(ClientError) as ex:
|
||||||
|
client.get_base_path_mapping(domainName=domain_name, basePath=base_path)
|
||||||
|
|
||||||
|
ex.value.response["Error"]["Message"].should.equal(
|
||||||
|
"Invalid base path mapping identifier specified"
|
||||||
|
)
|
||||||
|
ex.value.response["Error"]["Code"].should.equal("NotFoundException")
|
||||||
|
ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(404)
|
||||||
|
|
||||||
|
|
||||||
|
@mock_apigateway
|
||||||
|
def test_delete_base_path_mapping_with_unknown_domain():
|
||||||
|
client = boto3.client("apigateway", region_name="us-west-2")
|
||||||
|
|
||||||
|
with pytest.raises(ClientError) as ex:
|
||||||
|
client.delete_base_path_mapping(domainName="unknown-domain", basePath="v1")
|
||||||
|
|
||||||
|
ex.value.response["Error"]["Message"].should.equal(
|
||||||
|
"Invalid domain name identifier specified"
|
||||||
|
)
|
||||||
|
ex.value.response["Error"]["Code"].should.equal("NotFoundException")
|
||||||
|
ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(404)
|
||||||
|
|
||||||
|
|
||||||
|
@mock_apigateway
|
||||||
|
def test_delete_base_path_mapping_with_unknown_base_path():
|
||||||
|
client = boto3.client("apigateway", region_name="us-west-2")
|
||||||
|
domain_name = "testDomain"
|
||||||
|
test_certificate_name = "test.certificate"
|
||||||
|
client.create_domain_name(
|
||||||
|
domainName=domain_name, certificateName=test_certificate_name
|
||||||
|
)
|
||||||
|
|
||||||
|
response = client.create_rest_api(name="my_api", description="this is my api")
|
||||||
|
api_id = response["id"]
|
||||||
|
client.create_base_path_mapping(
|
||||||
|
domainName=domain_name, restApiId=api_id, basePath="v1"
|
||||||
|
)
|
||||||
|
|
||||||
|
with pytest.raises(ClientError) as ex:
|
||||||
|
client.delete_base_path_mapping(domainName=domain_name, basePath="unknown")
|
||||||
|
|
||||||
|
ex.value.response["Error"]["Message"].should.equal(
|
||||||
|
"Invalid base path mapping identifier specified"
|
||||||
|
)
|
||||||
|
ex.value.response["Error"]["Code"].should.equal("NotFoundException")
|
||||||
|
ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(404)
|
||||||
|
Loading…
Reference in New Issue
Block a user