promptlooper/backend/tests/test_routers.py
John Lightner 0f64dfbb02 MAESTRO: Implement webhook CRUD router, async dispatch with retry logic, and delivery logging
Full webhook system: CRUD endpoints (list/filter/get/create/update/delete),
WebhookDelivery model for delivery audit trail, dispatch engine with 3-attempt
retry and exponential backoff, Celery task integration with sync fallback,
and webhook firing hooks in runner.py and sweep.py event paths.
2026-04-07 03:41:04 -05:00

226 lines
6.1 KiB
Python

"""Tests for router stubs — verify all routes are mounted and return 501."""
import pytest
from fastapi.testclient import TestClient
@pytest.fixture()
def client(tmp_path, monkeypatch):
"""Create a test client with a temporary database."""
monkeypatch.setenv("DATA_DIR", str(tmp_path))
monkeypatch.setenv("DATABASE_URL", "")
monkeypatch.setenv("REDIS_URL", "")
# Reload config to pick up test env
import importlib
import config as config_mod
importlib.reload(config_mod)
import main as main_mod
importlib.reload(main_mod)
with TestClient(main_mod.app) as c:
yield c
# ---- Auth router (/api/auth) ----
def test_auth_setup(client):
resp = client.post("/api/auth/setup")
assert resp.status_code == 501
def test_auth_login(client):
resp = client.post("/api/auth/login")
assert resp.status_code == 501
def test_auth_me(client):
resp = client.get("/api/auth/me")
assert resp.status_code == 501
# ---- Projects router (/api/projects) ----
def test_projects_list(client):
resp = client.get("/api/projects/")
assert resp.status_code == 501
def test_projects_create(client):
resp = client.post("/api/projects/")
assert resp.status_code == 501
def test_projects_get(client):
resp = client.get("/api/projects/00000000-0000-0000-0000-000000000001")
assert resp.status_code == 501
def test_projects_update(client):
resp = client.put("/api/projects/00000000-0000-0000-0000-000000000001")
assert resp.status_code == 501
def test_projects_delete(client):
resp = client.delete("/api/projects/00000000-0000-0000-0000-000000000001")
assert resp.status_code == 501
# ---- Experiments router (/api/experiments) — now implemented, requires auth ----
def test_experiments_list(client):
resp = client.get("/api/experiments/")
assert resp.status_code == 401
def test_experiments_create(client):
resp = client.post("/api/experiments/")
assert resp.status_code == 401
def test_experiments_get(client):
resp = client.get("/api/experiments/00000000-0000-0000-0000-000000000001")
assert resp.status_code == 401
def test_experiments_update(client):
resp = client.put("/api/experiments/00000000-0000-0000-0000-000000000001")
assert resp.status_code == 401
def test_experiments_delete(client):
resp = client.delete("/api/experiments/00000000-0000-0000-0000-000000000001")
assert resp.status_code == 401
def test_experiments_sweep(client):
resp = client.post("/api/experiments/00000000-0000-0000-0000-000000000001/sweep")
assert resp.status_code == 401
def test_experiments_pause(client):
resp = client.post("/api/experiments/00000000-0000-0000-0000-000000000001/pause")
assert resp.status_code == 401
def test_experiments_resume(client):
resp = client.post("/api/experiments/00000000-0000-0000-0000-000000000001/resume")
assert resp.status_code == 401
def test_experiments_stop(client):
resp = client.post("/api/experiments/00000000-0000-0000-0000-000000000001/stop")
assert resp.status_code == 401
# ---- Runs router (/api/runs) ----
def test_runs_list(client):
resp = client.get("/api/runs/")
# Runs router is now fully implemented and requires auth (returns 401 without credentials)
assert resp.status_code == 401
def test_runs_get(client):
resp = client.get("/api/runs/00000000-0000-0000-0000-000000000001")
assert resp.status_code == 401
def test_runs_create(client):
resp = client.post("/api/runs/")
assert resp.status_code == 401
def test_runs_score(client):
resp = client.post("/api/runs/00000000-0000-0000-0000-000000000001/score")
assert resp.status_code == 401
def test_runs_leaderboard(client):
resp = client.get("/api/runs/leaderboard/00000000-0000-0000-0000-000000000001")
assert resp.status_code == 401
# ---- Endpoints router (/api/endpoints) ----
# Endpoints router is now fully implemented and requires auth (returns 401 without credentials)
def test_endpoints_list(client):
resp = client.get("/api/endpoints/")
assert resp.status_code == 401
def test_endpoints_create(client):
resp = client.post("/api/endpoints/")
assert resp.status_code == 401
def test_endpoints_update(client):
resp = client.put("/api/endpoints/00000000-0000-0000-0000-000000000001")
assert resp.status_code == 401
def test_endpoints_delete(client):
resp = client.delete("/api/endpoints/00000000-0000-0000-0000-000000000001")
assert resp.status_code == 401
def test_endpoints_test(client):
resp = client.post("/api/endpoints/00000000-0000-0000-0000-000000000001/test")
assert resp.status_code == 401
# ---- Export router (/api/export) ----
def test_export_best(client):
resp = client.get("/api/export/experiments/00000000-0000-0000-0000-000000000001/best")
assert resp.status_code == 401
def test_export_env(client):
resp = client.get("/api/export/experiments/00000000-0000-0000-0000-000000000001/env")
assert resp.status_code == 401
def test_export_yaml(client):
resp = client.get("/api/export/experiments/00000000-0000-0000-0000-000000000001/yaml")
assert resp.status_code == 401
def test_export_report(client):
resp = client.get("/api/export/experiments/00000000-0000-0000-0000-000000000001/report")
assert resp.status_code == 401
# ---- Webhooks router (/api/webhooks) ----
def test_webhooks_list(client):
resp = client.get("/api/webhooks/")
assert resp.status_code == 401 # auth required
def test_webhooks_create(client):
resp = client.post("/api/webhooks/")
assert resp.status_code == 401 # auth required
def test_webhooks_delete(client):
resp = client.delete("/api/webhooks/00000000-0000-0000-0000-000000000001")
assert resp.status_code == 401 # auth required
# ---- Admin router (/api/admin) ----
def test_admin_get_settings(client):
resp = client.get("/api/admin/settings")
assert resp.status_code == 501
def test_admin_update_settings(client):
resp = client.put("/api/admin/settings")
assert resp.status_code == 501
def test_admin_stats(client):
resp = client.get("/api/admin/stats")
assert resp.status_code == 501