-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-test-users
More file actions
executable file
·45 lines (39 loc) · 1.3 KB
/
create-test-users
File metadata and controls
executable file
·45 lines (39 loc) · 1.3 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
#!/bin/sh -
# Helper script to generate admin and user accounts for development ONLY
# Create a superuser with username 'admin' and password 'test'
./compose-dev.sh exec \
-e DJANGO_SUPERUSER_USERNAME=admin \
-e DJANGO_SUPERUSER_EMAIL=admin@example.com \
-e DJANGO_SUPERUSER_PASSWORD=test \
--interactive=false \
backend \
python manage.py createsuperuser --no-input
# Create base groups
./compose-dev.sh exec \
backend \
python manage.py create_base_groups
# Create a normal user with username 'user' and password 'test'.
# Add to 'Bird ringing experts' group
./compose-dev.sh exec backend \
python manage.py shell -v 0 -c "from django.contrib.auth import get_user_model
from django.contrib.auth.models import Group
User = get_user_model()
u, created = User.objects.get_or_create(
username='user',
defaults={'email': 'user@example.com'},
)
if created:
u.set_password('test')
u.is_staff = False
u.is_superuser = False
u.save()
print(f'User {u.username} created successfully')
else:
print(f'User {u.username} already exists')
g = Group.objects.get(name='Bird ringing experts')
if u.groups.filter(pk=g.pk).exists():
print(f'User {u.username} is already in group {g.name}')
else:
u.groups.add(g)
print(f'Added user {u.username} to group {g.name}')
"