diff options
author | Matthew Lemon <lemon@matthewlemon.com> | 2020-02-20 16:11:17 +0000 |
---|---|---|
committer | Matthew Lemon <lemon@matthewlemon.com> | 2020-02-20 16:11:17 +0000 |
commit | 1a419c01172ef00b29bc0bbfc39766d9ecccfa18 (patch) | |
tree | 322bd02eab60828ecb399d40e820ec1733a93364 /ctrack/organisations | |
parent | 286c6bfc65636f57f29b4d4f9a45de5218c62cfe (diff) |
new migrationjs and generate_people command working
Diffstat (limited to 'ctrack/organisations')
-rw-r--r-- | ctrack/organisations/management/commands/generate_people.py | 19 | ||||
-rw-r--r-- | ctrack/organisations/migrations/0001_initial.py | 2 | ||||
-rw-r--r-- | ctrack/organisations/migrations/0002_auto_20200220_1434.py (renamed from ctrack/organisations/migrations/0002_auto_20200218_2221.py) | 4 | ||||
-rw-r--r-- | ctrack/organisations/tests/factories.py | 12 |
4 files changed, 28 insertions, 9 deletions
diff --git a/ctrack/organisations/management/commands/generate_people.py b/ctrack/organisations/management/commands/generate_people.py index d61902e..d429438 100644 --- a/ctrack/organisations/management/commands/generate_people.py +++ b/ctrack/organisations/management/commands/generate_people.py @@ -1,4 +1,9 @@ from django.core.management import BaseCommand +from django.core.management import CommandParser + +from ctrack.organisations.tests.factories import PersonFactory +from ctrack.organisations.tests.factories import RoleFactory +from ctrack.organisations.tests.factories import UserFactory class Command(BaseCommand): @@ -8,6 +13,20 @@ class Command(BaseCommand): python manage.py generate_people """ + def add_arguments(self, parser: CommandParser) -> None: + parser.add_argument("number", nargs=1, type=int) + + def handle(self, *args, **options): + number = options["number"][0] + # Let's use the factory to create people (and organisations, a user and role as a by-product) + user = UserFactory.create() + role = RoleFactory.create() # all these people get the role for now + PersonFactory.create_batch(number, role=role, updated_by=user, predecessor=None) # predecessor is too hard at the moment + self.stdout.write( + self.style.SUCCESS( + f"Created {number} Person object[s]! Go forth and multiply." + ) + ) # def add_arguments(self, parser): # parser.add_argument("year", nargs="+", type=int) diff --git a/ctrack/organisations/migrations/0001_initial.py b/ctrack/organisations/migrations/0001_initial.py index 1ec5895..c922874 100644 --- a/ctrack/organisations/migrations/0001_initial.py +++ b/ctrack/organisations/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 2.2.9 on 2020-02-18 22:21 +# Generated by Django 2.2.9 on 2020-02-20 14:34 from django.db import migrations, models import django.db.models.deletion diff --git a/ctrack/organisations/migrations/0002_auto_20200218_2221.py b/ctrack/organisations/migrations/0002_auto_20200220_1434.py index 45022d6..6d12071 100644 --- a/ctrack/organisations/migrations/0002_auto_20200218_2221.py +++ b/ctrack/organisations/migrations/0002_auto_20200220_1434.py @@ -1,4 +1,4 @@ -# Generated by Django 2.2.9 on 2020-02-18 22:21 +# Generated by Django 2.2.9 on 2020-02-20 14:34 from django.conf import settings from django.db import migrations, models @@ -10,8 +10,8 @@ class Migration(migrations.Migration): initial = True dependencies = [ - ('organisations', '0001_initial'), migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('organisations', '0001_initial'), ] operations = [ diff --git a/ctrack/organisations/tests/factories.py b/ctrack/organisations/tests/factories.py index 99a4bb3..e079271 100644 --- a/ctrack/organisations/tests/factories.py +++ b/ctrack/organisations/tests/factories.py @@ -36,7 +36,8 @@ class UserFactory(DjangoModelFactory): class Meta: model = User - name = Faker("name", locale="en_GB") + username = Faker("lexify", text="???????", letters="abcdsgTGQA") + password = Faker("lexify", text="????????", letters="AdOIqkcvBnMP") class ModeFactory(DjangoModelFactory): @@ -86,24 +87,23 @@ class PersonFactory(DjangoModelFactory): if not create: return if extracted: - for role in extracted: - self.role.add(role) + self.role.add(extracted) primary_nis_contact = True voluntary_point_of_contact = True has_egress = False - title = Faker("prefix") + title = factory.LazyFunction(lambda: random.randint(1, 8)) job_title = Faker("job") first_name = Faker("first_name") last_name = Faker("last_name") - organisation = SubFactory(OrganisationFactory) + organisation = SubFactory("ctrack.organisations.tests.factories.OrganisationFactory") 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 = SubFactory(UserFactory) - clearance = factory.LazyFunction(datetime.now) + clearance = factory.LazyFunction(lambda: random.randint(1,6)) clearance_sponsor = Faker("name", locale="en_GB") clearance_start_date = factory.LazyFunction(datetime.now) clearance_last_checked = factory.LazyFunction(datetime.now) |