1
|
|
|
# -*- coding: utf-8 -*- |
2
|
|
|
|
3
|
|
|
# Third Party Stuff |
4
|
|
|
import datetime |
5
|
|
|
|
6
|
|
|
from django.conf import settings |
7
|
|
|
|
8
|
|
|
import factory |
9
|
|
|
from wye.base.constants import OrganisationType, WorkshopLevel, WorkshopStatus |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class Factory(factory.DjangoModelFactory): |
13
|
|
|
|
14
|
|
|
class Meta: |
15
|
|
|
strategy = factory.CREATE_STRATEGY |
16
|
|
|
model = None |
17
|
|
|
abstract = True |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
class UserTypeFactory(Factory): |
21
|
|
|
|
22
|
|
|
class Meta: |
23
|
|
|
model = 'profiles.UserType' |
24
|
|
|
|
25
|
|
|
|
26
|
|
|
class UserFactory(Factory): |
27
|
|
|
|
28
|
|
|
class Meta: |
29
|
|
|
model = settings.AUTH_USER_MODEL |
30
|
|
|
|
31
|
|
|
username = factory.Sequence(lambda n: 'user%04d' % n) |
32
|
|
|
email = factory.Sequence(lambda n: 'user%[email protected]' % n) |
33
|
|
|
password = factory.PostGeneration( |
34
|
|
|
lambda obj, *args, **kwargs: obj.set_password('123123')) |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
class StateFactory(Factory): |
38
|
|
|
|
39
|
|
|
class Meta: |
40
|
|
|
model = "regions.State" |
41
|
|
|
|
42
|
|
|
name = factory.Sequence(lambda n: "state{}".format(n)) |
43
|
|
|
|
44
|
|
|
|
45
|
|
|
class LocationFactory(Factory): |
46
|
|
|
|
47
|
|
|
class Meta: |
48
|
|
|
model = "regions.Location" |
49
|
|
|
name = factory.Sequence(lambda n: "location{}".format(n)) |
50
|
|
|
state = factory.SubFactory("tests.factories.StateFactory") |
51
|
|
|
|
52
|
|
|
|
53
|
|
|
class OrganisationFactory(Factory): |
54
|
|
|
|
55
|
|
|
class Meta: |
56
|
|
|
model = "organisations.Organisation" |
57
|
|
|
|
58
|
|
|
name = factory.Sequence(lambda n: "organisation{}".format(n)) |
59
|
|
|
description = factory.Sequence( |
60
|
|
|
lambda n: "organisation_Description{}".format(n)) |
61
|
|
|
organisation_role = factory.Sequence( |
62
|
|
|
lambda n: "organisation_role{}".format(n)) |
63
|
|
|
organisation_type = factory.Iterator(dict(OrganisationType.CHOICES).keys()) |
64
|
|
|
location = factory.SubFactory("tests.factories.LocationFactory") |
65
|
|
|
|
66
|
|
|
|
67
|
|
|
class RegionalLeadFactory(Factory): |
68
|
|
|
class Meta: |
69
|
|
|
model = "regions.RegionalLead" |
70
|
|
|
|
71
|
|
|
location = factory.SubFactory("tests.factories.LocationFactory") |
72
|
|
|
|
73
|
|
|
|
74
|
|
|
class WorkshopSectionFactory(Factory): |
75
|
|
|
|
76
|
|
|
class Meta: |
77
|
|
|
model = 'workshops.WorkshopSections' |
78
|
|
|
|
79
|
|
|
|
80
|
|
|
class WorkshopFactory(Factory): |
81
|
|
|
|
82
|
|
|
class Meta: |
83
|
|
|
model = "workshops.Workshop" |
84
|
|
|
|
85
|
|
|
description = factory.Sequence( |
86
|
|
|
lambda n: "Workshop_Description{}".format(n)) |
87
|
|
|
no_of_participants = 20 |
88
|
|
|
requester = factory.SubFactory("tests.factories.OrganisationFactory") |
89
|
|
|
location = factory.SubFactory("tests.factories.LocationFactory") |
90
|
|
|
workshop_level = factory.Iterator(dict(WorkshopLevel.CHOICES).keys()) |
91
|
|
|
workshop_section = factory.SubFactory( |
92
|
|
|
"tests.factories.WorkshopSectionFactory") |
93
|
|
|
status = factory.Iterator(dict(WorkshopStatus.CHOICES).keys()) |
94
|
|
|
expected_date = datetime.datetime.now() |
95
|
|
|
|
96
|
|
|
|
97
|
|
|
class WorkshopRatingValuesFactory(Factory): |
98
|
|
|
|
99
|
|
|
class Meta: |
100
|
|
|
model = "workshops.WorkshopRatingValues" |
101
|
|
|
name = factory.Sequence(lambda n: "Rating{}".format(n)) |
102
|
|
|
|
103
|
|
|
|
104
|
|
|
def create_usertype(**kwargs): |
105
|
|
|
return UserTypeFactory.create(**kwargs) |
106
|
|
|
|
107
|
|
|
|
108
|
|
|
def create_user(**kwargs): |
109
|
|
|
"Create an user along with their dependencies" |
110
|
|
|
return UserFactory.create(**kwargs) |
111
|
|
|
|
112
|
|
|
|
113
|
|
|
def create_organisation(**kwargs): |
114
|
|
|
return OrganisationFactory.create(**kwargs) |
115
|
|
|
|
116
|
|
|
|
117
|
|
|
def create_regional_lead(**kwargs): |
118
|
|
|
return RegionalLeadFactory.create(**kwargs) |
119
|
|
|
|
120
|
|
|
|
121
|
|
|
def create_workshop(**kwargs): |
122
|
|
|
return WorkshopFactory.create(**kwargs) |
123
|
|
|
|
124
|
|
|
|
125
|
|
|
def create_workshop_rating(**kwargs): |
126
|
|
|
return WorkshopRatingValuesFactory.create(**kwargs) |
127
|
|
|
|
128
|
|
|
|
129
|
|
|
def create_workshop_section(**kwargs): |
130
|
|
|
return WorkshopSectionFactory.create(**kwargs) |
131
|
|
|
|
132
|
|
|
|
133
|
|
|
def create_locaiton(**kwargs): |
134
|
|
|
return LocationFactory.create(**kwargs) |
135
|
|
|
|
136
|
|
|
|
137
|
|
|
def create_state(**kwargs): |
138
|
|
|
return StateFactory.create(**kwargs) |
139
|
|
|
|