ENH: changes the behavior of delete_parameter to respond with a 400 error when the parameter does not exist.

Currently, the delete_parameter function for the ssm client will respond with a dict containing a key of Invalid Parameter which has a value of a list containing the parameter name that was requested to be deleted when a parameter with said name doesn't exist which doesn't match the behavior of boto3.
This commit is contained in:
Olabode Anise 2020-02-25 20:25:44 -05:00
parent f8af496445
commit 607e0a8452
3 changed files with 22 additions and 5 deletions

View File

@ -278,10 +278,7 @@ class SimpleSystemManagerBackend(BaseBackend):
self._region = region
def delete_parameter(self, name):
try:
del self._parameters[name]
except KeyError:
pass
return self._parameters.pop(name, None)
def delete_parameters(self, names):
result = []

View File

@ -22,7 +22,13 @@ class SimpleSystemManagerResponse(BaseResponse):
def delete_parameter(self):
name = self._get_param("Name")
self.ssm_backend.delete_parameter(name)
result = self.ssm_backend.delete_parameter(name)
if result is None:
error = {
"__type": "ParameterNotFound",
"message": "Parameter {0} not found.".format(name),
}
return json.dumps(error), dict(status=400)
return json.dumps({})
def delete_parameters(self):

View File

@ -30,6 +30,20 @@ def test_delete_parameter():
len(response["Parameters"]).should.equal(0)
@mock_ssm
def test_delete_nonexistent_parameter():
client = boto3.client("ssm", region_name="us-east-1")
try:
client.delete_parameter(Name="test_noexist")
raise RuntimeError("Should of failed")
except botocore.exceptions.ClientError as err:
err.operation_name.should.equal("DeleteParameter")
err.response["Error"]["Message"].should.equal(
"Parameter test_noexist not found."
)
@mock_ssm
def test_delete_parameters():
client = boto3.client("ssm", region_name="us-east-1")