shaml / test_request.py
Cursor Agent
Add Diac API backend, Arabic RTL frontend, Docker, and docs
0b083c6 unverified
raw
history blame contribute delete
904 Bytes
"""Simple smoke test for the diacritization API."""
import os
import sys
import requests
BASE = os.getenv("API_BASE", "http://localhost:8000")
HEADERS = {"Content-Type": "application/json"}
if key := os.getenv("API_KEY"):
HEADERS["X-API-Key"] = key
def main() -> int:
health = requests.get(f"{BASE}/health", timeout=30)
health.raise_for_status()
print("health:", health.json())
payload = {"text": "كتب الطالب الدرس"}
response = requests.post(f"{BASE}/diacritize", json=payload, headers=HEADERS, timeout=120)
response.raise_for_status()
data = response.json()
assert "diacritized" in data, data
print("diacritize:", data)
return 0
if __name__ == "__main__":
try:
raise SystemExit(main())
except requests.RequestException as exc:
print(f"Request failed: {exc}", file=sys.stderr)
raise SystemExit(1) from exc