-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfactories.py
More file actions
152 lines (120 loc) · 5.03 KB
/
Copy pathfactories.py
File metadata and controls
152 lines (120 loc) · 5.03 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
from zoneinfo import ZoneInfo
import factory
from common.mixins import SaveAfterPostGenerationMixin
from occurrences.models import (
Enrolment,
EventQueueEnrolment,
Language,
Occurrence,
PalvelutarjotinEvent,
StudyGroup,
StudyLevel,
VenueCustomData,
)
from organisations.factories import OrganisationFactory, PersonFactory
class LanguageFactory(factory.django.DjangoModelFactory):
id = factory.Faker("pystr", max_chars=10)
name = factory.Faker("text", max_nb_chars=20)
class Meta:
model = Language
skip_postgeneration_save = True # Not needed after factory v4.0.0
class PalvelutarjotinEventFactory(factory.django.DjangoModelFactory):
linked_event_id = factory.Faker("pystr", max_chars=5)
enrolment_start = factory.Faker(
"date_time",
tzinfo=ZoneInfo("Europe/Helsinki"),
)
enrolment_end_days = factory.Faker("random_int", max=2)
needed_occurrences = factory.Faker("random_int", max=10)
contact_phone_number = factory.Faker("phone_number")
contact_email = factory.Faker("email")
organisation = factory.SubFactory(OrganisationFactory)
contact_person = factory.SubFactory(PersonFactory)
is_queueing_allowed = True
class Meta:
model = PalvelutarjotinEvent
skip_postgeneration_save = True # Not needed after factory v4.0.0
class OccurrenceFactory(
SaveAfterPostGenerationMixin, factory.django.DjangoModelFactory
):
place_id = factory.Faker("text", max_nb_chars=64)
min_group_size = factory.Faker("random_int", max=1000)
max_group_size = factory.Faker("random_int", max=1000)
start_time = factory.Faker("date_time", tzinfo=ZoneInfo("Europe/Helsinki"))
end_time = factory.Faker("date_time", tzinfo=ZoneInfo("Europe/Helsinki"))
p_event = factory.SubFactory(PalvelutarjotinEventFactory)
amount_of_seats = factory.Faker("random_int", max=50)
seat_type = Occurrence.OCCURRENCE_SEAT_TYPE_CHILDREN_COUNT
class Meta:
model = Occurrence
@factory.post_generation
def contact_persons(self, create, extracted, **kwargs):
if not create:
# Simple build, do nothing.
return
if extracted:
# A list of organisations were passed in, use them
for person in extracted:
self.contact_persons.add(person)
@factory.post_generation
def languages(self, create, extracted, **kwargs):
if not create:
# Simple build, do nothing.
return
if extracted:
# A list of organisations were passed in, use them
for language in extracted:
self.languages.add(language)
class StudyLevelFactory(factory.django.DjangoModelFactory):
id = factory.Faker("text", max_nb_chars=10)
label = factory.Faker("text", max_nb_chars=20)
level = factory.Faker("random_int", min=0, max=15)
class Meta:
model = StudyLevel
skip_postgeneration_save = True # Not needed after factory v4.0.0
class StudyGroupFactory(
SaveAfterPostGenerationMixin, factory.django.DjangoModelFactory
):
person = factory.SubFactory(PersonFactory)
unit_name = factory.Faker("text", max_nb_chars=100)
group_size = factory.Faker("random_int", max=1000)
extra_needs = factory.Faker("text", max_nb_chars=100)
group_name = factory.Faker("text", max_nb_chars=100)
amount_of_adult = 0
preferred_times = factory.Faker("text", max_nb_chars=30)
@factory.post_generation
def study_levels(self, create, extracted, **kwargs):
if not create:
# Simple build, do nothing.
return
if extracted:
# A list of organisations were passed in, use them
for study_level in extracted:
self.study_levels.add(study_level)
class Meta:
model = StudyGroup
class EventQueueEnrolmentFactory(factory.django.DjangoModelFactory):
is_part_of_cultural_route = factory.Faker("boolean")
study_group = factory.SubFactory(StudyGroupFactory)
p_event = factory.SubFactory(PalvelutarjotinEventFactory)
person = factory.SubFactory(PersonFactory)
class Meta:
model = EventQueueEnrolment
skip_postgeneration_save = True # Not needed after factory v4.0.0
class EnrolmentFactory(factory.django.DjangoModelFactory):
is_part_of_cultural_route = factory.Faker("boolean")
study_group = factory.SubFactory(StudyGroupFactory)
occurrence = factory.SubFactory(OccurrenceFactory)
person = factory.SubFactory(PersonFactory)
class Meta:
model = Enrolment
skip_postgeneration_save = True # Not needed after factory v4.0.0
class VenueCustomDataFactory(factory.django.DjangoModelFactory):
place_id = factory.Faker("pystr", max_chars=5)
description = factory.Faker("text", max_nb_chars=100)
has_clothing_storage = factory.Faker("boolean")
has_snack_eating_place = factory.Faker("boolean")
outdoor_activity = factory.Faker("boolean")
class Meta:
model = VenueCustomData
skip_postgeneration_save = True # Not needed after factory v4.0.0