Skip to content

Commit df1dd1d

Browse files
committed
refactor test
1 parent 8847f27 commit df1dd1d

File tree

1 file changed

+41
-31
lines changed

1 file changed

+41
-31
lines changed

services/storage/tests/unit/test_handlers_paths.py

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,34 @@ async def test_list_paths_with_display_name_containing_slashes(
500500
), "display path parts should be url encoded"
501501

502502

503+
async def _assert_compute_path_total_size(
504+
initialized_app: FastAPI,
505+
client: httpx.AsyncClient,
506+
location_id: LocationID,
507+
user_id: UserID,
508+
*,
509+
path: Path,
510+
expected_total_size: ByteSize,
511+
) -> None:
512+
url = url_from_operation_id(
513+
client,
514+
initialized_app,
515+
"compute_path_total_size",
516+
location_id=f"{location_id}",
517+
path=f"{path}",
518+
).with_query(user_id=user_id)
519+
response = await client.post(f"{url}")
520+
521+
received, _ = assert_status(
522+
response,
523+
status.HTTP_200_OK,
524+
PathTotalSizeCreate,
525+
)
526+
assert received
527+
assert received.path == path
528+
assert received.size == expected_total_size
529+
530+
503531
@pytest.mark.parametrize(
504532
"project_params",
505533
[
@@ -534,25 +562,16 @@ async def test_path_compute_size(
534562
# get size of a full project
535563
expected_total_size = project_params.allowed_file_sizes[0] * total_num_files
536564
path = Path(project["uuid"])
537-
url = url_from_operation_id(
538-
client,
565+
await _assert_compute_path_total_size(
539566
initialized_app,
540-
"compute_path_total_size",
541-
location_id=f"{location_id}",
542-
path=f"{path}",
543-
).with_query(user_id=user_id)
544-
response = await client.post(f"{url}")
545-
546-
received, _ = assert_status(
547-
response,
548-
status.HTTP_200_OK,
549-
PathTotalSizeCreate,
567+
client,
568+
location_id,
569+
user_id,
570+
path=path,
571+
expected_total_size=expected_total_size,
550572
)
551-
assert received
552-
assert received.path == path
553-
assert received.size == expected_total_size
554573

555-
# get size of a project/node
574+
# get size of one of the nodes
556575
selected_node_id = NodeID(random.choice(list(project["workbench"]))) # noqa: S311
557576
selected_node_s3_keys = [
558577
Path(s3_object_id) for s3_object_id in list_of_files[selected_node_id]
@@ -561,20 +580,11 @@ async def test_path_compute_size(
561580
selected_node_s3_keys
562581
)
563582
path = Path(project["uuid"]) / f"{selected_node_id}"
564-
url = url_from_operation_id(
565-
client,
583+
await _assert_compute_path_total_size(
566584
initialized_app,
567-
"compute_path_total_size",
568-
location_id=f"{location_id}",
569-
path=f"{path}",
570-
).with_query(user_id=user_id)
571-
response = await client.post(f"{url}")
572-
573-
received, _ = assert_status(
574-
response,
575-
status.HTTP_200_OK,
576-
PathTotalSizeCreate,
585+
client,
586+
location_id,
587+
user_id,
588+
path=path,
589+
expected_total_size=expected_total_size,
577590
)
578-
assert received
579-
assert received.path == path
580-
assert received.size == expected_total_size

0 commit comments

Comments
 (0)