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: use real plugin runtime objects (#43386)

Asuka Minato74ebf9f88734
diff --git a/api/tests/unit_tests/core/plugin/impl/test_asset_manager.py b/api/tests/unit_tests/core/plugin/impl/test_asset_manager.py
index c2cce5d6915..994b00c2e6a 100644
--- a/api/tests/unit_tests/core/plugin/impl/test_asset_manager.py
+++ b/api/tests/unit_tests/core/plugin/impl/test_asset_manager.py
@@ -1,5 +1,4 @@
-from unittest.mock import MagicMock
-
+import httpx
import pytest
from pytest_mock import MockerFixture
@@ -9,7 +8,7 @@ from core.plugin.impl.asset import PluginAssetManager
class TestPluginAssetManager:
def test_fetch_asset_success(self, mocker: MockerFixture):
manager = PluginAssetManager()
- response = MagicMock(status_code=200, content=b"asset-bytes")
+ response = httpx.Response(status_code=200, content=b"asset-bytes")
request_mock = mocker.patch.object(manager, "_request", return_value=response)
result = manager.fetch_asset("tenant-1", "asset-1")
@@ -19,14 +18,14 @@ class TestPluginAssetManager:
def test_fetch_asset_not_found_raises(self, mocker: MockerFixture):
manager = PluginAssetManager()
- mocker.patch.object(manager, "_request", return_value=MagicMock(status_code=404, content=b""))
+ mocker.patch.object(manager, "_request", return_value=httpx.Response(status_code=404, content=b""))
with pytest.raises(ValueError, match="can not found asset asset-1"):
manager.fetch_asset("tenant-1", "asset-1")
def test_extract_asset_success(self, mocker: MockerFixture):
manager = PluginAssetManager()
- response = MagicMock(status_code=200, content=b"file-content")
+ response = httpx.Response(status_code=200, content=b"file-content")
request_mock = mocker.patch.object(manager, "_request", return_value=response)
result = manager.extract_asset("tenant-1", "org/plugin:1", "README.md")
@@ -40,7 +39,7 @@ class TestPluginAssetManager:
def test_extract_asset_not_found_raises(self, mocker: MockerFixture):
manager = PluginAssetManager()
- mocker.patch.object(manager, "_request", return_value=MagicMock(status_code=404, content=b""))
+ mocker.patch.object(manager, "_request", return_value=httpx.Response(status_code=404, content=b""))
with pytest.raises(ValueError, match="can not found asset org/plugin:1, 404"):
manager.extract_asset("tenant-1", "org/plugin:1", "README.md")
diff --git a/api/tests/unit_tests/core/plugin/impl/test_model_runtime_factory.py b/api/tests/unit_tests/core/plugin/impl/test_model_runtime_factory.py
index c2dfe3be309..4111b1e9ae0 100644
--- a/api/tests/unit_tests/core/plugin/impl/test_model_runtime_factory.py
+++ b/api/tests/unit_tests/core/plugin/impl/test_model_runtime_factory.py
@@ -1,14 +1,17 @@
-from unittest.mock import Mock, patch
+from unittest.mock import patch
-from core.plugin.impl.model_runtime_factory import create_plugin_model_assembly
+from core.model_manager import ModelManager
+from core.plugin.impl.model_runtime_factory import create_plugin_model_assembly, create_plugin_model_runtime
from core.plugin.plugin_service import PluginService
+from core.provider_manager import ProviderManager
+from graphon.model_runtime.model_providers.model_provider_factory import ModelProviderFactory
def test_plugin_model_assembly_reuses_single_runtime_across_views():
- runtime = Mock(name="runtime")
- provider_factory = Mock(name="provider_factory")
- provider_manager = Mock(name="provider_manager")
- model_manager = Mock(name="model_manager")
+ runtime = create_plugin_model_runtime(tenant_id="tenant-1", user_id="user-1")
+ provider_factory = ModelProviderFactory(runtime=runtime)
+ provider_manager = ProviderManager(model_runtime=runtime)
+ model_manager = ModelManager(provider_manager=provider_manager)
with (
patch(
@@ -38,8 +41,6 @@ def test_plugin_model_assembly_reuses_single_runtime_across_views():
def test_create_plugin_model_runtime_injects_plugin_service():
- from core.plugin.impl.model_runtime_factory import create_plugin_model_runtime
-
runtime = create_plugin_model_runtime(tenant_id="tenant-1", user_id="user-1")
assert runtime._plugin_service is PluginService