66 lines
1.7 KiB
Python
66 lines
1.7 KiB
Python
#!/usr/bin/env python3
|
|
"""Quick test script for AARS backend - run locally without Docker"""
|
|
|
|
import os
|
|
import sys
|
|
|
|
# Add backend to path
|
|
sys.path.insert(0, os.path.dirname(__file__))
|
|
|
|
# Generate secret if missing
|
|
if not os.path.exists("secret.py"):
|
|
with open("secret.py", "w") as f:
|
|
f.write(f"JWT_SECRET = 'dev-secret-{os.urandom(16).hex()}'\n")
|
|
|
|
# Import and run
|
|
from database import init_db, SessionLocal
|
|
from models import User
|
|
|
|
print("🧪 Testing AARS Backend...")
|
|
print()
|
|
|
|
# Test 1: Database init
|
|
print("1️⃣ Testing database initialization...")
|
|
try:
|
|
init_db()
|
|
print(" ✅ Database initialized")
|
|
except Exception as e:
|
|
print(f" ❌ Database init failed: {e}")
|
|
sys.exit(1)
|
|
|
|
# Test 2: Check admin user
|
|
print("2️⃣ Testing admin user...")
|
|
try:
|
|
db = SessionLocal()
|
|
admin = db.query(User).filter(User.email == "admin@aars.hk").first()
|
|
if admin:
|
|
print(f" ✅ Admin exists: {admin.email}")
|
|
else:
|
|
print(" ⚠️ Admin not found")
|
|
db.close()
|
|
except Exception as e:
|
|
print(f" ❌ Query failed: {e}")
|
|
sys.exit(1)
|
|
|
|
# Test 3: Test password hashing
|
|
print("3️⃣ Testing password hashing...")
|
|
try:
|
|
from database import get_password_hash, verify_password
|
|
pw_hash = get_password_hash("test123")
|
|
assert verify_password("test123", pw_hash)
|
|
print(" ✅ Password hashing works")
|
|
except Exception as e:
|
|
print(f" ❌ Password hashing failed: {e}")
|
|
sys.exit(1)
|
|
|
|
print()
|
|
print("🎉 All basic tests passed!")
|
|
print()
|
|
print("To run the backend:")
|
|
print(" cd backend")
|
|
print(" pip install -r requirements.txt")
|
|
print(" uvicorn main:app --reload --port 8000")
|
|
print()
|
|
print("Then visit: http://localhost:8000")
|
|
print("API docs: http://localhost:8000/docs")
|