From 1c3df7da507dc50b5ab638fa9156dd8cc4872bdb Mon Sep 17 00:00:00 2001 From: Denys Fedoryshchenko Date: Wed, 4 Sep 2024 18:57:53 +0300 Subject: [PATCH] feat(main): Add treeid field Add treeid field handling Signed-off-by: Denys Fedoryshchenko --- api/main.py | 8 +++++--- tests/unit_tests/test_node_handler.py | 11 +++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/api/main.py b/api/main.py index fe6d16a8..ff3a4cfb 100644 --- a/api/main.py +++ b/api/main.py @@ -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], @@ -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 = {} diff --git a/tests/unit_tests/test_node_handler.py b/tests/unit_tests/test_node_handler.py index d4af0de5..41734b6b 100644 --- a/tests/unit_tests/test_node_handler.py +++ b/tests/unit_tests/test_node_handler.py @@ -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 @@ -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", @@ -81,6 +83,7 @@ def test_create_node_endpoint(mock_db_create, mock_publish_cloudevent, 'submitter', 'state', 'timeout', + 'treeid', 'updated', 'user_groups', } @@ -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", @@ -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], @@ -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", @@ -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 @@ -235,6 +242,7 @@ def test_get_node_by_id_endpoint(mock_db_find_by_id, 'submitter', 'state', 'timeout', + 'treeid', 'updated', 'user_groups', } @@ -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 = { @@ -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 = { @@ -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(