Spaces:
Sleeping
Sleeping
File size: 1,330 Bytes
673a52e | 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 | #!/usr/bin/env python3
"""Validate /api/search filter behavior (Phase 4 QA)."""
import os
import requests
BASE_URL = os.getenv("BIOFLOW_API_URL", "http://localhost:8000")
def _post(payload):
r = requests.post(f"{BASE_URL}/api/search", json=payload, timeout=30)
try:
return r.status_code, r.json()
except Exception:
return r.status_code, {}
def _skip_if_unavailable(status):
if status in (404, 503):
print("[SKIP] Backend unavailable or not restarted")
return True
return False
def test_filters():
print("Phase 4: /api/search filter tests")
status, data = _post({
"query": "EGFR",
"top_k": 5,
"filters": {"sources": ["pubmed", "uniprot"]},
})
if _skip_if_unavailable(status):
return True
assert status == 200, f"status={status}"
assert "results" in data
status, data = _post({
"query": "EGFR",
"top_k": 5,
"filters": {"modality": "molecule"},
})
assert status == 200
status, data = _post({
"query": "EGFR",
"top_k": 5,
"filters": {"year_min": 2018, "year_max": 2026},
})
assert status == 200
print("[OK] filter tests completed")
return True
if __name__ == "__main__":
ok = test_filters()
raise SystemExit(0 if ok else 1)
|