-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_api.py
More file actions
40 lines (28 loc) · 1.5 KB
/
Copy pathtest_api.py
File metadata and controls
40 lines (28 loc) · 1.5 KB
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
"""Prod API smoke test via FastAPI TestClient — exercises the real HTTP layer
with mock embeddings (no API key). Requires `pip install -r requirements.txt`.
Run: python3 test_api.py
"""
import os
import tempfile
os.environ["CORTEX_STORE_DIR"] = tempfile.mkdtemp(prefix="cortex_api_")
from fastapi.testclient import TestClient
from main import app
c = TestClient(app)
assert c.get("/health").json()["status"] == "ok"
r = c.post("/remember", json={"namespace": "u1", "content": "The user is allergic to nuts",
"kind": "fact", "salience": 0.95})
assert r.status_code == 200, r.text
mid = r.json()["memory"]["id"]
r = c.post("/recall", json={"namespace": "u1", "query": "is the user allergic to nuts"})
assert any("allergic" in m["content"] for m in r.json()["memories"]), r.text
# namespace isolation
assert c.get("/memories", params={"namespace": "u2"}).json()["memories"] == []
# audit trail present
assert len(c.get("/audit", params={"namespace": "u1"}).json()["audit"]) >= 1
# delete (right to be forgotten)
assert c.delete(f"/memories/{mid}", params={"namespace": "u1"}).status_code == 200
assert c.get("/memories", params={"namespace": "u1"}).json()["memories"] == []
# input validation
assert c.post("/remember", json={"namespace": "u1", "content": "", "kind": "fact"}).status_code == 422
assert c.post("/remember", json={"namespace": "u1", "content": "x", "kind": "bogus"}).status_code == 422
print("PASS: /health /remember /recall /memories /audit /delete + isolation + validation")