mirror of
https://github.com/jhd3197/ServerKit.git
synced 2026-10-27 23:28:03 +09:00
One-click PowerShell entry point that spins up Ubuntu/Debian VMs in parallel, installs ServerKit from the local working tree (not origin/main), runs a pytest API harness against the live panel, and aggregates results into a self-contained HTML report. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
69 lines
1.7 KiB
Python
69 lines
1.7 KiB
Python
import os
|
|
import time
|
|
import uuid
|
|
import requests
|
|
import pytest
|
|
|
|
BASE_URL = os.environ.get("SERVERKIT_URL", "http://127.0.0.1:5000")
|
|
TIMEOUT = 15
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def base_url():
|
|
return BASE_URL
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def http():
|
|
s = requests.Session()
|
|
s.headers.update({"Accept": "application/json"})
|
|
return s
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def admin_credentials():
|
|
suffix = uuid.uuid4().hex[:8]
|
|
return {
|
|
"email": f"e2e-{suffix}@test.local",
|
|
"username": f"e2e_{suffix}",
|
|
"password": "Test12345!",
|
|
}
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def admin_token(http, base_url, admin_credentials):
|
|
"""Register the first user (becomes admin) or log in if already exists."""
|
|
# Wait briefly for backend in case test runs immediately after install
|
|
for _ in range(30):
|
|
try:
|
|
r = http.get(f"{base_url}/api/v1/system/health", timeout=2)
|
|
if r.status_code == 200:
|
|
break
|
|
except requests.RequestException:
|
|
time.sleep(1)
|
|
|
|
r = http.post(
|
|
f"{base_url}/api/v1/auth/register",
|
|
json=admin_credentials,
|
|
timeout=TIMEOUT,
|
|
)
|
|
if r.status_code in (200, 201):
|
|
return r.json()["access_token"]
|
|
|
|
# Fallback: maybe already registered (re-run on same VM)
|
|
r = http.post(
|
|
f"{base_url}/api/v1/auth/login",
|
|
json={
|
|
"email": admin_credentials["email"],
|
|
"password": admin_credentials["password"],
|
|
},
|
|
timeout=TIMEOUT,
|
|
)
|
|
r.raise_for_status()
|
|
return r.json()["access_token"]
|
|
|
|
|
|
@pytest.fixture
|
|
def auth_headers(admin_token):
|
|
return {"Authorization": f"Bearer {admin_token}"}
|