|
|
|
|
@ -1,12 +1,10 @@
|
|
|
|
|
import unittest
|
|
|
|
|
from types import SimpleNamespace
|
|
|
|
|
from unittest.mock import AsyncMock, patch
|
|
|
|
|
|
|
|
|
|
from app import main as main_module
|
|
|
|
|
from app.core.settings import Settings
|
|
|
|
|
from app.db import bootstrap as bootstrap_module
|
|
|
|
|
from app.db import init_db as init_db_module
|
|
|
|
|
from app.db import tool_seed as tool_seed_module
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SettingsParsingTests(unittest.TestCase):
|
|
|
|
|
@ -83,45 +81,6 @@ class BootstrapRuntimeTests(unittest.TestCase):
|
|
|
|
|
bootstrap_databases.assert_called_once_with()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ToolSeedTests(unittest.TestCase):
|
|
|
|
|
def test_seed_tools_remove_tool_legada_de_multa(self):
|
|
|
|
|
class FakeToolRepo:
|
|
|
|
|
def __init__(self, tools):
|
|
|
|
|
self.tools = list(tools)
|
|
|
|
|
self.deleted_ids = []
|
|
|
|
|
|
|
|
|
|
def get_all(self):
|
|
|
|
|
return list(self.tools)
|
|
|
|
|
|
|
|
|
|
def delete(self, tool_id):
|
|
|
|
|
self.deleted_ids.append(tool_id)
|
|
|
|
|
self.tools = [tool for tool in self.tools if tool.id != tool_id]
|
|
|
|
|
|
|
|
|
|
def update_by_name(self, **kwargs):
|
|
|
|
|
return kwargs
|
|
|
|
|
|
|
|
|
|
def create(self, **kwargs):
|
|
|
|
|
return kwargs
|
|
|
|
|
|
|
|
|
|
repo = FakeToolRepo(
|
|
|
|
|
[
|
|
|
|
|
SimpleNamespace(id=1, name="registrar_multa_aluguel"),
|
|
|
|
|
SimpleNamespace(id=2, name="consultar_estoque"),
|
|
|
|
|
]
|
|
|
|
|
)
|
|
|
|
|
fake_db = SimpleNamespace(close=lambda: None)
|
|
|
|
|
|
|
|
|
|
with patch.object(tool_seed_module, "SessionLocal", return_value=fake_db), patch.object(
|
|
|
|
|
tool_seed_module,
|
|
|
|
|
"ToolRepository",
|
|
|
|
|
return_value=repo,
|
|
|
|
|
):
|
|
|
|
|
tool_seed_module.seed_tools()
|
|
|
|
|
|
|
|
|
|
self.assertEqual(repo.deleted_ids, [1])
|
|
|
|
|
self.assertFalse(any(tool.name == "registrar_multa_aluguel" for tool in repo.get_all()))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class HttpStartupTests(unittest.IsolatedAsyncioTestCase):
|
|
|
|
|
async def test_startup_event_warms_llm_without_running_bootstrap(self):
|
|
|
|
|
with patch("app.main.LLMService") as llm_cls, patch(
|
|
|
|
|
|