From 908ea295bcc2bc9351a344882fe859bb77f1d28f Mon Sep 17 00:00:00 2001 From: -LAN- Date: Mon, 7 Jul 2025 15:29:05 +0800 Subject: [PATCH] test(test_workflow_draft_variable_service): Fix tests Signed-off-by: -LAN- --- .../test_workflow_draft_variable_service.py | 30 ++++++------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/api/tests/unit_tests/services/workflow/test_workflow_draft_variable_service.py b/api/tests/unit_tests/services/workflow/test_workflow_draft_variable_service.py index f07a18bc32..9c73bd3796 100644 --- a/api/tests/unit_tests/services/workflow/test_workflow_draft_variable_service.py +++ b/api/tests/unit_tests/services/workflow/test_workflow_draft_variable_service.py @@ -1,6 +1,5 @@ import dataclasses import secrets -from unittest import mock from unittest.mock import MagicMock, Mock, patch import pytest @@ -187,11 +186,6 @@ class TestWorkflowDraftVariableService: mock_session_maker.return_value.__exit__.return_value = None service = WorkflowDraftVariableService(mock_session, mock_session_maker) - # Mock the repository to return None (no execution record found) - service._api_node_execution_repo = Mock() - service._api_node_execution_repo.get_execution_by_id.return_value = None - - # Mock the repository to return None (no execution record found) service._api_node_execution_repo = Mock() service._api_node_execution_repo.get_execution_by_id.return_value = None @@ -204,7 +198,7 @@ class TestWorkflowDraftVariableService: variable = WorkflowDraftVariable.new_node_variable( app_id=test_app_id, node_id="test_node_id", name="test_var", value=test_value, node_execution_id="exec-id" ) - mock_variable.editable = True + # Variable is editable by default from factory method result = service._reset_node_var_or_sys_var(workflow, variable) @@ -227,16 +221,6 @@ class TestWorkflowDraftVariableService: mock_session_maker.return_value.__exit__.return_value = None service = WorkflowDraftVariableService(mock_session, mock_session_maker) - # Create mock execution record - mock_execution = Mock(spec=WorkflowNodeExecutionModel) - mock_execution.process_data_dict = {"test_var": "process_value"} - mock_execution.outputs_dict = {"test_var": "output_value"} - - # Mock the repository to return the execution record - service._api_node_execution_repo = Mock() - service._api_node_execution_repo.get_execution_by_id.return_value = mock_execution - - # Create mock execution record mock_execution = Mock(spec=WorkflowNodeExecutionModel) mock_execution.outputs_dict = {"test_var": "output_value"} @@ -253,7 +237,7 @@ class TestWorkflowDraftVariableService: variable = WorkflowDraftVariable.new_node_variable( app_id=test_app_id, node_id="test_node_id", name="test_var", value=test_value, node_execution_id="exec-id" ) - mock_variable.editable = True + # Variable is editable by default from factory method # Mock workflow methods mock_node_config = {"type": "test_node"} @@ -295,9 +279,11 @@ class TestWorkflowDraftVariableService: assert "cannot reset system variable" in str(exc_info.value) assert f"variable_id={variable.id}" in str(exc_info.value) - def test_reset_editable_system_variable_succeeds(self, mock_session): + def test_reset_editable_system_variable_succeeds(self): """Test that resetting an editable system variable succeeds""" - service = WorkflowDraftVariableService(mock_session) + mock_session = Mock(spec=Session) + mock_session_maker = Mock() + service = WorkflowDraftVariableService(mock_session, mock_session_maker) test_app_id = self._get_test_app_id() workflow = self._create_test_workflow(test_app_id) @@ -329,7 +315,9 @@ class TestWorkflowDraftVariableService: def test_reset_query_system_variable_succeeds(self, mock_session): """Test that resetting query system variable (another editable one) succeeds""" - service = WorkflowDraftVariableService(mock_session) + mock_session = Mock(spec=Session) + mock_session_maker = Mock() + service = WorkflowDraftVariableService(mock_session, mock_session_maker) test_app_id = self._get_test_app_id() workflow = self._create_test_workflow(test_app_id)