From e20afcf33bac3d1aadeaf37358640513219c2b07 Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Wed, 4 Mar 2020 21:05:24 +0000 Subject: added an all-in-one truncate and populate script and better population code --- .../management/commands/populate_db.py | 32 ++++++++++++---------- utility/trunc_and_populate.sh | 9 ++++++ 2 files changed, 27 insertions(+), 14 deletions(-) create mode 100755 utility/trunc_and_populate.sh diff --git a/ctrack/organisations/management/commands/populate_db.py b/ctrack/organisations/management/commands/populate_db.py index e994b41..6f51a22 100644 --- a/ctrack/organisations/management/commands/populate_db.py +++ b/ctrack/organisations/management/commands/populate_db.py @@ -160,23 +160,12 @@ class Command(BaseCommand): # Every org gets on CAF for now for org in orgs: - # create a CAF for it - caf = CAFFactory.create( - quality_grading__descriptor=random.choice(q_descriptors), - confidence_grading__descriptor=random.choice(c_descriptors), - triage_review_date=None, - triage_review_inspector=None, - ) - # create an ApplicableSystem for it - app_s = ApplicableSystemFactory.create( - name=random.choice(fnames), - organisation=org, - caf=caf, - ) + # create a CAF and ApplicableService for it + self._create_caf_app_service(c_descriptors, org, q_descriptors) # CAF submissions - they create EngagementEvents # Get a random CAF - _caf = CAF.objects.get(pk=1) # we should have one by now + _caf = CAF.objects.get(pk=1) # we should have one by now ee3 = EngagementEventFactory.create( type=etf3, user=user, participants=[inspectors[1], p2], related_caf=_caf ) @@ -187,3 +176,18 @@ class Command(BaseCommand): f"Created {number} Person object[s]! Go forth and multiply." ) ) + + def _create_caf_app_service(self, c_descriptors, org, q_descriptors): + caf = CAFFactory.create( + quality_grading__descriptor=random.choice(q_descriptors), + confidence_grading__descriptor=random.choice(c_descriptors), + triage_review_date=None, + triage_review_inspector=None, + ) + # Each CAF can have up to three systems associated with it + for s in range(random.randint(1,3)): + ApplicableSystemFactory.create( + name=random.choice(fnames), + organisation=org, + caf=caf, + ) diff --git a/utility/trunc_and_populate.sh b/utility/trunc_and_populate.sh new file mode 100755 index 0000000..8ac3a4f --- /dev/null +++ b/utility/trunc_and_populate.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +echo "Truncating the database." +sudo -u postgres psql -f utility/truncate_script.sql ctrack + +sleep 1 + +echo "Populating the database with test data." +python manage.py populate_db 20 -- cgit v1.2.3