83 lines
2.7 KiB
Python
83 lines
2.7 KiB
Python
#!/usr/bin/env python3
|
|
"""WEVAL Functional Tests - exhaustif"""
|
|
import requests,json,sys,glob,os
|
|
BASE="https://localhost"
|
|
V=requests.Session()
|
|
V.verify=False
|
|
P,F=0,0
|
|
|
|
def ok(name):
|
|
global P;P+=1;print(f" PASS {name}")
|
|
def fail(name,reason):
|
|
global F;F+=1;print(f" FAIL {name}: {reason}")
|
|
|
|
# 1. ALL HTML pages return content (not just 200)
|
|
print("=== HTML CONTENT TESTS ===")
|
|
for f in sorted(glob.glob("/var/www/html/*.html")):
|
|
name=os.path.basename(f)
|
|
try:
|
|
r=V.get(f"{BASE}/{name}",timeout=5)
|
|
if r.status_code==200 and len(r.text)>100: ok(name)
|
|
else: fail(name,f"status={r.status_code} size={len(r.text)}")
|
|
except Exception as e: fail(name,str(e)[:50])
|
|
|
|
# 2. Critical dirs
|
|
print("=== DIRECTORY TESTS ===")
|
|
for u in ["/wevads-ia/","/wevia/"]:
|
|
try:
|
|
r=V.get(f"{BASE}{u}",timeout=5)
|
|
if r.status_code==200 and len(r.text)>500: ok(u)
|
|
else: fail(u,f"{r.status_code}")
|
|
except Exception as e: fail(u,str(e)[:50])
|
|
|
|
# 3. APIs return valid JSON
|
|
print("=== API JSON TESTS ===")
|
|
for api in ["/api/ecosystem-health.php","/api/weval-ia"]:
|
|
try:
|
|
if api=="/api/weval-ia":
|
|
r=V.post(f"{BASE}{api}",json={"message":"test","provider":"groq"},timeout=10)
|
|
else:
|
|
r=V.get(f"{BASE}{api}",timeout=5)
|
|
d=r.json()
|
|
if d: ok(api)
|
|
else: fail(api,"empty json")
|
|
except Exception as e: fail(api,str(e)[:50])
|
|
|
|
# 4. WEVIA chatbot responds meaningfully
|
|
print("=== BUSINESS TESTS ===")
|
|
try:
|
|
r=V.post(f"{BASE}/api/weval-ia",json={"message":"bonjour","provider":"groq"},timeout=15)
|
|
d=r.json()
|
|
if d.get("success") or d.get("result") or d.get("response"):
|
|
ok("WEVIA chatbot responds")
|
|
else: fail("WEVIA chatbot","no response field")
|
|
except Exception as e: fail("WEVIA chatbot",str(e)[:50])
|
|
|
|
# 5. DB connectivity
|
|
print("=== DB TESTS ===")
|
|
try:
|
|
import subprocess as sp
|
|
r=sp.run(["psql","-U","postgres","-d","wevia_db","-t","-c","SELECT count(*) FROM pg_tables"],capture_output=True,text=True,timeout=5)
|
|
if int(r.stdout.strip())>0: ok(f"PG wevia_db: {r.stdout.strip()} tables")
|
|
else: fail("PG wevia_db","0 tables")
|
|
except Exception as e: fail("PG wevia_db",str(e)[:50])
|
|
|
|
# 6. Docker
|
|
print("=== INFRA TESTS ===")
|
|
try:
|
|
r=sp.run(["docker","ps","-q"],capture_output=True,text=True,timeout=5)
|
|
n=len(r.stdout.strip().split("\n"))
|
|
if n>=16: ok(f"Docker {n} containers")
|
|
else: fail(f"Docker",f"only {n}")
|
|
except: fail("Docker","cmd fail")
|
|
|
|
# 7. Ollama
|
|
try:
|
|
r=V.get("http://localhost:11434/api/tags",timeout=5)
|
|
n=len(r.json()["models"])
|
|
if n>=8: ok(f"Ollama {n} models")
|
|
else: fail("Ollama",f"only {n}")
|
|
except Exception as e: fail("Ollama",str(e)[:50])
|
|
|
|
print(f"\n=== TOTAL: {P} PASS / {F} FAIL / {P+F} TOTAL ===")
|