Spaces:
Paused
Paused
File size: 2,078 Bytes
3143c25 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
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())
|