-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcreate_test_data.py
More file actions
147 lines (132 loc) · 5.74 KB
/
create_test_data.py
File metadata and controls
147 lines (132 loc) · 5.74 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/usr/bin/env python
"""
테스트 데이터 생성 스크립트
팀매칭 알고리즘 테스트용 데이터 자동 생성
"""
import os
import django
from django.utils import timezone
from datetime import timedelta
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
django.setup()
from apps.accounts.models import User, Role, UserRoleLevel
from apps.projects.models import Season
def create_test_data():
print("=" * 50)
print("🚀 테스트 데이터 생성 시작")
print("=" * 50)
# 1. Role 확인/생성
print("\n1️⃣ Role 생성 중...")
roles = {}
role_data = [
('PM', 'PM(기획)'),
('FRONTEND', '프론트엔드'),
('BACKEND', '백엔드'),
]
for code, name in role_data:
role, created = Role.objects.get_or_create(
code=code,
defaults={'name': name}
)
roles[code] = role
status = "생성" if created else "기존"
print(f" ✅ {status}: {name}")
# 2. 시즌 생성
print("\n2️⃣ 시즌 생성 중...")
now = timezone.now()
season, created = Season.objects.get_or_create(
name='2026년 2월 시즌',
defaults={
'status': 'MATCHING',
'matching_start': now - timedelta(hours=1),
'matching_end': now + timedelta(days=7),
'project_start': now + timedelta(days=8),
'project_end': now + timedelta(days=30),
'is_active': True
}
)
status = "생성" if created else "기존"
print(f" ✅ {status}: {season.name}")
# 3. 테스트 유저 생성 (30명: PM 6, FE 12, BE 12)
print("\n3️⃣ 테스트 유저 생성 중...")
test_users = [
# PM (6명)
# FE (12명)
# BE (12명)
]
for username, nickname, email, role_code, level, passion_level in test_users:
# 유저 생성
user, created = User.objects.get_or_create(
username=username,
defaults={
'email': email,
'nickname': nickname,
'passion_level': passion_level,
'is_active': True,
}
)
if created:
user.set_password('test1234')
user.save()
else:
# 기존 유저의 열정 레벨 업데이트
user.passion_level = passion_level
user.save()
# UserRoleLevel 설정
role = roles[role_code]
level_obj, _ = UserRoleLevel.objects.update_or_create(
user=user,
role=role,
defaults={'level': level}
)
status = "생성" if created else "기존"
print(f" ✅ {status}: {username:10s} ({nickname:6s}) - {role.name:8s} Lv{level} | 열정 {passion_level}⭐")
print("\n" + "=" * 50)
print("🎉 테스트 데이터 준비 완료!")
print("=" * 50)
print(f"\n📊 생성 통계:")
print(f" • Role: 3개")
print(f" • Season: 1개 (2026년 2월 시즌)")
print(f" • Users: {len(test_users)}명")
print(f" - PM: 6명")
print(f" - FE: 12명")
print(f" - BE: 12명")
print(f"\n💡 로그인 정보:")
print(f" • Username: testpm1, testfe1, testbe1 등")
print(f" • Password: test1234")
print(f"\n🎯 다음 단계:")
print(f" 1. 로그인하여 마이페이지에서 레벨 확인")
print(f" 2. 관리자 페이지에서 팀매칭 실행")
print(f" 3. 결과 확인")
if __name__ == '__main__':
create_test_data()