Skip to content

Commit

Permalink
Fix no error for non-recursive iterrmove of folder (#237)
Browse files Browse the repository at this point in the history
Co-authored-by: Roman Skurikhin <[email protected]>
  • Loading branch information
romasku and Roman Skurikhin authored Aug 18, 2020
1 parent b50d1bd commit d4cb0cd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 4 additions & 1 deletion platform_storage_api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,11 +557,14 @@ async def _handle_iterdelete(
recursive = request.query.get("recursive", "true") == "true"
response = web.StreamResponse()
response.headers["Content-Type"] = "application/x-ndjson"
await response.prepare(request)
request_prepared = False
try:
async for remove_listing in await self._storage.iterremove(
storage_path, recursive=recursive
):
if not request_prepared:
await response.prepare(request)
request_prepared = True
listing_dict = {
"path": str(remove_listing.path),
"is_dir": remove_listing.is_dir,
Expand Down
7 changes: 6 additions & 1 deletion tests/integration/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -685,8 +685,10 @@ async def test_iterdelete_dir_with_file(
}

@pytest.mark.asyncio
@pytest.mark.parametrize("use_stream_response", [False, True])
async def test_cant_delete_folder_without_non_recursive(
self,
use_stream_response: bool,
server_url: str,
client: aiohttp.ClientSession,
regular_user_factory: Callable[[], User],
Expand All @@ -696,12 +698,15 @@ async def test_cant_delete_folder_without_non_recursive(
headers = {"Authorization": "Bearer " + user.token}
params_mkdir = {"op": "MKDIRS"}
params_delete = {"recursive": "false"}
path_str = f"/{user.name}/new/nested/{uuid.uuid4()}"
path_str = f"/{user.name}/new/nested/foobar222/{uuid.uuid4()}"
url = f"{server_url}{path_str}"

async with client.put(url, headers=headers, params=params_mkdir) as response:
assert response.status == aiohttp.web.HTTPCreated.status_code

if use_stream_response:
headers["Accept"] = "application/x-ndjson"

async with client.delete(
url, headers=headers, params=params_delete
) as response:
Expand Down

0 comments on commit d4cb0cd

Please sign in to comment.