-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_test_user.py
More file actions
executable file
·55 lines (46 loc) · 1.67 KB
/
create_test_user.py
File metadata and controls
executable file
·55 lines (46 loc) · 1.67 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
#!/usr/bin/env python3
"""テストユーザーを作成"""
import sys
import os
# プロジェクトルートをパスに追加
sys.path.insert(0, os.path.abspath(os.path.dirname(__file__)))
from sqlalchemy.orm import Session
from backend.app.database.session import SessionLocal
from backend.app.database.models import User
from backend.app.utils.password_hash import get_password_hash
def create_test_user():
"""テストユーザーを作成"""
db = SessionLocal()
try:
# 既存ユーザーを確認
existing_user = db.query(User).filter(User.email == "test@example.com").first()
if existing_user:
print("✅ テストユーザーは既に存在します")
print(f" Email: test@example.com")
print(f" Password: test123")
print(f" Role: {existing_user.role}")
return
# テストユーザーを作成
test_user = User(
email="test@example.com",
username="testuser",
hashed_password=get_password_hash("test123"),
role="editor", # editorロールで作成
is_active=True
)
db.add(test_user)
db.commit()
db.refresh(test_user)
print("✅ テストユーザーを作成しました!")
print(f" Email: test@example.com")
print(f" Password: test123")
print(f" Role: editor")
print()
print("フロントエンド (http://localhost:5173) でログインできます")
except Exception as e:
print(f"❌ エラー: {e}")
db.rollback()
finally:
db.close()
if __name__ == "__main__":
create_test_user()