def test_prepare_for_revival_failure(make_stubber, make_unique_name): s3_stubber = make_stubber(batch_versioning.s3.meta.client) bucket_name = make_unique_name('bucket') obj_prefix = 'test-prefix' s3_stubber.stub_list_object_versions(bucket_name, f'{obj_prefix}stanza', error_code='TestException') with pytest.raises(ClientError) as exc_info: batch_versioning.prepare_for_revival( batch_versioning.s3.Bucket(bucket_name), obj_prefix) assert exc_info.value.response['Error']['Code'] == 'TestException'
def test_prepare_for_revival(make_stubber, make_unique_name): s3_stubber = make_stubber(batch_versioning.s3.meta.client) bucket_name = make_unique_name('bucket') obj_prefix = 'test-prefix' # include a space in the key to test url-encoding/decoding delete_markers = [ s3_stubber.make_version(f'key {index}', f'version-{index}', True) for index in range(5) ] s3_stubber.stub_list_object_versions(bucket_name, f'{obj_prefix}stanza', delete_markers=delete_markers) manifest_lines = batch_versioning.prepare_for_revival( batch_versioning.s3.Bucket(bucket_name), obj_prefix) assert manifest_lines == [ f"{bucket_name},{parse.quote(ver['Key'])},{ver['VersionId']}" for ver in delete_markers ]