Files
MathApp/tools/loadtest/mkusers.py
Zareian 663252a260 Remove the guest system entirely: no is_guest/device_id, no guest throttles, phone login is the only way in
accounts.0008 drops the columns and refuses to run while guest rows exist.
Docs describe the current state; tests that only proved guest behaviour are gone.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-05 18:20:10 +03:30

31 lines
1.4 KiB
Python

# Run with: manage.py shell -c "exec(open('tools/loadtest/mkusers.py').read())" env: LT_N, LT_PREFIX, LT_SEED
# Creates N test users (fake 0900… numbers, no signals, no SMS) and prints
# [{userId, token, grade, asks:[{lessonId, question}], nodeId, questionIds}] as JSON.
import json
import os
import random
from accounts.authentication import issue_access_token
from accounts.models import User
from content.models import Lesson, Question
N = int(os.environ['LT_N'])
PREFIX = os.environ.get('LT_PREFIX', '0900990')
GRADES = [8, 9, 10, 11, 12, 4, 5, 6, 7, 3]
rnd = random.Random(int(os.environ.get('LT_SEED', '7')))
out = []
for i in range(N):
grade = GRADES[i % len(GRADES)]
phone = f'{PREFIX}{i:04d}'
user, _ = User.objects.get_or_create(phone=phone, defaults={'name': f'تست بار {i}', 'grade_id': grade})
qs = list(Question.objects.filter(lesson__node__unit__grade_id=grade).select_related('lesson__node')
.values_list('id', 'prompt', 'lesson_id', 'lesson__node_id')[:4000])
picks = rnd.sample(qs, 6)
out.append({
'userId': user.id, 'token': issue_access_token(user.id), 'grade': grade,
'asks': [{'lessonId': p[2], 'question': f'این سوال رو قدم به قدم توضیح بده: {p[1][:300]}'} for p in picks[:3]],
'nodeId': picks[3][3], 'answerQuestionIds': [p[0] for p in picks[3:]],
})
print('LTJSON' + json.dumps(out, ensure_ascii=False))