Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱(dashboard) add consent development fixtures #244

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.")
)
Loading