From 936a09c70494ecbf83a1a52a10a726136241b80a Mon Sep 17 00:00:00 2001 From: EvanYao <2869018789@qq.com> Date: Fri, 8 May 2026 11:18:21 +0800 Subject: [PATCH] fix: replace SimpleNamespace with MagicMock(spec=App) in _app_stub (#34636) (#35897) Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> --- .../services/test_app_dsl_service.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/api/tests/test_containers_integration_tests/services/test_app_dsl_service.py b/api/tests/test_containers_integration_tests/services/test_app_dsl_service.py index 6b844615b5..7c5d2390ba 100644 --- a/api/tests/test_containers_integration_tests/services/test_app_dsl_service.py +++ b/api/tests/test_containers_integration_tests/services/test_app_dsl_service.py @@ -3,7 +3,7 @@ from __future__ import annotations import base64 import json from types import SimpleNamespace -from typing import Any, cast +from typing import Any from unittest.mock import MagicMock, patch from uuid import uuid4 @@ -71,6 +71,7 @@ def _pending_yaml_content(version: str = "99.0.0") -> bytes: def _app_stub(**overrides: Any) -> App: + """Create a stub App object for testing without hitting the database.""" defaults = { "id": str(uuid4()), "tenant_id": _DEFAULT_TENANT_ID, @@ -83,7 +84,10 @@ def _app_stub(**overrides: Any) -> App: "use_icon_as_answer_icon": False, "app_model_config": None, } - return cast(App, SimpleNamespace(**(defaults | overrides))) + app = MagicMock(spec=App) + for key, value in (defaults | overrides).items(): + object.__setattr__(app, key, value) + return app class TestAppDslService: