fix: use TestClient as context manager to trigger lifespan
This commit is contained in:
@@ -40,5 +40,5 @@ dev = [
|
|||||||
|
|
||||||
[tool.taskipy.tasks]
|
[tool.taskipy.tasks]
|
||||||
dev = "uvicorn src.naliiabotapi.main:app --host 0.0.0.0 --port 8010 --reload"
|
dev = "uvicorn src.naliiabotapi.main:app --host 0.0.0.0 --port 8010 --reload"
|
||||||
test = "pytest -v"
|
test = "pytest -vv"
|
||||||
test-cov = "pytest tests/test_agent.py --cov=src.naliiabot.bot.agent --cov-report=html && python -m http.server 8000 --directory htmlcov"
|
test-cov = "pytest tests/test_agent.py --cov=src.naliiabot.bot.agent --cov-report=html && python -m http.server 8000 --directory htmlcov"
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ from .schemes import ScheduleSchema
|
|||||||
|
|
||||||
|
|
||||||
TIMEZONE = "America/Bogota"
|
TIMEZONE = "America/Bogota"
|
||||||
MCP_SERVER_URL = "http://localhost:8001/mcp"
|
MCP_SERVER_URL = "http://192.168.58.109:3001/mcp"
|
||||||
_MCP_CLIENT = Client(MCP_SERVER_URL)
|
_MCP_CLIENT = Client(MCP_SERVER_URL)
|
||||||
|
|
||||||
|
|
||||||
@@ -76,10 +76,10 @@ class NaliiaTools:
|
|||||||
@tool
|
@tool
|
||||||
def find_customer_by_identifier(identifier: str) -> str:
|
def find_customer_by_identifier(identifier: str) -> str:
|
||||||
"""
|
"""
|
||||||
Busca un cliente por su identificador (teléfono, email o número de documento).
|
Busca un cliente por su identificador (teléfono o número de documento).
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
identifier: Identificador del cliente (teléfono, email o número de documento).
|
identifier: Identificador del cliente (teléfono o número de documento).
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
str: JSON con la información del cliente encontrado.
|
str: JSON con la información del cliente encontrado.
|
||||||
@@ -97,6 +97,7 @@ class NaliiaTools:
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
result = asyncio.run(call_tool())
|
result = asyncio.run(call_tool())
|
||||||
|
|
||||||
return result.content[0].text
|
return result.content[0].text
|
||||||
|
|
||||||
@tool
|
@tool
|
||||||
@@ -122,6 +123,7 @@ class NaliiaTools:
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
result = asyncio.run(call_tool())
|
result = asyncio.run(call_tool())
|
||||||
|
|
||||||
return result.content[0].text
|
return result.content[0].text
|
||||||
|
|
||||||
@tool
|
@tool
|
||||||
@@ -150,6 +152,7 @@ class NaliiaTools:
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
result = asyncio.run(call_tool())
|
result = asyncio.run(call_tool())
|
||||||
|
|
||||||
return result.content[0].text
|
return result.content[0].text
|
||||||
|
|
||||||
@tool(args_schema=ScheduleSchema)
|
@tool(args_schema=ScheduleSchema)
|
||||||
@@ -216,6 +219,8 @@ class NaliiaTools:
|
|||||||
|
|
||||||
logger.info(result)
|
logger.info(result)
|
||||||
|
|
||||||
asyncio.run(call_tool())
|
return result
|
||||||
|
|
||||||
|
result = asyncio.run(call_tool())
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|||||||
@@ -14,7 +14,8 @@ async def send_whatsapp_message(request_data: SendMessageScheme):
|
|||||||
"""
|
"""
|
||||||
Envía un mensaje de texto a través de la API de WhatsApp.
|
Envía un mensaje de texto a través de la API de WhatsApp.
|
||||||
"""
|
"""
|
||||||
instance_url = request_data["instance_url"]
|
# instance_url = request_data["instance_url"]
|
||||||
|
instance_url = 'http://192.168.58.109:8080'
|
||||||
instance_name = request_data["instance_name"]
|
instance_name = request_data["instance_name"]
|
||||||
apikey = request_data["apikey"]
|
apikey = request_data["apikey"]
|
||||||
jid = request_data["jid"]
|
jid = request_data["jid"]
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ class TestAgentConstruction:
|
|||||||
|
|
||||||
agent = Agent(model=mock_model)
|
agent = Agent(model=mock_model)
|
||||||
|
|
||||||
assert agent.config.max_iterations == 10
|
assert agent.config.max_iterations == 200
|
||||||
assert "helpful assistant" in agent.config.system_prompt
|
assert "helpful assistant" in agent.config.system_prompt
|
||||||
assert agent.tools == []
|
assert agent.tools == []
|
||||||
|
|
||||||
|
|||||||
@@ -5,9 +5,8 @@ from src.naliiabotapi.main import app
|
|||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def client():
|
def client():
|
||||||
client = TestClient(app)
|
with TestClient(app) as client:
|
||||||
|
yield client
|
||||||
return client
|
|
||||||
|
|
||||||
|
|
||||||
def test_root(client):
|
def test_root(client):
|
||||||
|
|||||||
Reference in New Issue
Block a user