diff --git a/moto/apigateway/models.py b/moto/apigateway/models.py index fc2352e29..79295f231 100644 --- a/moto/apigateway/models.py +++ b/moto/apigateway/models.py @@ -1780,6 +1780,16 @@ class APIGatewayBackend(BaseBackend): 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 = {} for region_name in Session().get_available_regions("apigateway"): diff --git a/moto/apigateway/responses.py b/moto/apigateway/responses.py index ee890416f..6cdb22e5e 100644 --- a/moto/apigateway/responses.py +++ b/moto/apigateway/responses.py @@ -893,7 +893,7 @@ class APIGatewayResponse(BaseResponse): ) return 200, {}, json.dumps(base_path_mapping) elif self.method == "DELETE": - # TODO Implements - pass + self.backend.delete_base_path_mapping(domain_name, base_path) + return 202, {}, "" except NotFoundException as e: return self.error("NotFoundException", e.message, 404) diff --git a/tests/test_apigateway/test_apigateway.py b/tests/test_apigateway/test_apigateway.py index 9cdff407b..dbb418ed1 100644 --- a/tests/test_apigateway/test_apigateway.py +++ b/tests/test_apigateway/test_apigateway.py @@ -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["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)