"""Quick test of all API endpoints.""" import httpx import json import time BASE = "http://localhost:8000" MASTER = "eJQV7hMfRTo-2j1f2c5po4vq4amD-F4nylHRtGPGkMU" ADM = {"X-API-Key": MASTER} def p(label, r): print(f"\n=== {label} === [{r.status_code}]") try: print(json.dumps(r.json(), indent=2)) except Exception: print(r.text) # Health p("HEALTH", httpx.get(f"{BASE}/health")) # Create key r = httpx.post(f"{BASE}/admin/keys", headers=ADM, json={ "owner": "test_client", "gateways": ["comwave", "comwave3"], "request_limit": 100, "rate_per_minute": 10 }) p("CREATE KEY", r) KEY = r.json()["api_key"] CLI = {"X-API-Key": KEY} # List keys p("LIST KEYS", httpx.get(f"{BASE}/admin/keys", headers=ADM)) # Client usage p("USAGE", httpx.get(f"{BASE}/api/usage", headers=CLI)) # Client gateways p("GATEWAYS", httpx.get(f"{BASE}/api/gateways", headers=CLI)) # Client cooldown p("COOLDOWN", httpx.get(f"{BASE}/api/cooldown", headers=CLI)) # Admin stats p("STATS", httpx.get(f"{BASE}/admin/stats", headers=ADM)) # Security: bad key p("BAD KEY", httpx.get(f"{BASE}/api/usage", headers={"X-API-Key": "fake"})) # Security: no key p("NO KEY", httpx.get(f"{BASE}/api/usage")) # Security: wrong gateway p("WRONG GW", httpx.post(f"{BASE}/api/check/fakegw", headers=CLI, json={"card": "4111111111111111|12|2025|123"})) # Security: bad card format p("BAD CARD", httpx.post(f"{BASE}/api/check/comwave", headers=CLI, json={"card": "not-a-card"})) print("\n=== ALL ENDPOINT TESTS DONE ===")