From 12907a601ab868b9c89b9ef3bc44074270ec7928 Mon Sep 17 00:00:00 2001 From: moanos Date: Mon, 18 Mar 2024 13:57:56 +0100 Subject: [PATCH] feat(test): Add data to populate basic db --- src/fellchensammlung/baker_recipes.py | 26 +++++++++++++++ .../management/commands/populate_db.py | 33 +++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 src/fellchensammlung/baker_recipes.py create mode 100644 src/fellchensammlung/management/commands/populate_db.py diff --git a/src/fellchensammlung/baker_recipes.py b/src/fellchensammlung/baker_recipes.py new file mode 100644 index 0000000..a4e99db --- /dev/null +++ b/src/fellchensammlung/baker_recipes.py @@ -0,0 +1,26 @@ +from django.contrib.auth.models import User +from model_bakery.recipe import Recipe, seq +from fellchensammlung.models import * + +location = Recipe( + Location, + name=seq('Ort_'), + description=seq('Detaillierte Beschreibung_'), + postcode=seq("7322"), +) + +rescue_org = Recipe( + RescueOrganization, + name=seq('Rattennothilfe_'), + location=location.make() +) + +rat = Recipe( + Animal, + name=seq('Ratte_'), +) + +cat = Recipe( + Animal, + name=seq('Katze_'), +) diff --git a/src/fellchensammlung/management/commands/populate_db.py b/src/fellchensammlung/management/commands/populate_db.py new file mode 100644 index 0000000..7ff7b0c --- /dev/null +++ b/src/fellchensammlung/management/commands/populate_db.py @@ -0,0 +1,33 @@ +from django.core.management.base import BaseCommand, CommandError +from django.contrib.auth.models import User + +from fellchensammlung.models import * +from fellchensammlung import baker_recipes +from model_bakery import baker + + +class Command(BaseCommand): + help = "Populates the database with test data" + + @staticmethod + def populate_db(): + rat1 = baker.make_recipe( + 'fellchensammlung.rat' + ) + rat2 = baker.make_recipe( + 'fellchensammlung.rat' + ) + rescue1 = baker.make_recipe( + 'fellchensammlung.rescue_org' + ) + rescue2 = baker.make_recipe( + 'fellchensammlung.rescue_org' + ) + + baker.make(AdoptionNotice, name="Vermittung1", animals=[rat1, rat2], organization=rescue1) + + User.objects.create_user('test', password='foobar') + User.objects.create_superuser(username="admin", password="admin") + + def handle(self, *args, **options): + self.populate_db()