from fastapi.testclient import TestClient from main import app import uuid client = TestClient(app) def test_flow(): # 1. Create Session response = client.post("/api/v1/sessions", json={"title": "Test Session"}) assert response.status_code == 201 session_data = response.json() session_id = session_data["id"] print(f"Created Session: {session_id}") # 2. List Sessions response = client.get("/api/v1/sessions") assert response.status_code == 200 sessions = response.json() assert len(sessions) > 0 print(f"Listed {len(sessions)} sessions") # 3. Chat Message (Mocking LightRAG since we don't have it running/installed fully) # Note: This might fail if LightRAGWrapper tries to actually initialize and fails. # We might need to mock LightRAGWrapper in the app. # For this test, we assume the app handles LightRAG initialization failure gracefully # or we mock it. Since we didn't mock it in main.py, this test might error out # if LightRAG dependencies are missing. # However, let's try to send a message. try: response = client.post("/api/v1/chat/message", json={ "session_id": session_id, "content": "Hello", "mode": "hybrid" }) # If it fails due to LightRAG, we catch it. if response.status_code == 200: print("Chat response received") print(response.json()) else: print(f"Chat failed with {response.status_code}: {response.text}") except Exception as e: print(f"Chat execution failed: {e}") # 4. Get History response = client.get(f"/api/v1/sessions/{session_id}/history") assert response.status_code == 200 history = response.json() print(f"History length: {len(history)}") if __name__ == "__main__": test_flow()