Cloudfront: correct create_invalidation API response (#6387)

This commit is contained in:
Daniel Gomes-Sebastiao 2023-06-11 06:31:38 +12:00 committed by GitHub
parent 7b4cd492ff
commit 6d9f4646c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 2 deletions

View File

@ -14,7 +14,7 @@ class CloudFrontResponse(BaseResponse):
super().__init__(service_name="cloudfront")
def _get_xml_body(self) -> Dict[str, Any]:
return xmltodict.parse(self.body, dict_constructor=dict)
return xmltodict.parse(self.body, dict_constructor=dict, force_list="Path")
@property
def backend(self) -> CloudFrontBackend:

View File

@ -5,7 +5,36 @@ import sure # noqa # pylint: disable=unused-import
@mock_cloudfront
def test_create_invalidation():
def test_create_invalidation_with_single_path():
client = boto3.client("cloudfront", region_name="us-west-1")
config = scaffold.example_distribution_config("ref")
resp = client.create_distribution(DistributionConfig=config)
dist_id = resp["Distribution"]["Id"]
resp = client.create_invalidation(
DistributionId=dist_id,
InvalidationBatch={
"Paths": {"Quantity": 1, "Items": ["/path1"]},
"CallerReference": "ref2",
},
)
resp.should.have.key("Location")
resp.should.have.key("Invalidation")
resp["Invalidation"].should.have.key("Id")
resp["Invalidation"].should.have.key("Status").equals("COMPLETED")
resp["Invalidation"].should.have.key("CreateTime")
resp["Invalidation"].should.have.key("InvalidationBatch").equals(
{
"Paths": {"Quantity": 1, "Items": ["/path1"]},
"CallerReference": "ref2",
}
)
@mock_cloudfront
def test_create_invalidation_with_multiple_paths():
client = boto3.client("cloudfront", region_name="us-west-1")
config = scaffold.example_distribution_config("ref")
resp = client.create_distribution(DistributionConfig=config)