Files
ai-video-fullstack/backend/tests/test_config_resolver.py
T

39 lines
1.9 KiB
Python

import unittest
from types import SimpleNamespace
from unittest.mock import AsyncMock, Mock
from services.config_resolver import _agent_resource_for, _resource_for
class DisabledResourceTest(unittest.IsolatedAsyncioTestCase):
async def test_disabled_binding_uses_enabled_fallback_for_models_and_agents(self):
for capability, interface_type in (("LLM", "openai-llm"), ("Agent", "dify")):
with self.subTest(capability=capability):
disabled = SimpleNamespace(
id="disabled", capability=capability,
interface_type=interface_type, enabled=False,
)
fallback = SimpleNamespace(id="enabled", enabled=True)
result = Mock()
result.scalar_one_or_none.return_value = fallback
session = SimpleNamespace(
get=AsyncMock(side_effect=[SimpleNamespace(model_resource_id="disabled"), disabled]),
execute=AsyncMock(return_value=result),
)
if capability == "Agent":
selected = await _agent_resource_for(session, "assistant", interface_type)
else:
selected = await _resource_for(session, "assistant", capability)
self.assertIs(selected, fallback)
statement = str(session.execute.await_args.args[0])
self.assertIn("model_resources.enabled IS true", statement)
async def test_enabled_binding_is_preserved(self):
resource = SimpleNamespace(id="enabled", capability="LLM", enabled=True)
session = SimpleNamespace(
get=AsyncMock(side_effect=[SimpleNamespace(model_resource_id=resource.id), resource]),
execute=AsyncMock(),
)
self.assertIs(await _resource_for(session, "assistant", "LLM"), resource)
session.execute.assert_not_awaited()