diff options
author | Matthew Lemon <lemon@matthewlemon.com> | 2020-02-21 17:04:57 +0000 |
---|---|---|
committer | Matthew Lemon <lemon@matthewlemon.com> | 2020-02-21 17:04:57 +0000 |
commit | 3b2a8ac12c8b0303ebecf277f975449e8e560ec9 (patch) | |
tree | 6e5f6b7a30a1ebee9206a3df2cfd143125b2355c | |
parent | abd22b0143661370aa29246d21389d5f0bf7abc3 (diff) |
populate script now does EngagementEvent objects
-rw-r--r-- | ctrack/organisations/management/commands/populate_db.py | 28 | ||||
-rw-r--r-- | ctrack/register/tests.py | 3 | ||||
-rw-r--r-- | ctrack/register/tests/__init__.py | 0 | ||||
-rw-r--r-- | ctrack/register/tests/factories.py | 69 |
4 files changed, 97 insertions, 3 deletions
diff --git a/ctrack/organisations/management/commands/populate_db.py b/ctrack/organisations/management/commands/populate_db.py index 4477b63..1674ec0 100644 --- a/ctrack/organisations/management/commands/populate_db.py +++ b/ctrack/organisations/management/commands/populate_db.py @@ -11,6 +11,7 @@ from ctrack.organisations.tests.factories import OrganisationFactory from ctrack.organisations.tests.factories import PersonFactory from ctrack.organisations.tests.factories import RoleFactory from ctrack.organisations.tests.factories import UserFactory +from ctrack.register.tests.factories import EngagementEventFactory class Command(BaseCommand): @@ -71,3 +72,30 @@ class Command(BaseCommand): f"Created {number} Person object[s]! Go forth and multiply." ) ) + + # set up some EngagementEvents + + p1 = PersonFactory.create( + role=role, + updated_by=user, + predecessor=None, + organisation__submode=submodes[randint(0, len(submodes) - 1)], + organisation=org, + ) + p2 = PersonFactory.create( + role=role, + updated_by=user, + predecessor=None, + organisation__submode=submodes[randint(0, len(submodes) - 1)], + organisation=org, + ) + p3 = PersonFactory.create( + role=role, + updated_by=user, + predecessor=None, + organisation__submode=submodes[randint(0, len(submodes) - 1)], + organisation=org, + ) + + ee1 = EngagementEventFactory.create(user=user, participants=[p1, p2]) + ee2 = EngagementEventFactory.create(user=user, participants=[p3]) diff --git a/ctrack/register/tests.py b/ctrack/register/tests.py deleted file mode 100644 index 4d66077..0000000 --- a/ctrack/register/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -#from django.test import TestCase - -# Create your tests here. diff --git a/ctrack/register/tests/__init__.py b/ctrack/register/tests/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/ctrack/register/tests/__init__.py diff --git a/ctrack/register/tests/factories.py b/ctrack/register/tests/factories.py new file mode 100644 index 0000000..963c1a5 --- /dev/null +++ b/ctrack/register/tests/factories.py @@ -0,0 +1,69 @@ +import factory +import string +import random + +from django.utils import timezone + +from django.contrib.auth import get_user_model +from factory import post_generation + +from ctrack.register.models import EngagementEvent +from ctrack.register.models import EngagementType + +User = get_user_model() + + +def _regulation_scrambler(): + reg_type = ["Act", "Regulations", "Directive"] + reg_titles = [ + "NIS", + "ISO", + "NIRST", + "BIRST", + "Civil Communications", + "Paralegal Consequences", + "Marine and Inner-Waters", + "Rail Bridges and Overhead Wires", + "Internal Platform Sewage", + "Electrical Wires", + "Cyber Consciousness", + ] + section = ["Paragraph", "Section", "Appendix", "Chapter"] + return ( + f"{random.choice(reg_titles)} {random.choice(reg_type)} " + f"{str(random.randint(1945, 2020))} - " + f"{random.choice(section)} {str(random.randint(1, 100))}({random.choice(string.ascii_lowercase[:3])})" + ) + + +class EngagementTypeFactory(factory.DjangoModelFactory): + class Meta: + model = EngagementType + + descriptor = "Generic Engagement Type" + enforcement_instrument = True + regulation_reference = factory.LazyFunction(_regulation_scrambler) + + +class EngagementEventFactory(factory.DjangoModelFactory): + class Meta: + model = EngagementEvent + + @post_generation + def participants(self, create, extracted, **kwargs): + if not create: + return + if extracted: + for p in extracted: + self.participants.add(p) + + type = factory.SubFactory(EngagementTypeFactory) + short_description = factory.LazyAttribute(lambda o: f"An event related to {o.type.descriptor}") + # particpants fed in + # user fed in + date = factory.LazyFunction(timezone.now) + end_date = factory.LazyFunction(timezone.now) + document_link = factory.Faker("uri") + response_date_requested = factory.LazyFunction(timezone.now) + response_received = None + related_caf = None |