mirror of
https://github.com/langgenius/dify.git
synced 2026-04-29 12:37:20 +08:00
test: migrate tool provider controller tests to testcontainers (#34293)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
daebe26089
commit
097095a69b
@ -1,9 +1,11 @@
|
|||||||
|
"""Testcontainers integration tests for controllers.console.workspace.tool_providers endpoints."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import json
|
import json
|
||||||
from unittest.mock import MagicMock, patch
|
from unittest.mock import MagicMock, patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from flask import Flask
|
|
||||||
from flask_restx import Api
|
|
||||||
from werkzeug.exceptions import Forbidden
|
from werkzeug.exceptions import Forbidden
|
||||||
|
|
||||||
from controllers.console.workspace.tool_providers import (
|
from controllers.console.workspace.tool_providers import (
|
||||||
@ -31,7 +33,6 @@ from controllers.console.workspace.tool_providers import (
|
|||||||
ToolOAuthCustomClient,
|
ToolOAuthCustomClient,
|
||||||
ToolPluginOAuthApi,
|
ToolPluginOAuthApi,
|
||||||
ToolProviderListApi,
|
ToolProviderListApi,
|
||||||
ToolProviderMCPApi,
|
|
||||||
ToolWorkflowListApi,
|
ToolWorkflowListApi,
|
||||||
ToolWorkflowProviderCreateApi,
|
ToolWorkflowProviderCreateApi,
|
||||||
ToolWorkflowProviderDeleteApi,
|
ToolWorkflowProviderDeleteApi,
|
||||||
@ -39,8 +40,6 @@ from controllers.console.workspace.tool_providers import (
|
|||||||
ToolWorkflowProviderUpdateApi,
|
ToolWorkflowProviderUpdateApi,
|
||||||
is_valid_url,
|
is_valid_url,
|
||||||
)
|
)
|
||||||
from core.db.session_factory import configure_session_factory
|
|
||||||
from extensions.ext_database import db
|
|
||||||
from services.tools.mcp_tools_manage_service import ReconnectResult
|
from services.tools.mcp_tools_manage_service import ReconnectResult
|
||||||
|
|
||||||
|
|
||||||
@ -61,17 +60,8 @@ def _mock_user_tenant():
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def client():
|
def client(flask_app_with_containers):
|
||||||
app = Flask(__name__)
|
return flask_app_with_containers.test_client()
|
||||||
app.config["TESTING"] = True
|
|
||||||
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///:memory:"
|
|
||||||
api = Api(app)
|
|
||||||
api.add_resource(ToolProviderMCPApi, "/console/api/workspaces/current/tool-provider/mcp")
|
|
||||||
db.init_app(app)
|
|
||||||
# Configure session factory used by controller code
|
|
||||||
with app.app_context():
|
|
||||||
configure_session_factory(db.engine)
|
|
||||||
return app.test_client()
|
|
||||||
|
|
||||||
|
|
||||||
@patch(
|
@patch(
|
||||||
@ -152,10 +142,14 @@ class TestUtils:
|
|||||||
assert not is_valid_url("")
|
assert not is_valid_url("")
|
||||||
assert not is_valid_url("ftp://example.com")
|
assert not is_valid_url("ftp://example.com")
|
||||||
assert not is_valid_url("not-a-url")
|
assert not is_valid_url("not-a-url")
|
||||||
assert not is_valid_url(None)
|
assert not is_valid_url(None) # type: ignore[arg-type]
|
||||||
|
|
||||||
|
|
||||||
class TestToolProviderListApi:
|
class TestToolProviderListApi:
|
||||||
|
@pytest.fixture
|
||||||
|
def app(self, flask_app_with_containers):
|
||||||
|
return flask_app_with_containers
|
||||||
|
|
||||||
def test_get_success(self, app):
|
def test_get_success(self, app):
|
||||||
api = ToolProviderListApi()
|
api = ToolProviderListApi()
|
||||||
method = unwrap(api.get)
|
method = unwrap(api.get)
|
||||||
@ -175,6 +169,10 @@ class TestToolProviderListApi:
|
|||||||
|
|
||||||
|
|
||||||
class TestBuiltinProviderApis:
|
class TestBuiltinProviderApis:
|
||||||
|
@pytest.fixture
|
||||||
|
def app(self, flask_app_with_containers):
|
||||||
|
return flask_app_with_containers
|
||||||
|
|
||||||
def test_list_tools(self, app):
|
def test_list_tools(self, app):
|
||||||
api = ToolBuiltinProviderListToolsApi()
|
api = ToolBuiltinProviderListToolsApi()
|
||||||
method = unwrap(api.get)
|
method = unwrap(api.get)
|
||||||
@ -379,6 +377,10 @@ class TestBuiltinProviderApis:
|
|||||||
|
|
||||||
|
|
||||||
class TestApiProviderApis:
|
class TestApiProviderApis:
|
||||||
|
@pytest.fixture
|
||||||
|
def app(self, flask_app_with_containers):
|
||||||
|
return flask_app_with_containers
|
||||||
|
|
||||||
def test_add(self, app):
|
def test_add(self, app):
|
||||||
api = ToolApiProviderAddApi()
|
api = ToolApiProviderAddApi()
|
||||||
method = unwrap(api.post)
|
method = unwrap(api.post)
|
||||||
@ -502,6 +504,10 @@ class TestApiProviderApis:
|
|||||||
|
|
||||||
|
|
||||||
class TestWorkflowApis:
|
class TestWorkflowApis:
|
||||||
|
@pytest.fixture
|
||||||
|
def app(self, flask_app_with_containers):
|
||||||
|
return flask_app_with_containers
|
||||||
|
|
||||||
def test_create(self, app):
|
def test_create(self, app):
|
||||||
api = ToolWorkflowProviderCreateApi()
|
api = ToolWorkflowProviderCreateApi()
|
||||||
method = unwrap(api.post)
|
method = unwrap(api.post)
|
||||||
@ -587,6 +593,10 @@ class TestWorkflowApis:
|
|||||||
|
|
||||||
|
|
||||||
class TestLists:
|
class TestLists:
|
||||||
|
@pytest.fixture
|
||||||
|
def app(self, flask_app_with_containers):
|
||||||
|
return flask_app_with_containers
|
||||||
|
|
||||||
def test_builtin_list(self, app):
|
def test_builtin_list(self, app):
|
||||||
api = ToolBuiltinListApi()
|
api = ToolBuiltinListApi()
|
||||||
method = unwrap(api.get)
|
method = unwrap(api.get)
|
||||||
@ -649,6 +659,10 @@ class TestLists:
|
|||||||
|
|
||||||
|
|
||||||
class TestLabels:
|
class TestLabels:
|
||||||
|
@pytest.fixture
|
||||||
|
def app(self, flask_app_with_containers):
|
||||||
|
return flask_app_with_containers
|
||||||
|
|
||||||
def test_labels(self, app):
|
def test_labels(self, app):
|
||||||
api = ToolLabelsApi()
|
api = ToolLabelsApi()
|
||||||
method = unwrap(api.get)
|
method = unwrap(api.get)
|
||||||
@ -664,6 +678,10 @@ class TestLabels:
|
|||||||
|
|
||||||
|
|
||||||
class TestOAuth:
|
class TestOAuth:
|
||||||
|
@pytest.fixture
|
||||||
|
def app(self, flask_app_with_containers):
|
||||||
|
return flask_app_with_containers
|
||||||
|
|
||||||
def test_oauth_no_client(self, app):
|
def test_oauth_no_client(self, app):
|
||||||
api = ToolPluginOAuthApi()
|
api = ToolPluginOAuthApi()
|
||||||
method = unwrap(api.get)
|
method = unwrap(api.get)
|
||||||
@ -692,6 +710,10 @@ class TestOAuth:
|
|||||||
|
|
||||||
|
|
||||||
class TestOAuthCustomClient:
|
class TestOAuthCustomClient:
|
||||||
|
@pytest.fixture
|
||||||
|
def app(self, flask_app_with_containers):
|
||||||
|
return flask_app_with_containers
|
||||||
|
|
||||||
def test_save_custom_client(self, app):
|
def test_save_custom_client(self, app):
|
||||||
api = ToolOAuthCustomClient()
|
api = ToolOAuthCustomClient()
|
||||||
method = unwrap(api.post)
|
method = unwrap(api.post)
|
||||||
Loading…
Reference in New Issue
Block a user