Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

test(api): use caller session for snippet repository delegation (#45143)

zhoulongjie777-gifadcc9a40bdfa
diff --git a/api/tests/unit_tests/services/test_snippet_service.py b/api/tests/unit_tests/services/test_snippet_service.py
index 885282527b7..b5a912b01b3 100644
--- a/api/tests/unit_tests/services/test_snippet_service.py
+++ b/api/tests/unit_tests/services/test_snippet_service.py
@@ -3,7 +3,7 @@ from __future__ import annotations
import json
from datetime import datetime
from types import SimpleNamespace
-from unittest.mock import ANY, Mock
+from unittest.mock import Mock
import pytest
from sqlalchemy import event, select
@@ -1009,8 +1009,10 @@ def test_delete_archived_workflow_run_files_removes_prefixed_objects(monkeypatch
archive_storage.delete_object.assert_called_once_with("tenant-1/app_id=snippet-1/run.json")
-def test_workflow_run_queries_delegate_to_repositories(monkeypatch: pytest.MonkeyPatch) -> None:
- service = SnippetService.__new__(SnippetService)
+def test_workflow_run_queries_delegate_to_repositories(
+ monkeypatch: pytest.MonkeyPatch, sqlite_session: Session
+) -> None:
+ service = SnippetService(session=sqlite_session)
workflow_run_repo = SimpleNamespace(
get_paginated_workflow_runs=Mock(return_value=SimpleNamespace(data=[])),
get_workflow_run_by_id=Mock(return_value=WorkflowRun(id="run-1")),
@@ -1021,8 +1023,6 @@ def test_workflow_run_queries_delegate_to_repositories(monkeypatch: pytest.Monke
)
service._workflow_run_repo = workflow_run_repo
service._node_execution_service_repo = node_execution_repo
- service._session = Mock()
- service._session_maker = Mock()
snippet = _snippet()
expected_traces = [SimpleNamespace(id="node-execution-1:retry:1"), SimpleNamespace(id="node-execution-1")]
mock_assemble = Mock(return_value=expected_traces)
@@ -1053,7 +1053,7 @@ def test_workflow_run_queries_delegate_to_repositories(monkeypatch: pytest.Monke
workflow_run_id="run-1",
)
mock_assemble.assert_called_once_with(
- node_execution_repo.get_executions_by_workflow_run.return_value, node_execution_repo, session=ANY
+ node_execution_repo.get_executions_by_workflow_run.return_value, node_execution_repo, session=sqlite_session
)
node_execution_repo.get_node_last_execution.assert_called_once_with(
tenant_id="tenant-1",