create management command to create test users, use it in Docker

This commit is contained in:
aatish 2018-10-26 15:08:49 +05:45
parent d3ade15c9a
commit d13d3f53d5
5 changed files with 29 additions and 2 deletions

View file

@ -13,4 +13,4 @@ ADD requirements.txt /site/
RUN pip install -U -r /site/requirements.txt RUN pip install -U -r /site/requirements.txt
COPY ./ /site COPY ./ /site
CMD bash -c 'python3 manage.py migrate --noinput && python3 manage.py collectstatic --noinput && uwsgi --ini=/site/uwsgi.ini' CMD bash -c 'python3 manage.py migrate --noinput && python3 manage.py collectstatic --noinput && python3 manage.py create_test_users && uwsgi --ini=/site/uwsgi.ini'

View file

@ -1,3 +1,5 @@
docker build -t ipv6dotwork . docker build -t ipv6dotwork .
docker run -d -p 127.0.0.1:8001:8000 --name ipv6dotwork ipv6dotwork sudo docker rm -f ipv6dotwork
sudo docker run -d -p 127.0.0.1:8001:8000 --env-file .env --name ipv6dotwork ipv6dotwork

View file

View file

View file

@ -0,0 +1,25 @@
from django.core.management import BaseCommand
from django.contrib.auth import get_user_model
User = get_user_model()
class Command(BaseCommand):
help = "Create test accounts. Don't use this in production!"
def handle(self, *args, **options):
user_fixture = [
{
'username': 'user1',
'email': 'user1@dev.ipv6.work',
'password': 'user1'
},
{
'username': 'user2',
'email': 'user2@dev.ipv6.work',
'password': 'user2'
},
]
for user_data in user_fixture:
User.objects.create_user(**user_data)