From f433b8a175eec3462f6561d805dd46710e126ce3 Mon Sep 17 00:00:00 2001 From: GuanMu Date: Mon, 21 Jul 2025 15:01:34 +0000 Subject: [PATCH] test: Refactor AnswerNode tests, extract configuration to variables and update node initialization. --- .../core/workflow/nodes/answer/test_answer.py | 50 +++++++++++-------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/api/tests/unit_tests/core/workflow/nodes/answer/test_answer.py b/api/tests/unit_tests/core/workflow/nodes/answer/test_answer.py index 7c968f6ff0..c72d73ae4e 100644 --- a/api/tests/unit_tests/core/workflow/nodes/answer/test_answer.py +++ b/api/tests/unit_tests/core/workflow/nodes/answer/test_answer.py @@ -144,25 +144,29 @@ def test_execute_answer_with_outputs(): variable_pool.add(["start", "weather"], "sunny") variable_pool.add(["start", "score"], 85) + node_config = { + "id": "answer", + "data": { + "title": "Answer with outputs", + "type": "answer", + "answer": "Weather: {{#start.weather#}}, Score: {{#start.score#}}", + "outputs": [ + {"variable": "confidence", "type": "number", "value_selector": ["start", "score"]}, + {"variable": "status", "type": "string", "value_selector": ["start", "weather"]}, + ], + }, + } + node = AnswerNode( id=str(uuid.uuid4()), graph_init_params=init_params, graph=graph, graph_runtime_state=GraphRuntimeState(variable_pool=variable_pool, start_at=time.perf_counter()), - config={ - "id": "answer", - "data": { - "title": "Answer with outputs", - "type": "answer", - "answer": "Weather: {{#start.weather#}}, Score: {{#start.score#}}", - "outputs": [ - {"variable": "confidence", "type": "number", "value_selector": ["start", "score"]}, - {"variable": "status", "type": "string", "value_selector": ["start", "weather"]}, - ], - }, - }, + config=node_config, ) + node.init_node_data(node_config["data"]) + # Mock db.session.close() db.session.close = MagicMock() @@ -228,22 +232,26 @@ def test_execute_answer_with_empty_outputs(): conversation_variables=[], ) + node_config = { + "id": "answer", + "data": { + "title": "No outputs", + "type": "answer", + "answer": "Simple answer", + "outputs": [], + }, + } + node = AnswerNode( id=str(uuid.uuid4()), graph_init_params=init_params, graph=graph, graph_runtime_state=GraphRuntimeState(variable_pool=variable_pool, start_at=time.perf_counter()), - config={ - "id": "answer", - "data": { - "title": "No outputs", - "type": "answer", - "answer": "Simple answer", - "outputs": [], - }, - }, + config=node_config, ) + node.init_node_data(node_config["data"]) + # Mock db.session.close() db.session.close = MagicMock()