import asyncio import uuid from sqlalchemy import select from core.database import async_session_factory from models.user import User, UserRole from api.v1.dashboard import get_dashboard_stats async def verify_dashboard(): ansell_ws_id = uuid.UUID("00078389-5ae6-449f-baf4-72a17ed03fa7") async with async_session_factory() as db: # Mock a staff user for the request stmt = select(User).where(User.global_role == UserRole.SC_ADMIN).limit(1) res = await db.execute(stmt) admin_user = res.scalar() stats = await get_dashboard_stats( workspace_id=str(ansell_ws_id), current_user=admin_user, db=db ) load = stats.get("personnel_load", []) names = [p["name"] for p in load] print(f"Personnel Load in Ansell: {load}") if "Lead User" in names: print("SUCCESS: Lead User is visible in the dashboard.") else: print("FAIL: Lead User is NOT in the dashboard personnel load.") if "Admin A" in names: print("FAIL: Admin A is still leaking into the dashboard!") else: print("SUCCESS: Admin A is excluded from the dashboard.") async def verify_serialization(): # We can check if the code runs without error by simulating a small dict with UUID import json def sanitize_json(val): if isinstance(val, uuid.UUID): return str(val) if isinstance(val, dict): return {k: sanitize_json(v) for k, v in val.items()} if isinstance(val, list): return [sanitize_json(i) for i in val] return val test_data = {"id": uuid.uuid4(), "nested": {"uid": uuid.uuid4()}, "list": [uuid.uuid4()]} sanitized = sanitize_json(test_data) try: json.dumps(sanitized) print("SUCCESS: JSON serialization test passed.") except TypeError as e: print(f"FAIL: JSON serialization test failed: {e}") if __name__ == "__main__": asyncio.run(verify_dashboard()) asyncio.run(verify_serialization())