Techdebt: Improve AWS tests (#7387)
This commit is contained in:
parent
3a8d3a3a08
commit
6f797c2f00
@ -6,6 +6,7 @@ import uuid
|
|||||||
import zlib
|
import zlib
|
||||||
from gzip import GzipFile
|
from gzip import GzipFile
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
from time import sleep
|
||||||
from unittest import SkipTest
|
from unittest import SkipTest
|
||||||
from urllib.parse import parse_qs, urlparse
|
from urllib.parse import parse_qs, urlparse
|
||||||
|
|
||||||
@ -1716,9 +1717,7 @@ def test_delete_versioned_bucket_returns_metadata(name=None):
|
|||||||
bucket = resource.Bucket(name)
|
bucket = resource.Bucket(name)
|
||||||
versions = bucket.object_versions
|
versions = bucket.object_versions
|
||||||
|
|
||||||
client.put_bucket_versioning(
|
enable_versioning(name, client)
|
||||||
Bucket=name, VersioningConfiguration={"Status": "Enabled"}
|
|
||||||
)
|
|
||||||
|
|
||||||
client.put_object(Bucket=name, Key="test1", Body=b"test1")
|
client.put_object(Bucket=name, Key="test1", Body=b"test1")
|
||||||
|
|
||||||
@ -3311,3 +3310,14 @@ def test_checksum_response(algorithm):
|
|||||||
def add_proxy_details(kwargs):
|
def add_proxy_details(kwargs):
|
||||||
kwargs["proxies"] = {"https": "http://localhost:5005"}
|
kwargs["proxies"] = {"https": "http://localhost:5005"}
|
||||||
kwargs["verify"] = moto_proxy.__file__.replace("__init__.py", "ca.crt")
|
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)
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
from time import sleep
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
import boto3
|
import boto3
|
||||||
@ -81,9 +82,7 @@ def test_list_object_versions():
|
|||||||
@s3_aws_verified
|
@s3_aws_verified
|
||||||
def test_list_object_versions_with_delimiter(bucket_name=None):
|
def test_list_object_versions_with_delimiter(bucket_name=None):
|
||||||
s3_client = boto3.client("s3", region_name=DEFAULT_REGION_NAME)
|
s3_client = boto3.client("s3", region_name=DEFAULT_REGION_NAME)
|
||||||
s3_client.put_bucket_versioning(
|
enable_versioning(bucket_name, s3_client)
|
||||||
Bucket=bucket_name, VersioningConfiguration={"Status": "Enabled"}
|
|
||||||
)
|
|
||||||
for key_index in list(range(1, 5)) + list(range(10, 14)):
|
for key_index in list(range(1, 5)) + list(range(10, 14)):
|
||||||
for version_index in range(1, 4):
|
for version_index in range(1, 4):
|
||||||
body = f"data-{version_index}".encode("UTF-8")
|
body = f"data-{version_index}".encode("UTF-8")
|
||||||
@ -297,9 +296,7 @@ def test_list_object_versions_with_versioning_enabled_late():
|
|||||||
@s3_aws_verified
|
@s3_aws_verified
|
||||||
def test_list_object_versions_with_paging(bucket_name=None):
|
def test_list_object_versions_with_paging(bucket_name=None):
|
||||||
s3_client = boto3.client("s3", region_name=DEFAULT_REGION_NAME)
|
s3_client = boto3.client("s3", region_name=DEFAULT_REGION_NAME)
|
||||||
s3_client.put_bucket_versioning(
|
enable_versioning(bucket_name, s3_client)
|
||||||
Bucket=bucket_name, VersioningConfiguration={"Status": "Enabled"}
|
|
||||||
)
|
|
||||||
|
|
||||||
obj1ver1 = s3_client.put_object(Bucket=bucket_name, Key="obj1", Body=b"ver1")
|
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")
|
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
|
@s3_aws_verified
|
||||||
def test_list_object_versions_with_paging_and_delete_markers(bucket_name=None):
|
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 = boto3.client("s3", region_name=DEFAULT_REGION_NAME)
|
||||||
s3_client.put_bucket_versioning(
|
enable_versioning(bucket_name, s3_client)
|
||||||
Bucket=bucket_name, VersioningConfiguration={"Status": "Enabled"}
|
|
||||||
)
|
|
||||||
|
|
||||||
# A mix of versions and delete markers.
|
# A mix of versions and delete markers.
|
||||||
obj1ver1 = s3_client.put_object(Bucket=bucket_name, Key="obj1", Body=b"ver1")
|
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):
|
def test_list_object_versions_with_paging_and_delimiter(bucket_name=None):
|
||||||
s3_client = boto3.client("s3", region_name=DEFAULT_REGION_NAME)
|
s3_client = boto3.client("s3", region_name=DEFAULT_REGION_NAME)
|
||||||
|
|
||||||
s3_client.put_bucket_versioning(
|
enable_versioning(bucket_name, s3_client)
|
||||||
Bucket=bucket_name, VersioningConfiguration={"Status": "Enabled"}
|
|
||||||
)
|
|
||||||
|
|
||||||
# Copied from test_list_object_versions_with_delimiter.
|
# Copied from test_list_object_versions_with_delimiter.
|
||||||
for key_index in list(range(1, 5)) + list(range(10, 14)):
|
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
|
@s3_aws_verified
|
||||||
def test_list_object_versions__sort_order(bucket_name=None):
|
def test_list_object_versions__sort_order(bucket_name=None):
|
||||||
s3_client = boto3.client("s3", region_name=DEFAULT_REGION_NAME)
|
s3_client = boto3.client("s3", region_name=DEFAULT_REGION_NAME)
|
||||||
s3_client.put_bucket_versioning(
|
enable_versioning(bucket_name, s3_client)
|
||||||
Bucket=bucket_name, VersioningConfiguration={"Status": "Enabled"}
|
|
||||||
)
|
|
||||||
|
|
||||||
# Put one object, and delete it
|
# Put one object, and delete it
|
||||||
b_ver1 = s3_client.put_object(Bucket=bucket_name, Key="bbb", Body=b"ver1")[
|
upl = s3_client.put_object(Bucket=bucket_name, Key="bbb", Body=b"ver1")
|
||||||
"VersionId"
|
b_ver1 = upl["ResponseMetadata"]["HTTPHeaders"]["x-amz-version-id"]
|
||||||
]
|
|
||||||
|
|
||||||
b_del = s3_client.delete_object(Bucket=bucket_name, Key="bbb")["VersionId"]
|
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 version_list["Versions"][2]["VersionId"] == b_ver1
|
||||||
assert len(version_list["DeleteMarkers"]) == 1
|
assert len(version_list["DeleteMarkers"]) == 1
|
||||||
assert version_list["DeleteMarkers"][0]["VersionId"] == b_del
|
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)
|
||||||
|
Loading…
Reference in New Issue
Block a user