From ec9b62d439d6a699c894e216e509fbe2809b0c16 Mon Sep 17 00:00:00 2001 From: Yaroslava Lukoyanova Date: Mon, 1 May 2023 21:02:23 +0300 Subject: [PATCH] Added new test cases for s3 gate, delete marker feature --- .../services/s3_gate/test_s3_object.py | 51 +++++++++++++++++++ 1 file changed, 51 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 e846312..d4eb943 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,54 @@ 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) + 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 "DeleteMarkers" not in delete_obj.keys(), "Delete markers not found" + 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) + 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 "DeleteMarkers" not 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"