hisham-cmd commited on
Commit
38ff36f
·
verified ·
1 Parent(s): 9ab82fc

Upload test_admin_stats.py

Browse files
Files changed (1) hide show
  1. test_admin_stats.py +30 -0
test_admin_stats.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import sys
3
+
4
+ # Add app to path
5
+ sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__))))
6
+
7
+ from app.db.base import SessionLocal
8
+ from app.api.admin import get_dashboard_stats
9
+
10
+ def run():
11
+ db = SessionLocal()
12
+ # Mock user_id 1 (assume admin for test or bypass check_admin temporarily for script or just pass admin user id)
13
+ # The check_admin function needs a real admin user ID.
14
+ # Let's just catch the exception and see what check_admin complains about if user 1 is not admin.
15
+ try:
16
+ from app.models.user import User, UserRole
17
+ admin = db.query(User).filter(User.role == UserRole.ADMIN).first()
18
+ if not admin:
19
+ print("No admin found in DB.")
20
+ return
21
+
22
+ res = get_dashboard_stats(admin.id, db)
23
+ print("Success:", res)
24
+ except Exception as e:
25
+ print("Error:", e)
26
+ finally:
27
+ db.close()
28
+
29
+ if __name__ == "__main__":
30
+ run()