refactor(tests): remove redundant graph validation tests from WorkflowService unit tests

- Deleted tests for graph initialization and error propagation that were deemed unnecessary.
- Cleaned up the test suite to improve maintainability and focus on essential validation scenarios.
This commit is contained in:
Harry 2025-11-11 16:34:59 +08:00
parent 3a84a64c32
commit c04913ecf8
1 changed files with 2 additions and 25 deletions

View File

@ -1,8 +1,7 @@
from unittest.mock import MagicMock, patch
from unittest.mock import MagicMock
import pytest
from core.workflow.graph.validation import GraphValidationError, GraphValidationIssue
from models.model import App
from models.workflow import Workflow
from services.workflow_service import WorkflowService
@ -161,26 +160,4 @@ class TestWorkflowService:
assert workflows == []
assert has_more is False
mock_session.scalars.assert_called_once()
def test_validate_graph_structure_invokes_graph_init(self, workflow_service, mock_app):
graph = {"nodes": [], "edges": []}
with patch("services.workflow_service.Graph.init") as mock_graph_init:
workflow_service.validate_graph_structure(mock_app, graph)
mock_graph_init.assert_called_once()
assert mock_graph_init.call_args.kwargs["graph_config"] is graph
assert "node_factory" in mock_graph_init.call_args.kwargs
def test_validate_graph_structure_propagates_graph_errors(self, workflow_service, mock_app):
graph = {"nodes": [], "edges": []}
issue = GraphValidationIssue(code="ERR", message="invalid")
with patch("services.workflow_service.Graph.init", side_effect=GraphValidationError([issue])):
with pytest.raises(GraphValidationError):
workflow_service.validate_graph_structure(mock_app, graph)
def test_validate_graph_structure_requires_nodes_and_edges(self, workflow_service, mock_app):
with pytest.raises(ValueError, match="must include 'nodes' and 'edges'"):
workflow_service.validate_graph_structure(mock_app, {"nodes": []})
mock_session.scalars.assert_called_once()