Skip to content

Commit a0d89e4

Browse files
fix: paths with problematic names
1 parent 5bce45d commit a0d89e4

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed

services/storage/tests/unit/test_handlers_paths.py

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from pytest_simcore.helpers.httpx_assert_checks import assert_status
3232
from pytest_simcore.helpers.storage_utils import FileIDDict, ProjectWithFilesParams
3333
from simcore_postgres_database.models.projects import projects
34+
from simcore_postgres_database.models.projects_nodes import projects_nodes
3435
from simcore_service_storage.simcore_s3_dsm import SimcoreS3DataManager
3536
from sqlalchemy.ext.asyncio import AsyncEngine
3637

@@ -462,34 +463,46 @@ async def test_list_paths_with_display_name_containing_slashes(
462463
user_id: UserID,
463464
with_random_project_with_files: tuple[
464465
dict[str, Any],
466+
dict[NodeID, dict[str, Any]],
465467
dict[NodeID, dict[SimcoreS3FileID, FileIDDict]],
466468
],
467469
sqlalchemy_async_engine: AsyncEngine,
468470
):
469-
project, list_of_files = with_random_project_with_files
471+
project, nodes, list_of_files = with_random_project_with_files
470472
project_name_with_slashes = "soméà$èq¨thing with/ slas/h/es/"
471473
node_name_with_non_ascii = "my node / is not ascii: éàèù"
472-
# adjust project to contain "difficult" characters
474+
473475
async with sqlalchemy_async_engine.begin() as conn:
476+
# update project to contain "difficult" characters
474477
result = await conn.execute(
475478
sa.update(projects)
476479
.where(projects.c.uuid == project["uuid"])
477480
.values(name=project_name_with_slashes)
478-
.returning(sa.literal_column(f"{projects.c.name}, {projects.c.workbench}"))
481+
.returning(projects.c.name)
479482
)
480483
row = result.one()
481484
assert row.name == project_name_with_slashes
482-
project_workbench = row.workbench
483-
assert len(project_workbench) == 1
484-
node = next(iter(project_workbench.values()))
485-
node["label"] = node_name_with_non_ascii
486-
result = await conn.execute(
487-
sa.update(projects)
485+
486+
# update a node (first occurrence) to contain "difficult" characters
487+
subquery = (
488+
sa.select(projects_nodes.c.node_id)
489+
.select_from(projects_nodes.join(projects))
488490
.where(projects.c.uuid == project["uuid"])
489-
.values(workbench=project_workbench)
490-
.returning(sa.literal_column(f"{projects.c.name}, {projects.c.workbench}"))
491+
.order_by(projects_nodes.c.node_id)
492+
.limit(1)
491493
)
492-
row = result.one()
494+
first_row = await conn.execute(subquery)
495+
first_id = first_row.scalar_one_or_none()
496+
497+
if first_id:
498+
result = await conn.execute(
499+
sa.update(projects_nodes)
500+
.where(projects_nodes.c.node_id == first_id)
501+
.values(label=node_name_with_non_ascii)
502+
.returning(projects_nodes.c.label)
503+
)
504+
row = result.one()
505+
assert row.label == node_name_with_non_ascii
493506

494507
# ls the root
495508
file_filter = None
@@ -511,7 +524,7 @@ async def test_list_paths_with_display_name_containing_slashes(
511524
# ls the nodes to ensure / is still there between project and node
512525
file_filter = Path(project["uuid"])
513526
expected_paths = sorted(
514-
((file_filter / node_key, False) for node_key in project["workbench"]),
527+
((file_filter / f"{node_id}", False) for node_id in nodes),
515528
key=lambda x: x[0],
516529
)
517530
assert len(expected_paths) == 1, "test configuration problem"
@@ -530,7 +543,7 @@ async def test_list_paths_with_display_name_containing_slashes(
530543
), "display path parts should be url encoded"
531544

532545
# ls in the node workspace
533-
selected_node_id = NodeID(random.choice(list(project["workbench"]))) # noqa: S311
546+
selected_node_id = random.choice(list(nodes)) # noqa: S311
534547
selected_node_s3_keys = [
535548
Path(s3_object_id) for s3_object_id in list_of_files[selected_node_id]
536549
]

0 commit comments

Comments
 (0)