Skip to content

Commit

Permalink
🌱(dashboard) add consent development fixtures
Browse files Browse the repository at this point in the history
Create and manage consent development fixtures.
The seed-dashboard Makefile target was updated to include the fixture creation command.
  • Loading branch information
ssorin committed Nov 28, 2024
1 parent b2704f2 commit 1d6e748
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ seed-dashboard: ## seed dashboard
@$(COMPOSE_UP) --wait postgresql
@echo "Seeding dashboard…"#
@bin/manage loaddata dashboard/fixtures/dsfr_fixtures.json
@bin/manage seed_consent
.PHONY: seed-dashboard

# -- API
Expand Down
1 change: 1 addition & 0 deletions src/dashboard/apps/consent/fixtures/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Dashboard consent app fixtures."""
41 changes: 41 additions & 0 deletions src/dashboard/apps/consent/fixtures/consent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""Dashboard consent dev fixture."""

from apps.auth.factories import UserFactory
from apps.consent.factories import ConsentFactory
from apps.core.factories import DeliveryPointFactory, EntityFactory
from apps.core.models import DeliveryPoint


def seed_consent():
"""Creates development fixtures for consent management system.
This function performs the following tasks:
1. Creates three user instances using UserFactory.
2. Creates three entity instances with assigned users using EntityFactory.
3. Creates multiple delivery points for each entity using DeliveryPointFactory.
4. Generates consent instances for each delivery point using ConsentFactory.
"""
# create users
user1 = UserFactory(username="user1")
user2 = UserFactory(username="user2")
user3 = UserFactory(username="user3")
user4 = UserFactory(username="user4")
user5 = UserFactory(username="user5")

# create entities
entity1 = EntityFactory(users=(user1,))
entity2 = EntityFactory(users=(user2, user4))
entity3 = EntityFactory(users=(user3,), proxy_for=(entity1, entity2))
entity4 = EntityFactory(users=(user5,))


# create delivery points
for i in range(1, 4):
DeliveryPointFactory(provider_assigned_id=f"entity1_{i}", entity=entity1)
DeliveryPointFactory(provider_assigned_id=f"entity2_{i}", entity=entity2)
DeliveryPointFactory(provider_assigned_id=f"entity3_{i}", entity=entity3)
DeliveryPointFactory(provider_assigned_id=f"entity4_{i}", entity=entity4)

# create awaiting consents
for delivery_point in DeliveryPoint.objects.all():
ConsentFactory(delivery_point=delivery_point, created_by=user1)
1 change: 1 addition & 0 deletions src/dashboard/apps/consent/management/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Dashboard consent app management."""
1 change: 1 addition & 0 deletions src/dashboard/apps/consent/management/commands/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Dashboard consent app management commands."""
19 changes: 19 additions & 0 deletions src/dashboard/apps/consent/management/commands/seed_consent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""Consent management commands."""

from django.core.management.base import BaseCommand

from apps.consent.fixtures.consent import seed_consent


class Command(BaseCommand):
"""Create development fixtures for the consent management system."""

help = __doc__

def handle(self, *args, **kwargs):
"""Executes the command for creating development consent fixtures."""
self.stdout.write(self.style.NOTICE("Seeding database with consents..."))
seed_consent()
self.stdout.write(
self.style.SUCCESS("Done.")
)

0 comments on commit 1d6e748

Please sign in to comment.