From fc6ab9cd21a01c7d9f52bf1599813da3cbdd9fed Mon Sep 17 00:00:00 2001 From: jedi Date: Thu, 28 Nov 2024 19:20:46 +0100 Subject: [PATCH] stash --- deploy/dev/docker-compose.yml | 3 +- deploy/dev/testdata.py | 87 +++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 deploy/dev/testdata.py diff --git a/deploy/dev/docker-compose.yml b/deploy/dev/docker-compose.yml index dff5ab3..64a15af 100644 --- a/deploy/dev/docker-compose.yml +++ b/deploy/dev/docker-compose.yml @@ -3,7 +3,7 @@ services: build: context: ../../core dockerfile: ../deploy/dev/Dockerfile.backend - command: bash -c 'python manage.py migrate && python manage.py runserver 0.0.0.0:8000' + command: bash -c 'python manage.py runserver 0.0.0.0:8000' environment: - HTTP_HOST=core - DB_HOST=db @@ -13,6 +13,7 @@ services: - DB_PASSWORD=system3 volumes: - ../../core:/code + - ./testdata.py:/code/testdata.py ports: - "8000:8000" depends_on: diff --git a/deploy/dev/testdata.py b/deploy/dev/testdata.py new file mode 100644 index 0000000..767f644 --- /dev/null +++ b/deploy/dev/testdata.py @@ -0,0 +1,87 @@ +import os + + +def setup(): + from authentication.models import ExtendedUser, EventPermission + from inventory.models import Event + from django.contrib.auth.models import Permission, Group + permissions = ['add_item', 'view_item', 'view_file', 'delete_item', 'change_item'] + if not ExtendedUser.objects.filter(username='admin').exists(): + admin = ExtendedUser.objects.create_superuser('admin', 'admin@example.com', 'admin') + admin.set_password('admin') + admin.user_permissions.add(*Permission.objects.all()) + admin.save() + + if not ExtendedUser.objects.filter(username='testuser').exists(): + testuser = ExtendedUser.objects.create_user('testuser', 'testuser@example.com', 'testuser') + testuser.set_password('testuser') + testuser.user_permissions.add(*Permission.objects.all()) + testuser.save() + + team = Group.objects.get(name='Team') + team.permissions.add( + *Permission.objects.all() + ) + + if not ExtendedUser.objects.filter(username='testuser2').exists(): + testuser2 = ExtendedUser.objects.create_user('testuser2', 'testuser2@example.com', 'testuser2') + testuser2.set_password('testuser2') + testuser2.groups.add(team) + testuser2.save() + + # hbug = ExtendedUser.objects.get(username='hbug') + + if not Event.objects.filter(slug='TEST1').exists(): + event1 = Event.objects.create(name='first test event', slug='TEST1', + start='2023-12-18 00:00:00.000000', end='2023-12-27 00:00:00.000000', + pre_start='2023-12-31 00:00:00.000000', post_end='2024-01-04 00:00:00.000000') + + if not Event.objects.filter(slug='TEST2').exists(): + event2 = Event.objects.create(name='second test event', slug='TEST2', + start='2024-12-18 00:00:00.000000', end='2024-12-27 00:00:00.000000', + pre_start='2024-12-31 00:00:00.000000', post_end='2025-01-04 00:00:00.000000') + + # for permission in permissions: + # EventPermission.objects.create(event=event_37c3, user=hbug, + # permission=Permission.objects.get(codename=permission)) + +# from tickets.models import IssueThread +# +# from mail.models import Email +# +# issue_thread = IssueThread.objects.create( +# name="test", +# event=Event.objects.get(slug='TEST1') +# ) +# mail1 = Email.objects.create( +# subject='test subject', +# body='test', +# sender='test1@test', +# recipient='test2@test', +# issue_thread=issue_thread, +# ) +# mail1_reply = Email.objects.create( +# subject='Message received', +# body='Thank you for your message.', +# sender='test2@test', +# recipient='test1@test', +# in_reply_to=mail1.reference, +# issue_thread=issue_thread, +# ) + + +def main(): + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "core.settings") + import django + + django.setup() + + from django.core.management import call_command + call_command('migrate') + + setup() + print('testdata initialised') + + +if __name__ == '__main__': + main()