ai: cover atlasbot timeout behavior
This commit is contained in:
parent
0e7b9452c1
commit
2a3ee95e74
@ -59,3 +59,56 @@ class AiRouteTests(TestCase):
|
||||
self.assertEqual(resp.status_code, 200)
|
||||
self.assertEqual(data.get("profile"), "atlas-genius")
|
||||
self.assertEqual(data.get("model"), "genius-model")
|
||||
|
||||
def test_atlasbot_answer_uses_profile_specific_timeout(self):
|
||||
captured: dict[str, object] = {}
|
||||
|
||||
class DummyResponse:
|
||||
status_code = 200
|
||||
|
||||
def json(self):
|
||||
return {"reply": "atlas reply"}
|
||||
|
||||
class DummyClient:
|
||||
def __init__(self, timeout):
|
||||
captured["timeout"] = timeout
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type, exc, tb):
|
||||
return False
|
||||
|
||||
def post(self, endpoint, json=None, headers=None):
|
||||
captured["endpoint"] = endpoint
|
||||
captured["json"] = json
|
||||
captured["headers"] = headers or {}
|
||||
return DummyResponse()
|
||||
|
||||
with (
|
||||
mock.patch.object(ai.httpx, "Client", DummyClient),
|
||||
mock.patch.object(ai.settings, "AI_ATLASBOT_ENDPOINT", "http://atlasbot.invalid/v1/answer"),
|
||||
):
|
||||
reply = ai._atlasbot_answer("How is Titan doing?", "genius", "conv-1")
|
||||
|
||||
self.assertEqual(reply, "atlas reply")
|
||||
self.assertEqual(captured["timeout"], ai.settings.AI_ATLASBOT_TIMEOUT_GENIUS_SEC)
|
||||
self.assertEqual(captured["json"], {"prompt": "How is Titan doing?", "mode": "genius", "conversation_id": "conv-1"})
|
||||
|
||||
def test_chat_returns_fallback_when_atlasbot_returns_empty(self):
|
||||
with mock.patch.object(ai, "_atlasbot_answer", return_value=""):
|
||||
resp = self.client.post(
|
||||
"/api/chat",
|
||||
data=json.dumps(
|
||||
{
|
||||
"message": "How is Titan doing?",
|
||||
"profile": "atlas-quick",
|
||||
}
|
||||
),
|
||||
content_type="application/json",
|
||||
)
|
||||
|
||||
data = resp.get_json()
|
||||
self.assertEqual(resp.status_code, 200)
|
||||
self.assertEqual(data.get("source"), "atlas-quick")
|
||||
self.assertIn("Quick mode hit", data.get("reply", ""))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user