From b13f0ec33d51f9f0a46f384736b6983173c7c043 Mon Sep 17 00:00:00 2001 From: Yaroslava Lukoyanova Date: Thu, 4 May 2023 09:52:55 +0300 Subject: [PATCH] Added new test cases for s3 gate, delete marker feature --- .../services/s3_gate/test_s3_object.py | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/pytest_tests/testsuites/services/s3_gate/test_s3_object.py b/pytest_tests/testsuites/services/s3_gate/test_s3_object.py index e8463128..1700f54b 100644 --- a/pytest_tests/testsuites/services/s3_gate/test_s3_object.py +++ b/pytest_tests/testsuites/services/s3_gate/test_s3_object.py @@ -949,3 +949,56 @@ class TestS3GateObject(TestS3GateBase): with allure.step("Put object"): s3_gate_object.put_object_s3(self.s3_client, bucket, file_path_1) check_objects_in_bucket(self.s3_client, bucket, [file_name]) + + @allure.title("Test S3: Delete non-existing object from empty bucket") + def test_s3_delete_non_existing_object(self, bucket): + set_bucket_versioning(self.s3_client, bucket, s3_gate_bucket.VersioningStatus.ENABLED) + + objects_list = s3_gate_object.list_objects_versions_s3(self.s3_client, bucket) + with allure.step("Check that bucket is empty"): + assert not objects_list, f"Expected empty bucket, got {objects_list}" + + obj_key = "fake_object_key" + + with allure.step("Delete non-existing object"): + delete_obj = s3_gate_object.delete_object_s3(self.s3_client, bucket, obj_key) + # there should be no objects or delete markers in the bucket + assert "DeleteMarker" not in delete_obj.keys(), "Delete markers should not be created" + objects_list = s3_gate_object.list_objects_versions_s3(self.s3_client, bucket) + assert not objects_list, f"Expected empty bucket, got {objects_list}" + + @allure.title("Test S3: Delete the same object twice") + def test_s3_delete_twice(self, bucket, simple_object_size): + set_bucket_versioning(self.s3_client, bucket, s3_gate_bucket.VersioningStatus.ENABLED) + objects_list = s3_gate_object.list_objects_s3(self.s3_client, bucket) + with allure.step("Check that bucket is empty"): + assert not objects_list, f"Expected empty bucket, got {objects_list}" + + file_path = generate_file(simple_object_size) + file_name = self.object_key_from_file_path(file_path) + + with allure.step("Put object into one bucket"): + s3_gate_object.put_object_s3(self.s3_client, bucket, file_path) + + with allure.step("Delete the object from the bucket"): + delete_object = s3_gate_object.delete_object_s3(self.s3_client, bucket, file_name) + 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, f"Object versions were not found {objects_list}" + assert "DeleteMarker" in delete_object.keys(), "Delete markers not found" + + with allure.step("Delete the object from the bucket again"): + delete_object_2nd_attempt = s3_gate_object.delete_object_s3( + self.s3_client, bucket, file_name + ) + versions_2nd_attempt = s3_gate_object.list_objects_versions_s3(self.s3_client, bucket) + + assert ( + delete_object.keys() == delete_object_2nd_attempt.keys() + ), "Delete markers are not the same" + # check that nothing was changed + # checking here not VersionId only, but all data (for example LastModified) + assert versions == versions_2nd_attempt, "Versions are not the same"