aboutsummaryrefslogtreecommitdiffstats
path: root/ctrack/register/tests/factories.py
blob: b3666dd28a4d8935e2f403a646a85f58cbb04168 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import factory
import string
import random

from django.utils import timezone

from django.contrib.auth import get_user_model
from factory import post_generation, Faker

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.django.DjangoModelFactory):
    class Meta:
        model = EngagementType

    descriptor = "Generic Engagement Type"
    enforcement_instrument = True
    regulation_reference = factory.LazyFunction(_regulation_scrambler)
    single_date_type = True


class EngagementEventFactory(factory.django.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
    comments = Faker("paragraph", nb_sentences=5, variable_nb_sentences=True, ext_word_list=None)