aboutsummaryrefslogtreecommitdiffstats
path: root/ctrack/organisations/management/commands
diff options
context:
space:
mode:
authorMatthew Lemon <lemon@matthewlemon.com>2020-02-18 17:33:57 +0000
committerMatthew Lemon <lemon@matthewlemon.com>2020-02-18 17:33:57 +0000
commitafed43baeb9b4f9ee9f449b7be4e8a89a65ce9a8 (patch)
tree28990c16a39e122741a6016b8125427e8c75400e /ctrack/organisations/management/commands
parentf739c571945dce2407a97c2b87ed5867b77a5f3d (diff)
seems to be a bug in factory_boy - not creating self-referential factory
Diffstat (limited to 'ctrack/organisations/management/commands')
-rw-r--r--ctrack/organisations/management/commands/generate_people.py79
1 files changed, 67 insertions, 12 deletions
diff --git a/ctrack/organisations/management/commands/generate_people.py b/ctrack/organisations/management/commands/generate_people.py
index 0e6b03e..0cb8c5b 100644
--- a/ctrack/organisations/management/commands/generate_people.py
+++ b/ctrack/organisations/management/commands/generate_people.py
@@ -1,14 +1,65 @@
from datetime import datetime
+import random
+
import factory
from django.core.management.base import BaseCommand, CommandError
from factory import DjangoModelFactory, Faker, SubFactory, post_generation
-from ctrack.organisation.models import Organisation, Person
+from ctrack.organisations.models import Organisation, Person, Submode, Mode
+
+
+def _random_mode():
+ sms = [
+ "Aviation",
+ "Rail",
+ "Maritime",
+ "Animal",
+ "Stellar",
+ ]
+ return sms[random.randint(0, len(sms) - 1)]
+
+def _random_submode():
+ sms = [
+ "Light Rail",
+ "Heavy Rail",
+ "Passenger Rail",
+ "Animal Transport",
+ "Infrastructure",
+ ]
+ return sms[random.randint(0, len(sms) - 1)]
+
+
+class ModeFactory(DjangoModelFactory):
+ class Meta:
+ model = Mode
+
+ descriptor = factory.LazyFunction(_random_mode)
+
+class SubModeFactory(DjangoModelFactory):
+ class Meta:
+ model = Submode
+
+ descriptor = factory.LazyFunction(_random_submode)
+ mode = SubFactory(ModeFactory)
class OrganisationFactory(DjangoModelFactory):
- pass
+ class Meta:
+ model = Organisation
+
+ name = Faker("company")
+ slug = Faker("lexify", text="????", letters="abcdsg")
+ submode = SubFactory(SubModeFactory)
+ designation_type = 1
+ registered_company_name = Faker("company")
+ registered_company_number = Faker("numerify", text="######")
+ date_updated = Faker("date_this_year", before_today=True)
+ updated_by = SubFactory(
+ "ctrack.organisations.management.commands.generate_people.PersonFactory"
+ )
+ comments = Faker("paragraph", nb_sentences=3)
+ active = True
class PersonFactory(DjangoModelFactory):
@@ -22,23 +73,27 @@ class PersonFactory(DjangoModelFactory):
job_title = Faker("job")
first_name = Faker("first_name")
last_name = Faker("last_name")
- organisation = SubFactory(OrganisationFactory) # TODO we need to create OrganisationFactory
+ organisation = SubFactory(OrganisationFactory)
role = Faker("job")
email = Faker("ascii_company_email")
secondary_email = "ascii_company_email"
mobile = Faker("msisdn", locale="en_GB")
landline = Faker("phone_number", locale="en_GB")
date_updated = factory.LazyFunction(datetime.now)
- updated_by = # TODO we need to create a fake User
- clearance =
- clearance_sponsor =
- clearance_start_date =
- clearance_last_checked =
- clearance_expiry =
+ updated_by = SubFactory(
+ "ctrack.organisations.management.commands.generate_people.PersonFactory"
+ )
+ clearance = factory.LazyFunction(datetime.now)
+ clearance_sponsor = Faker("name", locale="en_GB")
+ clearance_start_date = factory.LazyFunction(datetime.now)
+ clearance_last_checked = factory.LazyFunction(datetime.now)
+ clearance_expiry = factory.LazyFunction(datetime.now)
active = True
- date_ended =
- predecessor =
- comments =
+ date_ended = Faker("date_this_year")
+ predecessor = SubFactory(
+ "ctrack.organisations.management.commands.generate_people.PersonFactory"
+ )
+ comments = "Yaa!"
class Command(BaseCommand):