test(test_workflow_draft_variable_service): Fix tests

Signed-off-by: -LAN- <laipz8200@outlook.com>
pull/22581/head
-LAN- 11 months ago
parent 979c4affa1
commit 908ea295bc
No known key found for this signature in database
GPG Key ID: 6BA0D108DED011FF

@ -1,6 +1,5 @@
import dataclasses import dataclasses
import secrets import secrets
from unittest import mock
from unittest.mock import MagicMock, Mock, patch from unittest.mock import MagicMock, Mock, patch
import pytest import pytest
@ -187,11 +186,6 @@ class TestWorkflowDraftVariableService:
mock_session_maker.return_value.__exit__.return_value = None mock_session_maker.return_value.__exit__.return_value = None
service = WorkflowDraftVariableService(mock_session, mock_session_maker) 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) # Mock the repository to return None (no execution record found)
service._api_node_execution_repo = Mock() service._api_node_execution_repo = Mock()
service._api_node_execution_repo.get_execution_by_id.return_value = None service._api_node_execution_repo.get_execution_by_id.return_value = None
@ -204,7 +198,7 @@ class TestWorkflowDraftVariableService:
variable = WorkflowDraftVariable.new_node_variable( 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" 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) 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 mock_session_maker.return_value.__exit__.return_value = None
service = WorkflowDraftVariableService(mock_session, mock_session_maker) 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 # Create mock execution record
mock_execution = Mock(spec=WorkflowNodeExecutionModel) mock_execution = Mock(spec=WorkflowNodeExecutionModel)
mock_execution.outputs_dict = {"test_var": "output_value"} mock_execution.outputs_dict = {"test_var": "output_value"}
@ -253,7 +237,7 @@ class TestWorkflowDraftVariableService:
variable = WorkflowDraftVariable.new_node_variable( 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" 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 workflow methods
mock_node_config = {"type": "test_node"} mock_node_config = {"type": "test_node"}
@ -295,9 +279,11 @@ class TestWorkflowDraftVariableService:
assert "cannot reset system variable" in str(exc_info.value) assert "cannot reset system variable" in str(exc_info.value)
assert f"variable_id={variable.id}" 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""" """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() test_app_id = self._get_test_app_id()
workflow = self._create_test_workflow(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): def test_reset_query_system_variable_succeeds(self, mock_session):
"""Test that resetting query system variable (another editable one) succeeds""" """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() test_app_id = self._get_test_app_id()
workflow = self._create_test_workflow(test_app_id) workflow = self._create_test_workflow(test_app_id)

Loading…
Cancel
Save