diff options
Diffstat (limited to '')
-rw-r--r-- | ctrack/organisations/management/commands/populate_db.py | 15 | ||||
-rw-r--r-- | ctrack/organisations/tests/factories.py | 12 |
2 files changed, 15 insertions, 12 deletions
diff --git a/ctrack/organisations/management/commands/populate_db.py b/ctrack/organisations/management/commands/populate_db.py index 06759a9..1613cde 100644 --- a/ctrack/organisations/management/commands/populate_db.py +++ b/ctrack/organisations/management/commands/populate_db.py @@ -3,8 +3,10 @@ from random import randint from django.core.management import BaseCommand from django.core.management import CommandParser +from ctrack.organisations.models import AddressType from ctrack.organisations.models import Mode from ctrack.organisations.models import Submode +from ctrack.organisations.tests.factories import AddressFactory from ctrack.organisations.tests.factories import OrganisationFactory from ctrack.organisations.tests.factories import PersonFactory from ctrack.organisations.tests.factories import RoleFactory @@ -42,13 +44,20 @@ class Command(BaseCommand): # below. Then we need to write a post_generation hook in PersonFactory which ensures that the person # is only added to these Organisations and no further Organisation objects are created. - # we need a User object to completed the updated_by fields in Organisaton and Person + # we need a User object to completed the updated_by fields in Organisation and Person user = ( UserFactory.create() ) # we need to have at least one user for the updated_by field # Create 40 Organisation objects - orgs = [OrganisationFactory.create(submode=submodes[randint(0, len(submodes)-1)]) for org in range(40)] + orgs = [ + OrganisationFactory.create(submode=submodes[randint(0, len(submodes) - 1)]) + for org in range(40) + ] + # Create 40 Address objects + addr_type = AddressType.objects.create(descriptor="Primary Address") + for org in orgs: + AddressFactory.create(type=addr_type, organisation=org) role = ( RoleFactory.create() @@ -58,7 +67,7 @@ class Command(BaseCommand): role=role, updated_by=user, predecessor=None, - organisation__submode=submodes[randint(0, len(submodes)-1)], + organisation__submode=submodes[randint(0, len(submodes) - 1)], organisation=org, ) self.stdout.write( diff --git a/ctrack/organisations/tests/factories.py b/ctrack/organisations/tests/factories.py index 61f2ae3..daf86ad 100644 --- a/ctrack/organisations/tests/factories.py +++ b/ctrack/organisations/tests/factories.py @@ -110,21 +110,15 @@ class PersonFactory(DjangoModelFactory): class AddressFactory(DjangoModelFactory): type = SubFactory("ctrack.organisations.tests.factories.AddressTypeFactory") organisation = SubFactory(OrganisationFactory) - line1 = Faker("secondary_address", locale="en_GB") + line1 = Faker("building_number", locale="en_GB") line2 = Faker("street_name", locale="en_GB") line3 = Faker("secondary_address", locale="en_GB") city = Faker("city", locale="en_GB") county = Faker("lexify", locale="en_GB", text="??????", letters="aeioutzyj") postcode = Faker("postcode", locale="en_GB") - country = Faker("country") - other_details = Faker("lexify", locale="en_GB", text="??????", letters="aeioutzyj") + country = "UK" + other_details = Faker("text", max_nb_chars=200, ext_word_list=None) class Meta: model = Address - -class AddressTypeFactory(DjangoModelFactory): - descriptor = "Primary Address" - - class Meta: - model = AddressType |