fix: PEP8 Style
This commit is contained in:
@@ -6,13 +6,15 @@ from src.naliiabot.bot.factories.llm_factory import LLMFactory
|
||||
from httpx import ASGITransport, AsyncClient
|
||||
from naliiabotapi.main import app
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
async def async_client():
|
||||
"""Fixture para un cliente HTTP asíncrono."""
|
||||
|
||||
async with AsyncClient(
|
||||
transport=ASGITransport(app=app),
|
||||
base_url="http://localhost:8010") as client:
|
||||
base_url="http://localhost:8010"
|
||||
) as client:
|
||||
|
||||
yield client
|
||||
|
||||
@@ -73,101 +75,101 @@ def send_message_payload():
|
||||
"""Payload de ejemplo para enviar mensajes al webhook."""
|
||||
return {
|
||||
"event": "messages.upsert",
|
||||
"instance": "ALEJANDRO AYALA",
|
||||
"instance": "ALEJANDRO AYALA",
|
||||
"data": {
|
||||
"key": {
|
||||
"remoteJid": "5512992544490@s.whatsapp.net",
|
||||
"remoteJidAlt": "5512992544490@s.whatsapp.net",
|
||||
"fromMe": False, "id": "AC4367597BDC50537133B9C8848B2E62",
|
||||
"participant": "", "addressingMode": "lid"
|
||||
},
|
||||
"pushName": "Alejandro",
|
||||
"status": "DELIVERY_ACK",
|
||||
"message": {
|
||||
"conversation": "Hola",
|
||||
"messageContextInfo": {
|
||||
"threadId": [],
|
||||
"deviceListMetadata": {
|
||||
"senderKeyIndexes": [],
|
||||
"recipientKeyIndexes": [],
|
||||
"senderKeyHash": {
|
||||
"0": 154,
|
||||
"1": 106,
|
||||
"2": 69,
|
||||
"3": 189,
|
||||
"4": 90,
|
||||
"5": 105,
|
||||
"6": 172,
|
||||
"7": 243,
|
||||
"8": 27,
|
||||
"9": 98
|
||||
},
|
||||
"senderTimestamp": {
|
||||
"low": 1772156772,
|
||||
"high": 0,
|
||||
"unsigned": "true"
|
||||
},
|
||||
"recipientKeyHash": {
|
||||
"0": 16,
|
||||
"1": 98,
|
||||
"2": 75,
|
||||
"3": 100,
|
||||
"4": 131,
|
||||
"5": 43,
|
||||
"6": 24,
|
||||
"7": 225,
|
||||
"8": 244,
|
||||
"9": 126
|
||||
},
|
||||
"recipientTimestamp": {
|
||||
"low": 1772155597,
|
||||
"high": 0,
|
||||
"unsigned": True
|
||||
}
|
||||
},
|
||||
"deviceListMetadataVersion": 2,
|
||||
"messageSecret": {
|
||||
"0": 100,
|
||||
"1": 47,
|
||||
"2": 112,
|
||||
"3": 133,
|
||||
"4": 255,
|
||||
"5": 156,
|
||||
"6": 129,
|
||||
"7": 57,
|
||||
"8": 239,
|
||||
"9": 219,
|
||||
"10": 74,
|
||||
"11": 171,
|
||||
"12": 212,
|
||||
"13": 150,
|
||||
"14": 112,
|
||||
"15": 83,
|
||||
"16": 123,
|
||||
"17": 78,
|
||||
"18": 189,
|
||||
"19": 13,
|
||||
"20": 51,
|
||||
"21": 133,
|
||||
"22": 129,
|
||||
"23": 6,
|
||||
"24": 197,
|
||||
"25": 119,
|
||||
"26": 197,
|
||||
"27": 56,
|
||||
"28": 87,
|
||||
"29": 176,
|
||||
"30": 135,
|
||||
"31": 62
|
||||
}}},
|
||||
"messageType": "conversation",
|
||||
"messageTimestamp": 1772168493,
|
||||
"instanceId": "75a877f1-d772-422b-a6f1-6ac470af5663",
|
||||
"source": "android"
|
||||
},
|
||||
"destination": "http://192.168.58.110:8010/webhook",
|
||||
"date_time": "2026-02-27T02:01:34.178Z",
|
||||
"sender": "573016859278@s.whatsapp.net",
|
||||
"server_url": "http://localhost:8080",
|
||||
"apikey": "98B6B820AFC3-4544-9A4C-011B0719C2D1"
|
||||
}
|
||||
},
|
||||
"pushName": "Alejandro",
|
||||
"status": "DELIVERY_ACK",
|
||||
"message": {
|
||||
"conversation": "Hola",
|
||||
"messageContextInfo": {
|
||||
"threadId": [],
|
||||
"deviceListMetadata": {
|
||||
"senderKeyIndexes": [],
|
||||
"recipientKeyIndexes": [],
|
||||
"senderKeyHash": {
|
||||
"0": 154,
|
||||
"1": 106,
|
||||
"2": 69,
|
||||
"3": 189,
|
||||
"4": 90,
|
||||
"5": 105,
|
||||
"6": 172,
|
||||
"7": 243,
|
||||
"8": 27,
|
||||
"9": 98
|
||||
},
|
||||
"senderTimestamp": {
|
||||
"low": 1772156772,
|
||||
"high": 0,
|
||||
"unsigned": "true"
|
||||
},
|
||||
"recipientKeyHash": {
|
||||
"0": 16,
|
||||
"1": 98,
|
||||
"2": 75,
|
||||
"3": 100,
|
||||
"4": 131,
|
||||
"5": 43,
|
||||
"6": 24,
|
||||
"7": 225,
|
||||
"8": 244,
|
||||
"9": 126
|
||||
},
|
||||
"recipientTimestamp": {
|
||||
"low": 1772155597,
|
||||
"high": 0,
|
||||
"unsigned": True
|
||||
}
|
||||
},
|
||||
"deviceListMetadataVersion": 2,
|
||||
"messageSecret": {
|
||||
"0": 100,
|
||||
"1": 47,
|
||||
"2": 112,
|
||||
"3": 133,
|
||||
"4": 255,
|
||||
"5": 156,
|
||||
"6": 129,
|
||||
"7": 57,
|
||||
"8": 239,
|
||||
"9": 219,
|
||||
"10": 74,
|
||||
"11": 171,
|
||||
"12": 212,
|
||||
"13": 150,
|
||||
"14": 112,
|
||||
"15": 83,
|
||||
"16": 123,
|
||||
"17": 78,
|
||||
"18": 189,
|
||||
"19": 13,
|
||||
"20": 51,
|
||||
"21": 133,
|
||||
"22": 129,
|
||||
"23": 6,
|
||||
"24": 197,
|
||||
"25": 119,
|
||||
"26": 197,
|
||||
"27": 56,
|
||||
"28": 87,
|
||||
"29": 176,
|
||||
"30": 135,
|
||||
"31": 62
|
||||
}}},
|
||||
"messageType": "conversation",
|
||||
"messageTimestamp": 1772168493,
|
||||
"instanceId": "75a877f1-d772-422b-a6f1-6ac470af5663",
|
||||
"source": "android"
|
||||
},
|
||||
"destination": "http://192.168.58.110:8010/webhook",
|
||||
"date_time": "2026-02-27T02:01:34.178Z",
|
||||
"sender": "573016859278@s.whatsapp.net",
|
||||
"server_url": "http://localhost:8080",
|
||||
"apikey": "98B6B820AFC3-4544-9A4C-011B0719C2D1"
|
||||
}
|
||||
|
||||
@@ -375,8 +375,9 @@ class TestIntegrationFlows:
|
||||
assert "messages" in result
|
||||
assert "llm_calls" in result
|
||||
assert result["llm_calls"] == 1
|
||||
assert len(result["messages"]) == 2 # Input + Response
|
||||
assert result["messages"][-1].content == "¡Hola! ¿En qué puedo ayudarte?"
|
||||
assert len(result["messages"]) == 2
|
||||
assert result["messages"][-1].content == (
|
||||
"¡Hola! ¿En qué puedo ayudarte?")
|
||||
|
||||
def test_tool_use_flow(self, agent_with_tool):
|
||||
"""
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
from src.naliiabotapi.main import app
|
||||
from langchain_core.messages import HumanMessage
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -10,16 +9,19 @@ def client():
|
||||
|
||||
return client
|
||||
|
||||
|
||||
def test_root(client):
|
||||
response = client.get("/")
|
||||
|
||||
assert response.status_code == 200
|
||||
|
||||
|
||||
def test_health(client):
|
||||
response = client.get("/health")
|
||||
|
||||
assert response.status_code == 200
|
||||
|
||||
|
||||
def test_chat(client):
|
||||
response = client.post("/chat", json={"messages": "Hello, how are you?"})
|
||||
|
||||
|
||||
@@ -26,11 +26,14 @@ class TestWebhookChatBot:
|
||||
# Sobrescribir la dependencia del agente en la app
|
||||
app.dependency_overrides[get_agent] = lambda: mock_agent
|
||||
|
||||
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://localhost:8010") as client:
|
||||
async with AsyncClient(
|
||||
transport=ASGITransport(app=app),
|
||||
base_url="http://localhost:8010"
|
||||
) as client:
|
||||
response = await client.post("/webhook", json=send_message_payload)
|
||||
|
||||
# Limpiar override para no afectar a otros tests
|
||||
app.dependency_overrides.pop(get_agent, None)
|
||||
|
||||
assert response.status_code == 200
|
||||
assert response.json().get("reply") == "Respuesta mock"
|
||||
assert response.json().get("reply") == "Respuesta mock"
|
||||
|
||||
Reference in New Issue
Block a user