mirror of
https://github.com/langgenius/dify.git
synced 2026-05-26 20:07:46 +08:00
Delete services.plugin.plugin_service and update remaining tests to import and patch core.plugin.plugin_service directly. This completes the move of PluginService ownership into core.plugin without retaining the compatibility module.
40 lines
1.2 KiB
Python
40 lines
1.2 KiB
Python
"""Shared fixtures for services.plugin test suite."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from unittest.mock import MagicMock
|
|
|
|
import pytest
|
|
|
|
from services.feature_service import PluginInstallationScope
|
|
|
|
|
|
def make_features(
|
|
restrict_to_marketplace: bool = False,
|
|
scope: PluginInstallationScope = PluginInstallationScope.ALL,
|
|
) -> MagicMock:
|
|
"""Create a mock FeatureService.get_system_features() result."""
|
|
features = MagicMock()
|
|
features.plugin_installation_permission.restrict_to_marketplace_only = restrict_to_marketplace
|
|
features.plugin_installation_permission.plugin_installation_scope = scope
|
|
return features
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_installer(monkeypatch: pytest.MonkeyPatch):
|
|
"""Patch PluginInstaller at the service import site."""
|
|
mock = MagicMock()
|
|
monkeypatch.setattr("core.plugin.plugin_service.PluginInstaller", lambda: mock)
|
|
return mock
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_features():
|
|
"""Patch FeatureService to return permissive defaults."""
|
|
from unittest.mock import patch
|
|
|
|
features = make_features()
|
|
with patch("core.plugin.plugin_service.FeatureService") as mock_fs:
|
|
mock_fs.get_system_features.return_value = features
|
|
yield features
|