-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_demo.py
More file actions
92 lines (74 loc) · 2.71 KB
/
Copy pathsetup_demo.py
File metadata and controls
92 lines (74 loc) · 2.71 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env python3
"""
Setup demo environment with working credentials
"""
import sys
import os
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
from app.core.tenant import tenant_registry
from app.core.auth import user_manager
from app.utils.seeder import DatabaseSeeder
from app.core.database import get_db_session
def setup_demo():
"""Setup demo environment"""
tenant_id = "ui_test_tenant"
print(f"🚀 Setting up demo environment...")
try:
# Register tenant
print(f"📁 Registering tenant: {tenant_id}")
success = tenant_registry.register_tenant(
tenant_id,
{
"features": {
"inventory_tracking": True,
"product_variants": True,
"customer_accounts": True,
"order_management": True,
}
},
)
print(f"✅ Tenant registration: {success}")
# Check if data already exists
print(f"📦 Checking existing data...")
try:
db = next(get_db_session(tenant_id))
from app.models import Category, Product
categories = db.query(Category).count()
products = db.query(Product).count()
print(f" Categories: {categories}")
print(f" Products: {products}")
if categories == 0:
print(f" Seeding categories...")
seeder = DatabaseSeeder(db)
seeder.seed_categories()
db.commit()
if products == 0:
print(f" Seeding products...")
seeder = DatabaseSeeder(db)
seeder.seed_products()
db.commit()
db.close()
print(f"✅ Data check complete")
except Exception as e:
print(f"⚠️ Data check failed (but continuing): {e}")
# Test authentication
print(f"🔐 Testing authentication...")
user = user_manager.authenticate_tenant_user(tenant_id, "admin", "admin123")
if user:
print(f"✅ Authentication working!")
print(f" User: {user.get('username')}")
print(f" Roles: {user.get('roles')}")
else:
print(f"❌ Authentication failed")
print(f"\n🎉 Demo setup complete!")
print(f" Frontend: http://localhost:5173")
print(f" Backend: http://localhost:8000")
print(f" Tenant ID: {tenant_id}")
print(f" Username: admin")
print(f" Password: admin123")
except Exception as e:
print(f"❌ Error setting up demo: {e}")
import traceback
traceback.print_exc()
if __name__ == "__main__":
setup_demo()