aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Lemon <matt@matthewlemon.com>2020-02-28 22:43:01 +0000
committerMatthew Lemon <matt@matthewlemon.com>2020-02-28 22:43:01 +0000
commit41a67d4231c47bb5dc44b541b7d360ac79d21194 (patch)
tree0accc50b11da0da6e8b81565eebd9d07789aaab5
parent84f6f9e552a14345ce5ea2611ee39636be9ff60d (diff)
CAF factory basics but not essential services yet
-rw-r--r--ctrack/caf/migrations/0014_auto_20200228_2215.py19
-rw-r--r--ctrack/caf/models.py2
-rw-r--r--ctrack/caf/tests/factories.py38
-rw-r--r--ctrack/organisations/management/commands/populate_db.py19
4 files changed, 71 insertions, 7 deletions
diff --git a/ctrack/caf/migrations/0014_auto_20200228_2215.py b/ctrack/caf/migrations/0014_auto_20200228_2215.py
new file mode 100644
index 0000000..f1d8c7a
--- /dev/null
+++ b/ctrack/caf/migrations/0014_auto_20200228_2215.py
@@ -0,0 +1,19 @@
+# Generated by Django 2.2.9 on 2020-02-28 22:15
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('caf', '0013_auto_20200227_0827'),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name='essentialservice',
+ name='caf',
+ field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='caf.CAF'),
+ ),
+ ]
diff --git a/ctrack/caf/models.py b/ctrack/caf/models.py
index c17f064..669fc27 100644
--- a/ctrack/caf/models.py
+++ b/ctrack/caf/models.py
@@ -50,7 +50,7 @@ class EssentialService(models.Model):
organisation = models.ForeignKey(
Organisation, on_delete=models.SET(get_sentinel_org)
)
- caf = models.ForeignKey("CAF", on_delete=models.CASCADE)
+ caf = models.ForeignKey("CAF", on_delete=models.CASCADE, blank=True, null=True)
class Meta:
verbose_name = "Essential Service"
diff --git a/ctrack/caf/tests/factories.py b/ctrack/caf/tests/factories.py
index 53953fe..4de76a1 100644
--- a/ctrack/caf/tests/factories.py
+++ b/ctrack/caf/tests/factories.py
@@ -3,19 +3,53 @@ import random
import factory
from factory import Faker
-from ctrack.caf.models import EssentialService, Grading, DocumentFile, FileStore
+from ctrack.caf.models import EssentialService, Grading, DocumentFile, FileStore, CAF
from ctrack.organisations.tests.factories import OrganisationFactory
+class CAFFactory(factory.DjangoModelFactory):
+ owner = factory.SubFactory(OrganisationFactory)
+ quality_grading = factory.SubFactory("ctrack.caf.tests.factories.GradingFactory")
+ confidence_grading = factory.SubFactory("ctrack.caf.tests.factories.GradingFactory")
+ file = None
+
+ class Meta:
+ model = CAF
+
+
class EssentialServiceFactory(factory.DjangoModelFactory):
"""Factory for Essential Services."""
+ fnames = [
+ "Clock Pylon Systems",
+ "Ultramarine Hanglider Navigator",
+ "Membranous Floor Heaters",
+ "Alan's Wardrobe Hinge Circuits",
+ "Marine Sluicegate Extension Pulleys",
+ "Ironway Prob Modelling Area",
+ "Bufferage Clippers",
+ "Slow Gauze Thread Manipulator",
+ "Terratoast Piling",
+ "Accounting and Warehouse Conducer",
+ "Able Hopscotch Mirrors",
+ "Jolly Main Legacy Circuitry",
+ ]
+
class Meta:
model = EssentialService
+ name = random.choice(fnames)
+ description = Faker(
+ "paragraph", nb_sentences=4, variable_nb_sentences=True, ext_word_list=None
+ )
+ organisation = factory.SubFactory(OrganisationFactory)
+ caf = factory.SubFactory("ctrack.caf.tests.factories.CAFFactory")
+
class GradingFactory(factory.DjangoModelFactory):
- descriptor = factory.Iterator(["Q1", "Q2", "Q3", "Q4", "Q5", "C1", "C2", "C3", "C4", "C5"])
+ descriptor = factory.Iterator(
+ ["Q1", "Q2", "Q3", "Q4", "Q5", "C1", "C2", "C3", "C4", "C5"]
+ )
description = Faker("text", max_nb_chars=100, ext_word_list=None)
type = factory.Iterator(Grading.GRADING_TYPE, getter=lambda g: g[0])
diff --git a/ctrack/organisations/management/commands/populate_db.py b/ctrack/organisations/management/commands/populate_db.py
index ea81dfe..32e6ce4 100644
--- a/ctrack/organisations/management/commands/populate_db.py
+++ b/ctrack/organisations/management/commands/populate_db.py
@@ -1,9 +1,10 @@
+import random
from random import randint, choice
from django.core.management import BaseCommand
from django.core.management import CommandParser
-from ctrack.caf.tests.factories import GradingFactory, FileStoreFactory
+from ctrack.caf.tests.factories import GradingFactory, FileStoreFactory, CAFFactory
from ctrack.organisations.models import AddressType
from ctrack.organisations.models import Mode
from ctrack.organisations.models import Submode
@@ -106,12 +107,22 @@ class Command(BaseCommand):
ee2 = EngagementEventFactory.create(type=etf2, user=user, participants=[p3])
# Quality gradings
- for g in ["Q1", "Q2", "Q3", "Q4", "Q5"]:
+ q_descriptors = ["Q1", "Q2", "Q3", "Q4", "Q5"]
+ for g in q_descriptors:
GradingFactory.create(descriptor=g, type="QUALITY")
# Confidence gradings
- for g in ["C1", "C2", "C3", "C4", "C5"]:
+ c_descriptors = ["C1", "C2", "C3", "C4", "C5"]
+ for g in c_descriptors:
GradingFactory.create(descriptor=g, type="CONFIDENCE")
# File store
- fs = FileStoreFactory.create(physical_location_organistion=orgs[1])
+ fs = FileStoreFactory.create(physical_location_organisation=orgs[1])
+
+ # Some CAF objects
+ for c in range(35):
+ CAFFactory.create(
+ owner=random.choice(orgs),
+ quality_grading__descriptor=random.choice(q_descriptors),
+ confidence_grading__descriptor=random.choice(c_descriptors),
+ )