Skip to content

Commit 841593d

Browse files
fix: clone test
1 parent 427f998 commit 841593d

File tree

1 file changed

+16
-26
lines changed

1 file changed

+16
-26
lines changed

packages/pytest-simcore/src/pytest_simcore/helpers/storage_utils_project.py

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
from copy import deepcopy
33
from typing import Any
44

5-
from models_library.projects_nodes_io import NodeIDStr
5+
from models_library.projects_nodes_io import NodeID
66

77

88
def clone_project_data(
9-
project: dict,
10-
) -> tuple[dict[str, Any], dict[NodeIDStr, NodeIDStr]]:
9+
project: dict[str, Any],
10+
project_nodes: dict[NodeID, dict[str, Any]],
11+
) -> tuple[dict[str, Any], dict[NodeID, dict[str, Any]], dict[NodeID, NodeID]]:
1112
project_copy = deepcopy(project)
1213

1314
# Update project id
@@ -17,28 +18,17 @@ def clone_project_data(
1718
project_copy.pop("id", None)
1819
project_copy["name"] = f"{project['name']}-copy"
1920

20-
# Workbench nodes shall be unique within the project context
21-
def _create_new_node_uuid(old_uuid: NodeIDStr) -> NodeIDStr:
22-
return NodeIDStr(uuidlib.uuid5(project_copy_uuid, old_uuid))
21+
# Nodes shall be unique within the project context
22+
def _new_node_uuid(old: NodeID) -> NodeID:
23+
return uuidlib.uuid5(project_copy_uuid, f"{old}")
2324

24-
nodes_map = {}
25-
for node_uuid in project.get("workbench", {}):
26-
nodes_map[node_uuid] = _create_new_node_uuid(node_uuid)
25+
nodes_map = {node_uuid: _new_node_uuid(node_uuid) for node_uuid in project_nodes}
26+
project_nodes_copy = {
27+
nodes_map[old_node_id]: {
28+
**deepcopy(data),
29+
"node_id": nodes_map[old_node_id], # update the internal "node_id" field
30+
}
31+
for old_node_id, data in project_nodes.items()
32+
}
2733

28-
def _replace_uuids(node):
29-
if isinstance(node, str):
30-
node = nodes_map.get(node, node)
31-
elif isinstance(node, list):
32-
node = [_replace_uuids(item) for item in node]
33-
elif isinstance(node, dict):
34-
_frozen_items = tuple(node.items())
35-
for key, value in _frozen_items:
36-
if key in nodes_map:
37-
new_key = nodes_map[key]
38-
node[new_key] = node.pop(key)
39-
key = new_key
40-
node[key] = _replace_uuids(value)
41-
return node
42-
43-
project_copy["workbench"] = _replace_uuids(project_copy.get("workbench", {}))
44-
return project_copy, nodes_map
34+
return project_copy, project_nodes_copy, nodes_map

0 commit comments

Comments
 (0)