mirror of
https://github.com/langgenius/dify.git
synced 2026-09-24 23:22:26 +08:00
refactor: replace manual model_validate with @model_validate decorator in app controllers (#40170)
This commit is contained in:
@@ -8,7 +8,7 @@ from __future__ import annotations
|
||||
|
||||
from inspect import unwrap
|
||||
from types import SimpleNamespace
|
||||
from unittest.mock import MagicMock, PropertyMock, patch
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from flask import Flask
|
||||
from sqlalchemy import event
|
||||
@@ -28,7 +28,6 @@ from controllers.console.app.agent_config_inspector import (
|
||||
AgentConfigSkillInspectByAgentApi,
|
||||
AgentConfigSkillsApi,
|
||||
AgentConfigSkillUploadByAgentApi,
|
||||
console_ns,
|
||||
)
|
||||
from services.agent_config_service import AgentConfigServiceError
|
||||
|
||||
@@ -212,13 +211,10 @@ def test_skill_upload_by_agent_delegates_after_version_resolution():
|
||||
|
||||
def test_file_upload_by_agent_delegates_to_service_owned_upload_lookup():
|
||||
raw = _raw(AgentConfigFilesByAgentApi.post)
|
||||
with app.test_request_context("/?draft_type=debug_build"):
|
||||
with app.test_request_context("/?draft_type=debug_build", json={"upload_file_id": "upload-1"}):
|
||||
with (
|
||||
patch(f"{_MOD}.resolve_agent_runtime_app_model", return_value=_APP),
|
||||
patch(f"{_MOD}.AgentComposerService") as composer,
|
||||
patch.object(
|
||||
type(console_ns), "payload", new_callable=PropertyMock, return_value={"upload_file_id": "upload-1"}
|
||||
),
|
||||
patch(f"{_MOD}.AgentConfigService") as config_service,
|
||||
):
|
||||
composer.load_agent_app_build_draft.return_value = {"draft": {"id": "build-draft-1"}}
|
||||
@@ -226,7 +222,14 @@ def test_file_upload_by_agent_delegates_to_service_owned_upload_lookup():
|
||||
"file": {"id": "guide.txt", "name": "guide.txt", "file_id": "upload-1"},
|
||||
"config_version": {"id": "build-draft-1", "kind": "build_draft", "writable": True},
|
||||
}
|
||||
body, status = raw(AgentConfigFilesByAgentApi(), MagicMock(), "tenant-1", _USER, "agent-1")
|
||||
body, status = raw(
|
||||
AgentConfigFilesByAgentApi(),
|
||||
inspector.AgentConfigFileUploadPayload(upload_file_id="upload-1"),
|
||||
MagicMock(),
|
||||
"tenant-1",
|
||||
_USER,
|
||||
"agent-1",
|
||||
)
|
||||
assert status == 201
|
||||
assert body["file"]["name"] == "guide.txt"
|
||||
assert config_service.return_value.push_file_for_console.call_args.kwargs["upload_file_id"] == "upload-1"
|
||||
|
||||
@@ -163,12 +163,10 @@ class TestConsoleAnnotationRefBoundaries:
|
||||
api = annotation_module.AnnotationUpdateDeleteApi()
|
||||
handler = unwrap(api.post)
|
||||
update_mock = Mock(return_value=_annotation_model())
|
||||
payload = {"question": "updated"}
|
||||
_persist_app(sqlite_session)
|
||||
|
||||
with (
|
||||
app.test_request_context("/annotations/ann-1", method="POST", json=payload),
|
||||
patch.object(type(annotation_module.console_ns), "payload", payload),
|
||||
app.test_request_context("/annotations/ann-1", method="POST", json={"question": "updated"}),
|
||||
patch.object(
|
||||
annotation_module,
|
||||
"current_account_with_tenant",
|
||||
@@ -176,7 +174,13 @@ class TestConsoleAnnotationRefBoundaries:
|
||||
),
|
||||
patch.object(annotation_module.AppAnnotationService, "update_app_annotation_directly", update_mock),
|
||||
):
|
||||
response = handler(api, sqlite_session, "app-1", "ann-1")
|
||||
response = handler(
|
||||
api,
|
||||
annotation_module.UpdateAnnotationPayload(question="updated"),
|
||||
sqlite_session,
|
||||
"app-1",
|
||||
"ann-1",
|
||||
)
|
||||
|
||||
assert response["question"] == "q"
|
||||
update_mock.assert_called_once()
|
||||
|
||||
@@ -301,7 +301,7 @@ class TestOpsTraceEndpoints:
|
||||
)
|
||||
|
||||
with app.test_request_context("/?tracing_provider=langfuse"):
|
||||
result = method(api, app_model=MagicMock(id="app-1"))
|
||||
result = method(api, TraceProviderQuery(tracing_provider="langfuse"), MagicMock(id="app-1"))
|
||||
|
||||
assert result == {"has_not_configured": True}
|
||||
|
||||
@@ -320,7 +320,11 @@ class TestOpsTraceEndpoints:
|
||||
json={"tracing_provider": "langfuse", "tracing_config": {"api_key": "k"}},
|
||||
):
|
||||
with pytest.raises(BadRequest):
|
||||
method(api, app_model=MagicMock(id="app-1"))
|
||||
method(
|
||||
api,
|
||||
TraceConfigPayload(tracing_provider="langfuse", tracing_config={"api_key": "k"}),
|
||||
MagicMock(id="app-1"),
|
||||
)
|
||||
|
||||
def test_trace_app_config_delete_not_found(self, app: Flask, monkeypatch: pytest.MonkeyPatch):
|
||||
api = ops_trace_module.TraceAppConfigApi()
|
||||
@@ -334,7 +338,7 @@ class TestOpsTraceEndpoints:
|
||||
|
||||
with app.test_request_context("/?tracing_provider=langfuse"):
|
||||
with pytest.raises(BadRequest):
|
||||
method(api, app_model=MagicMock(id="app-1"))
|
||||
method(api, TraceProviderQuery(tracing_provider="langfuse"), MagicMock(id="app-1"))
|
||||
|
||||
|
||||
class TestSiteEndpoints:
|
||||
|
||||
Reference in New Issue
Block a user