Skip to content

Commit

Permalink
feat(main): Add treeid field
Browse files Browse the repository at this point in the history
Add treeid field handling

Signed-off-by: Denys Fedoryshchenko <[email protected]>
  • Loading branch information
nuclearcat committed Sep 19, 2024
1 parent abf2609 commit 1c3df7d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
8 changes: 5 additions & 3 deletions api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,13 +633,14 @@ async def put_node(node_id: str, node: Node,


async def _set_node_ownership_recursively(user: User, hierarchy: Hierarchy,
submitter: str):
submitter: str, treeid: str):
"""Set node ownership information for a hierarchy of nodes"""
if not hierarchy.node.owner:
hierarchy.node.owner = user.username
hierarchy.node.submitter = submitter
hierarchy.node.treeid = treeid
for node in hierarchy.child_nodes:
await _set_node_ownership_recursively(user, node, submitter)
await _set_node_ownership_recursively(user, node, submitter, treeid)


@app.put('/nodes/{node_id}', response_model=List[Node],
Expand All @@ -658,8 +659,9 @@ async def put_nodes(
detail=f"Node not found with id: {node_id}"
)
submitter = node_from_id.submitter
treeid = node_from_id.treeid

await _set_node_ownership_recursively(user, nodes, submitter)
await _set_node_ownership_recursively(user, nodes, submitter, treeid)
obj_list = await db.create_hierarchy(nodes, Node)
data = _get_node_event_data('updated', obj_list[0], True)
attributes = {}
Expand Down
11 changes: 11 additions & 0 deletions tests/unit_tests/test_node_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def test_create_node_endpoint(mock_db_create, mock_publish_cloudevent,
parent=None,
state="closing",
result=None,
treeid="61bda8f2eb1a63d2b7152418",
)
mock_db_create.return_value = node_obj

Expand All @@ -52,6 +53,7 @@ def test_create_node_endpoint(mock_db_create, mock_publish_cloudevent,
"kind": "checkout",
"path": ["checkout"],
"data": {"kernel_revision": revision_data},
"treeid": "61bda8f2eb1a63d2b7152418",
}
response = test_client.post(
"node",
Expand Down Expand Up @@ -81,6 +83,7 @@ def test_create_node_endpoint(mock_db_create, mock_publish_cloudevent,
'submitter',
'state',
'timeout',
'treeid',
'updated',
'user_groups',
}
Expand Down Expand Up @@ -112,6 +115,7 @@ def test_get_nodes_by_attributes_endpoint(mock_db_find_by_attributes,
"parent": "61bda8f2eb1a63d2b7152410",
"state": "closing",
"result": None,
"treeid": "61bda8f2eb1a63d2b7152418",
}
node_obj_2 = {
"id": "61bda8f2eb1a63d2b7152414",
Expand All @@ -130,6 +134,7 @@ def test_get_nodes_by_attributes_endpoint(mock_db_find_by_attributes,
"parent": "61bda8f2eb1a63d2b7152410",
"state": "closing",
"result": None,
"treeid": "61bda8f2eb1a63d2b7152414",
}
mock_db_find_by_attributes.return_value = PageModel(
items=[node_obj_1, node_obj_2],
Expand All @@ -144,6 +149,7 @@ def test_get_nodes_by_attributes_endpoint(mock_db_find_by_attributes,
"data.kernel_revision.branch": "master",
"state": "closing",
"parent": "61bda8f2eb1a63d2b7152410",
"treeid": "61bda8f2eb1a63d2b7152418",
}
response = test_client.get(
"nodes",
Expand Down Expand Up @@ -211,6 +217,7 @@ def test_get_node_by_id_endpoint(mock_db_find_by_id,
parent=None,
state="closing",
result=None,
treeid="61bdaa8f2eb1a63d2b7152418",
)
mock_db_find_by_id.return_value = node_obj

Expand All @@ -235,6 +242,7 @@ def test_get_node_by_id_endpoint(mock_db_find_by_id,
'submitter',
'state',
'timeout',
'treeid',
'updated',
'user_groups',
}
Expand Down Expand Up @@ -284,6 +292,7 @@ def test_get_all_nodes(mock_db_find_by_attributes,
"parent": None,
"state": "closing",
"result": None,
"treeid": "61bda8f2eb1a63d2b7152418",
}

node_obj_2 = {
Expand All @@ -305,6 +314,7 @@ def test_get_all_nodes(mock_db_find_by_attributes,
"parent": None,
"state": "closing",
"result": None,
"treeid": "61bda8f2eb1a63d2b7152418",
}

node_obj_3 = {
Expand All @@ -326,6 +336,7 @@ def test_get_all_nodes(mock_db_find_by_attributes,
"parent": None,
"state": "closing",
"result": None,
"treeid": "61bda8f2eb1a63d2b7152418",
}

mock_db_find_by_attributes.return_value = PageModel(
Expand Down

0 comments on commit 1c3df7d

Please sign in to comment.