mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-04 17:01:56 +02:00
Merge pull request #972 from cisagov/rjm/756-fixtures
756 - Fixtures load 8 times
This commit is contained in:
commit
4cad90d0d6
3 changed files with 11 additions and 18 deletions
|
@ -54,6 +54,7 @@ services:
|
|||
# command: "python"
|
||||
command: >
|
||||
bash -c " python manage.py migrate &&
|
||||
python manage.py load &&
|
||||
python manage.py runserver 0.0.0.0:8080"
|
||||
|
||||
db:
|
||||
|
|
|
@ -2,6 +2,7 @@ import logging
|
|||
|
||||
from django.core.management.base import BaseCommand
|
||||
from auditlog.context import disable_auditlog # type: ignore
|
||||
from django.conf import settings
|
||||
|
||||
from registrar.fixtures import UserFixture, DomainApplicationFixture, DomainFixture
|
||||
|
||||
|
@ -12,8 +13,11 @@ class Command(BaseCommand):
|
|||
def handle(self, *args, **options):
|
||||
# django-auditlog has some bugs with fixtures
|
||||
# https://github.com/jazzband/django-auditlog/issues/17
|
||||
with disable_auditlog():
|
||||
UserFixture.load()
|
||||
DomainApplicationFixture.load()
|
||||
DomainFixture.load()
|
||||
logger.info("All fixtures loaded.")
|
||||
if settings.DEBUG:
|
||||
with disable_auditlog():
|
||||
UserFixture.load()
|
||||
DomainApplicationFixture.load()
|
||||
DomainFixture.load()
|
||||
logger.info("All fixtures loaded.")
|
||||
else:
|
||||
logger.warn("Refusing to load fixture data in a non DEBUG env")
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
import logging
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.management import call_command
|
||||
from django.db.models.signals import post_save, post_migrate
|
||||
from django.db.models.signals import post_save
|
||||
from django.dispatch import receiver
|
||||
|
||||
from .models import User, Contact
|
||||
|
@ -55,13 +53,3 @@ def handle_profile(sender, instance, **kwargs):
|
|||
"There are multiple Contacts with the same email address."
|
||||
f" Picking #{contacts[0].id} for User #{instance.id}."
|
||||
)
|
||||
|
||||
|
||||
@receiver(post_migrate)
|
||||
def handle_loaddata(**kwargs):
|
||||
"""Attempt to load test fixtures when in DEBUG mode."""
|
||||
if settings.DEBUG:
|
||||
try:
|
||||
call_command("load")
|
||||
except Exception as e:
|
||||
logger.warning(e)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue