moto/tests/test_cloudfront/test_cloudfront_invalidation.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

100 lines
3.3 KiB
Python
Raw Permalink Normal View History

2022-06-29 20:12:56 +00:00
import boto3
2024-01-07 12:03:33 +00:00
from moto import mock_aws
2022-06-29 20:12:56 +00:00
from . import cloudfront_test_scaffolding as scaffold
2024-01-07 12:03:33 +00:00
@mock_aws
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",
},
)
assert "Location" in resp
assert "Invalidation" in resp
assert "Id" in resp["Invalidation"]
assert resp["Invalidation"]["Status"] == "COMPLETED"
assert "CreateTime" in resp["Invalidation"]
assert resp["Invalidation"]["InvalidationBatch"] == {
"Paths": {"Quantity": 1, "Items": ["/path1"]},
"CallerReference": "ref2",
}
2024-01-07 12:03:33 +00:00
@mock_aws
def test_create_invalidation_with_multiple_paths():
2022-06-29 20:12:56 +00:00
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": 2, "Items": ["/path1", "/path2"]},
"CallerReference": "ref2",
},
)
assert "Location" in resp
assert "Invalidation" in resp
2022-06-29 20:12:56 +00:00
assert "Id" in resp["Invalidation"]
assert resp["Invalidation"]["Status"] == "COMPLETED"
assert "CreateTime" in resp["Invalidation"]
assert resp["Invalidation"]["InvalidationBatch"] == {
"Paths": {"Quantity": 2, "Items": ["/path1", "/path2"]},
"CallerReference": "ref2",
}
2024-01-07 12:03:33 +00:00
@mock_aws
def test_list_invalidations():
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": 2, "Items": ["/path1", "/path2"]},
"CallerReference": "ref2",
},
)
invalidation_id = resp["Invalidation"]["Id"]
resp = client.list_invalidations(DistributionId=dist_id)
assert "NextMarker" not in resp["InvalidationList"]
assert resp["InvalidationList"]["MaxItems"] == 100
assert resp["InvalidationList"]["IsTruncated"] is False
assert resp["InvalidationList"]["Quantity"] == 1
assert len(resp["InvalidationList"]["Items"]) == 1
assert resp["InvalidationList"]["Items"][0]["Id"] == invalidation_id
assert "CreateTime" in resp["InvalidationList"]["Items"][0]
assert resp["InvalidationList"]["Items"][0]["Status"] == "COMPLETED"
2024-01-07 12:03:33 +00:00
@mock_aws
def test_list_invalidations__no_entries():
client = boto3.client("cloudfront", region_name="us-west-1")
resp = client.list_invalidations(DistributionId="SPAM")
assert "NextMarker" not in resp["InvalidationList"]
assert resp["InvalidationList"]["MaxItems"] == 100
assert resp["InvalidationList"]["IsTruncated"] is False
assert resp["InvalidationList"]["Quantity"] == 0
assert "Items" not in resp["InvalidationList"]