Spaces:
Sleeping
Sleeping
File size: 1,621 Bytes
bfa95ad | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | from fastapi.testclient import TestClient
from api.app import app
client = TestClient(app)
# Shared bounding box payload for all chat requests
BBOX = {
"north_east": {"lat": 40.0, "lon": -73.0},
"south_west": {"lat": 39.0, "lon": -74.0},
}
def test_health_check():
r = client.get("/health")
assert r.status_code == 200
assert r.json()["status"] == "ok"
def test_chat_with_empty_body():
r = client.post("/chat", json={
"user_input": "",
"conversation_history": [],
"bounding_box": BBOX,
})
assert r.status_code == 200
data = r.json()
assert "agent_reply" in data
def test_chat_with_text_only():
r = client.post("/chat", json={
"user_input": "Find cafes",
"conversation_history": [],
"bounding_box": BBOX,
})
assert r.status_code == 200
data = r.json()
assert "agent_reply" in data
def test_chat_with_bbox_and_text():
r = client.post("/chat", json={
"user_input": "parks",
"conversation_history": [],
"bounding_box": BBOX,
})
assert r.status_code == 200
data = r.json()
assert "agent_reply" in data
def test_chat_with_conversation_history():
history = [
{"human": "hello", "ai": {"message": "Hi there!"}},
{"human": "find restaurants", "ai": {"message": "Here are some places."}},
]
r = client.post("/chat", json={
"user_input": "any cafes?",
"conversation_history": history,
"bounding_box": BBOX,
})
assert r.status_code == 200
data = r.json()
assert len(data["conversation_history"]) >= 3
|