Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for retrieving bucket content when bucket contains manually created dirs #7018

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions tests/python/rest_api/test_cloud_storages.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io
import json
from enum import Enum
from functools import partial
from http import HTTPStatus
from typing import Any, Optional

Expand All @@ -17,6 +18,7 @@
from PIL import Image

from shared.utils.config import get_method, make_api_client
from shared.utils.s3 import make_client as make_s3_client

from .utils import CollectionSimpleFilterTestBase

Expand Down Expand Up @@ -591,6 +593,47 @@ def test_iterate_over_cloud_storage_content(

assert expected_content == current_content

@pytest.mark.parametrize("cloud_storage_id", [2])
def test_can_get_storage_content_with_manually_created_dirs(
self,
cloud_storage_id: int,
request,
cloud_storages,
):
initial_content = self._test_get_cloud_storage_content(cloud_storage_id)["content"]
s3_client = make_s3_client()
cs_name = cloud_storages[cloud_storage_id]["resource"]
new_directory = "manually_created_directory/"

# directory is 0 size object that has a name ending with a forward slash
s3_client.create_file(
bucket=cs_name,
filename=new_directory,
)
request.addfinalizer(
partial(
s3_client.remove_file,
bucket=cs_name,
filename=new_directory,
)
)

content = self._test_get_cloud_storage_content(
cloud_storage_id,
)["content"]
assert len(initial_content) + 1 == len(content)
assert list(
filter(
lambda x: new_directory.strip() == x["name"] and "DIR" == x["mime_type"], content
)
)
Marishka17 marked this conversation as resolved.
Show resolved Hide resolved

content = self._test_get_cloud_storage_content(
cloud_storage_id,
prefix=new_directory,
)["content"]
assert not len(content)


@pytest.mark.usefixtures("restore_db_per_class")
class TestListCloudStorages:
Expand Down
Loading