From 6d9f4646c1c807c6ea7b77ad5f76e59849190d2e Mon Sep 17 00:00:00 2001 From: Daniel Gomes-Sebastiao Date: Sun, 11 Jun 2023 06:31:38 +1200 Subject: [PATCH] Cloudfront: correct create_invalidation API response (#6387) --- moto/cloudfront/responses.py | 2 +- .../test_cloudfront_invalidation.py | 31 ++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/moto/cloudfront/responses.py b/moto/cloudfront/responses.py index b434b7c97..e4499953e 100644 --- a/moto/cloudfront/responses.py +++ b/moto/cloudfront/responses.py @@ -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: diff --git a/tests/test_cloudfront/test_cloudfront_invalidation.py b/tests/test_cloudfront/test_cloudfront_invalidation.py index b7c9600d3..3604d71e9 100644 --- a/tests/test_cloudfront/test_cloudfront_invalidation.py +++ b/tests/test_cloudfront/test_cloudfront_invalidation.py @@ -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)