diff --git a/tests/test_s3/test_s3.py b/tests/test_s3/test_s3.py index acee87f5c..40a9425b3 100644 --- a/tests/test_s3/test_s3.py +++ b/tests/test_s3/test_s3.py @@ -6,6 +6,7 @@ import uuid import zlib from gzip import GzipFile from io import BytesIO +from time import sleep from unittest import SkipTest from urllib.parse import parse_qs, urlparse @@ -1716,9 +1717,7 @@ def test_delete_versioned_bucket_returns_metadata(name=None): bucket = resource.Bucket(name) versions = bucket.object_versions - client.put_bucket_versioning( - Bucket=name, VersioningConfiguration={"Status": "Enabled"} - ) + enable_versioning(name, client) client.put_object(Bucket=name, Key="test1", Body=b"test1") @@ -3311,3 +3310,14 @@ def test_checksum_response(algorithm): def add_proxy_details(kwargs): kwargs["proxies"] = {"https": "http://localhost:5005"} kwargs["verify"] = moto_proxy.__file__.replace("__init__.py", "ca.crt") + + +def enable_versioning(bucket_name, s3_client): + s3_client.put_bucket_versioning( + Bucket=bucket_name, VersioningConfiguration={"Status": "Enabled"} + ) + # Versioning is not active immediately, so wait until we have confirmation the change has gone through + resp = {} + while resp.get("Status") != "Enabled": + sleep(0.1) + resp = s3_client.get_bucket_versioning(Bucket=bucket_name) diff --git a/tests/test_s3/test_s3_list_object_versions.py b/tests/test_s3/test_s3_list_object_versions.py index 4ee8facfa..3719eb2c3 100644 --- a/tests/test_s3/test_s3_list_object_versions.py +++ b/tests/test_s3/test_s3_list_object_versions.py @@ -1,3 +1,4 @@ +from time import sleep from uuid import uuid4 import boto3 @@ -81,9 +82,7 @@ def test_list_object_versions(): @s3_aws_verified def test_list_object_versions_with_delimiter(bucket_name=None): s3_client = boto3.client("s3", region_name=DEFAULT_REGION_NAME) - s3_client.put_bucket_versioning( - Bucket=bucket_name, VersioningConfiguration={"Status": "Enabled"} - ) + enable_versioning(bucket_name, s3_client) for key_index in list(range(1, 5)) + list(range(10, 14)): for version_index in range(1, 4): body = f"data-{version_index}".encode("UTF-8") @@ -297,9 +296,7 @@ def test_list_object_versions_with_versioning_enabled_late(): @s3_aws_verified def test_list_object_versions_with_paging(bucket_name=None): s3_client = boto3.client("s3", region_name=DEFAULT_REGION_NAME) - s3_client.put_bucket_versioning( - Bucket=bucket_name, VersioningConfiguration={"Status": "Enabled"} - ) + enable_versioning(bucket_name, s3_client) obj1ver1 = s3_client.put_object(Bucket=bucket_name, Key="obj1", Body=b"ver1") obj1ver2 = s3_client.put_object(Bucket=bucket_name, Key="obj1", Body=b"ver2") @@ -351,9 +348,7 @@ def test_list_object_versions_with_paging(bucket_name=None): @s3_aws_verified def test_list_object_versions_with_paging_and_delete_markers(bucket_name=None): s3_client = boto3.client("s3", region_name=DEFAULT_REGION_NAME) - s3_client.put_bucket_versioning( - Bucket=bucket_name, VersioningConfiguration={"Status": "Enabled"} - ) + enable_versioning(bucket_name, s3_client) # A mix of versions and delete markers. obj1ver1 = s3_client.put_object(Bucket=bucket_name, Key="obj1", Body=b"ver1") @@ -439,9 +434,7 @@ def test_list_object_versions_with_paging_and_delete_markers(bucket_name=None): def test_list_object_versions_with_paging_and_delimiter(bucket_name=None): s3_client = boto3.client("s3", region_name=DEFAULT_REGION_NAME) - s3_client.put_bucket_versioning( - Bucket=bucket_name, VersioningConfiguration={"Status": "Enabled"} - ) + enable_versioning(bucket_name, s3_client) # Copied from test_list_object_versions_with_delimiter. for key_index in list(range(1, 5)) + list(range(10, 14)): @@ -552,14 +545,11 @@ def test_bad_prefix_list_object_versions(): @s3_aws_verified def test_list_object_versions__sort_order(bucket_name=None): s3_client = boto3.client("s3", region_name=DEFAULT_REGION_NAME) - s3_client.put_bucket_versioning( - Bucket=bucket_name, VersioningConfiguration={"Status": "Enabled"} - ) + enable_versioning(bucket_name, s3_client) # Put one object, and delete it - b_ver1 = s3_client.put_object(Bucket=bucket_name, Key="bbb", Body=b"ver1")[ - "VersionId" - ] + upl = s3_client.put_object(Bucket=bucket_name, Key="bbb", Body=b"ver1") + b_ver1 = upl["ResponseMetadata"]["HTTPHeaders"]["x-amz-version-id"] b_del = s3_client.delete_object(Bucket=bucket_name, Key="bbb")["VersionId"] @@ -638,3 +628,14 @@ def test_list_object_versions__sort_order(bucket_name=None): assert version_list["Versions"][2]["VersionId"] == b_ver1 assert len(version_list["DeleteMarkers"]) == 1 assert version_list["DeleteMarkers"][0]["VersionId"] == b_del + + +def enable_versioning(bucket_name, s3_client): + s3_client.put_bucket_versioning( + Bucket=bucket_name, VersioningConfiguration={"Status": "Enabled"} + ) + # Versioning is not active immediately, so wait until we have confirmation the change has gone through + resp = {} + while resp.get("Status") != "Enabled": + sleep(0.1) + resp = s3_client.get_bucket_versioning(Bucket=bucket_name)