Files
dify/api/tests/unit_tests/controllers/console/test_spec.py
Mohammed Aqib a66b1de477 refactor: Use pytest caplog instead of logger patching in test_spec.py (#37997)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2026-06-26 04:48:22 +00:00

39 lines
1.0 KiB
Python

from inspect import unwrap
from unittest.mock import patch
import controllers.console.spec as spec_module
class TestSpecSchemaDefinitionsApi:
def test_get_success(self):
api = spec_module.SpecSchemaDefinitionsApi()
method = unwrap(api.get)
schema_definitions = [{"type": "string"}]
with patch.object(
spec_module,
"SchemaManager",
) as schema_manager_cls:
schema_manager_cls.return_value.get_all_schema_definitions.return_value = schema_definitions
resp, status = method(api)
assert status == 200
assert resp == schema_definitions
def test_get_exception_returns_empty_list(self, caplog):
api = spec_module.SpecSchemaDefinitionsApi()
method = unwrap(api.get)
with patch.object(
spec_module,
"SchemaManager",
side_effect=Exception("boom"),
):
resp, status = method(api)
assert status == 200
assert resp == []
assert "boom" in caplog.text