84 lines
2.6 KiB
Python
84 lines
2.6 KiB
Python
"""
|
|
Дымовой тест АВТОТЕСТА в эмуляции: create через /api/test, история через /api/history.
|
|
|
|
Бьёт в РАЗВЁРНУТЫЙ автотест (atest.pythonk8s.dev.nubes.ru), эмуляция TEST.
|
|
Операции идут через app-autotest -> executor -> save_run -> история в БД.
|
|
"""
|
|
import time, requests
|
|
|
|
BASE = "https://atest.pythonk8s.dev.nubes.ru"
|
|
COOKIES = {"mode": "polygon", "polygon_stand": "test"}
|
|
|
|
|
|
def test_services():
|
|
r = requests.get(f"{BASE}/api/services", cookies=COOKIES, timeout=10)
|
|
assert r.status_code == 200
|
|
svc = r.json()
|
|
assert len(svc) > 0
|
|
return svc
|
|
|
|
|
|
def test_create(svc_id):
|
|
r = requests.post(f"{BASE}/api/test",
|
|
json={"serviceId": svc_id, "operation": "create", "svcOperationId": 18,
|
|
"params": {}, "displayName": f"autotest-smoke-{svc_id}"},
|
|
cookies=COOKIES, timeout=30)
|
|
assert r.status_code == 200, f"Create failed: {r.text[:200]}"
|
|
data = r.json()
|
|
assert data["status"] == "RUNNING"
|
|
return data["opUid"], data.get("instanceUid")
|
|
|
|
|
|
def poll(op_uid, timeout=10):
|
|
deadline = time.time() + timeout
|
|
while time.time() < deadline:
|
|
r = requests.get(f"{BASE}/api/test/status/{op_uid}", cookies=COOKIES, timeout=5)
|
|
d = r.json()
|
|
if d.get("done") or d.get("status") in ("OK", "FAIL"):
|
|
return d
|
|
time.sleep(0.5)
|
|
return {"status": "TIMEOUT"}
|
|
|
|
|
|
def test_history():
|
|
r = requests.get(f"{BASE}/api/history", cookies=COOKIES, timeout=10)
|
|
assert r.status_code == 200
|
|
rows = r.json()
|
|
assert len(rows) > 0, "История пустая!"
|
|
return rows
|
|
|
|
|
|
if __name__ == "__main__":
|
|
print("=" * 60)
|
|
print("Дымовой тест АВТОТЕСТА (эмуляция TEST)")
|
|
print("=" * 60)
|
|
|
|
svc = test_services()
|
|
print(f"Сервисов: {len(svc)}")
|
|
|
|
ok = fail = 0
|
|
for s in svc[:3]:
|
|
sid, sname = s["svcId"], s["svc"]
|
|
try:
|
|
op_uid, iuid = test_create(sid)
|
|
result = poll(op_uid)
|
|
if result.get("status") == "OK":
|
|
print(f" OK {sid} {sname}")
|
|
ok += 1
|
|
else:
|
|
print(f" FAIL {sid} {sname} -> {result}")
|
|
fail += 1
|
|
except Exception as e:
|
|
print(f" FAIL {sid} {sname} -> {e}")
|
|
fail += 1
|
|
|
|
print(f"\nCreate: OK={ok} FAIL={fail}")
|
|
|
|
rows = test_history()
|
|
print(f"История: {len(rows)} записей")
|
|
for r in rows[:3]:
|
|
print(f" {r['created_at'][:19]} {r['op_name']:8s} {r['status']}")
|
|
|
|
print(f"\n{'='*60}")
|
|
print(f"РЕЗУЛЬТАТ: {'PASS' if fail == 0 else 'FAIL'}")
|