2022-09-26 08:25:49 +00:00
|
|
|
import os
|
|
|
|
|
|
|
|
import allure
|
|
|
|
import pytest
|
2022-10-11 08:18:08 +00:00
|
|
|
|
2023-02-27 16:54:27 +00:00
|
|
|
from pytest_tests.helpers.file_helper import generate_file, generate_file_with_content
|
|
|
|
from pytest_tests.helpers.s3_helper import set_bucket_versioning
|
|
|
|
from pytest_tests.steps import s3_gate_bucket, s3_gate_object
|
|
|
|
from pytest_tests.steps.s3_gate_base import TestS3GateBase
|
2022-09-26 08:25:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
def pytest_generate_tests(metafunc):
|
|
|
|
if "s3_client" in metafunc.fixturenames:
|
|
|
|
metafunc.parametrize("s3_client", ["aws cli", "boto3"], indirect=True)
|
|
|
|
|
|
|
|
|
2022-11-10 05:27:52 +00:00
|
|
|
@pytest.mark.sanity
|
2022-09-26 08:25:49 +00:00
|
|
|
@pytest.mark.s3_gate
|
2022-11-10 05:27:52 +00:00
|
|
|
@pytest.mark.s3_gate_versioning
|
2022-09-26 08:25:49 +00:00
|
|
|
class TestS3GateVersioning(TestS3GateBase):
|
|
|
|
@staticmethod
|
|
|
|
def object_key_from_file_path(full_path: str) -> str:
|
|
|
|
return os.path.basename(full_path)
|
|
|
|
|
|
|
|
@allure.title("Test S3: try to disable versioning")
|
|
|
|
def test_s3_version_off(self):
|
|
|
|
|
|
|
|
bucket = s3_gate_bucket.create_bucket_s3(self.s3_client, True)
|
|
|
|
with pytest.raises(Exception):
|
|
|
|
set_bucket_versioning(self.s3_client, bucket, s3_gate_bucket.VersioningStatus.SUSPENDED)
|
|
|
|
|
|
|
|
@allure.title("Test S3: Enable and disable versioning")
|
2022-12-07 12:38:56 +00:00
|
|
|
def test_s3_version(self, simple_object_size):
|
|
|
|
file_path = generate_file(simple_object_size)
|
2022-09-26 08:25:49 +00:00
|
|
|
file_name = self.object_key_from_file_path(file_path)
|
|
|
|
bucket_objects = [file_name]
|
|
|
|
bucket = s3_gate_bucket.create_bucket_s3(self.s3_client, False)
|
|
|
|
set_bucket_versioning(self.s3_client, bucket, s3_gate_bucket.VersioningStatus.SUSPENDED)
|
|
|
|
|
|
|
|
with allure.step("Put object into bucket"):
|
|
|
|
s3_gate_object.put_object_s3(self.s3_client, bucket, file_path)
|
|
|
|
objects_list = s3_gate_object.list_objects_s3(self.s3_client, bucket)
|
|
|
|
assert (
|
|
|
|
objects_list == bucket_objects
|
|
|
|
), f"Expected list with single objects in bucket, got {objects_list}"
|
|
|
|
object_version = s3_gate_object.list_objects_versions_s3(self.s3_client, bucket)
|
|
|
|
actual_version = [
|
|
|
|
version.get("VersionId")
|
|
|
|
for version in object_version
|
|
|
|
if version.get("Key") == file_name
|
|
|
|
]
|
2022-10-16 16:29:09 +00:00
|
|
|
assert actual_version == [
|
|
|
|
"null"
|
|
|
|
], f"Expected version is null in list-object-versions, got {object_version}"
|
|
|
|
object_0 = s3_gate_object.head_object_s3(self.s3_client, bucket, file_name)
|
|
|
|
assert (
|
|
|
|
object_0.get("VersionId") == "null"
|
|
|
|
), f"Expected version is null in head-object, got {object_0.get('VersionId')}"
|
2022-09-26 08:25:49 +00:00
|
|
|
|
|
|
|
set_bucket_versioning(self.s3_client, bucket, s3_gate_bucket.VersioningStatus.ENABLED)
|
|
|
|
|
|
|
|
with allure.step("Put several versions of object into bucket"):
|
|
|
|
version_id_1 = s3_gate_object.put_object_s3(self.s3_client, bucket, file_path)
|
2022-12-07 12:38:56 +00:00
|
|
|
file_name_1 = generate_file_with_content(simple_object_size, file_path=file_path)
|
2022-09-26 08:25:49 +00:00
|
|
|
version_id_2 = s3_gate_object.put_object_s3(self.s3_client, bucket, file_name_1)
|
|
|
|
|
|
|
|
with allure.step("Check bucket shows all versions"):
|
|
|
|
versions = s3_gate_object.list_objects_versions_s3(self.s3_client, bucket)
|
|
|
|
obj_versions = [
|
|
|
|
version.get("VersionId") for version in versions if version.get("Key") == file_name
|
|
|
|
]
|
|
|
|
assert (
|
|
|
|
obj_versions.sort() == [version_id_1, version_id_2, "null"].sort()
|
|
|
|
), f"Expected object has versions: {version_id_1, version_id_2, 'null'}"
|
|
|
|
|
|
|
|
with allure.step("Get object"):
|
|
|
|
object_1 = s3_gate_object.get_object_s3(
|
|
|
|
self.s3_client, bucket, file_name, full_output=True
|
|
|
|
)
|
|
|
|
assert (
|
|
|
|
object_1.get("VersionId") == version_id_2
|
|
|
|
), f"Get object with version {version_id_2}"
|
|
|
|
|
|
|
|
with allure.step("Get first version of object"):
|
|
|
|
object_2 = s3_gate_object.get_object_s3(
|
|
|
|
self.s3_client, bucket, file_name, version_id_1, full_output=True
|
|
|
|
)
|
|
|
|
assert (
|
|
|
|
object_2.get("VersionId") == version_id_1
|
|
|
|
), f"Get object with version {version_id_1}"
|
|
|
|
|
|
|
|
with allure.step("Get second version of object"):
|
|
|
|
object_3 = s3_gate_object.get_object_s3(
|
|
|
|
self.s3_client, bucket, file_name, version_id_2, full_output=True
|
|
|
|
)
|
|
|
|
assert (
|
|
|
|
object_3.get("VersionId") == version_id_2
|
|
|
|
), f"Get object with version {version_id_2}"
|