Envirolytics_backend / test_prod_deployment.py
Ayush Modi
Add production test script
359e1e3
import requests
import json
import time
# CONFIG
BASE_URL = "https://ayush472-envirolytics-backend.hf.space"
# BASE_URL = "http://localhost:8000" # Uncomment to test local
def print_result(name, response, expected_status=200):
print(f"\n--- {name} ---")
if response.status_code == expected_status:
print(f"βœ… STATUS: {response.status_code} (OK)")
try:
print("DATA:", json.dumps(response.json(), indent=2))
except:
print("DATA:", response.text)
else:
print(f"❌ FAILED: {response.status_code}")
print("MSG:", response.text)
def run_tests():
print(f"Testing Environment: {BASE_URL}")
print("Wait for 'Cold Start' if this is the first run...")
# 1. Root
try:
resp = requests.get(f"{BASE_URL}/")
print_result("Root Check", resp)
except Exception as e:
print(f"❌ Connection Failed: {e}")
return
# 2. Live Status (DB & OpenAQ)
resp = requests.get(f"{BASE_URL}/api/live-status")
print_result("Live Status", resp)
# 3. Source Attribution (ML Model)
resp = requests.get(f"{BASE_URL}/api/analysis/source-attribution")
print_result("Source Attribution", resp)
# 4. Green QR (Metro) - Database Log Check
payload = {
"user_gps": [28.6139, 77.2090],
"station_gps": [28.6140, 77.2090],
"transport_mode": "METRO"
}
resp = requests.post(f"{BASE_URL}/api/enforce/green-qr", json=payload)
print_result("Green QR (Metro)", resp)
# 5. Industry Audit (Fraud Model)
audit_load = {
"industry_id": "TEST_IND_01",
"nearest_station_pm25": 200.0,
"sensor_readings": {
"pm25": 10.0,
"no2": 20.0,
"so2": 5.0,
"co": 0.5,
"wind": 2.5,
"temp": 25.0
}
}
resp = requests.post(f"{BASE_URL}/api/government/audit-industry", json=audit_load)
print_result("Industry Audit", resp)
if __name__ == "__main__":
run_tests()