-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathfactories.py
57 lines (46 loc) · 2.04 KB
/
factories.py
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
# coding: utf-8
"""
Test data factories for staffing module
@author: Sébastien Renard (sebastien.renard@digitalfox.org)
@license: AGPL v3 or newer (http://www.gnu.org/licenses/agpl-3.0.html)
"""
from factory.django import DjangoModelFactory
import factory.fuzzy
from crm.models import Subsidiary
from staffing.models import Mission, MarketingProduct
from leads.models import Lead
from people.models import Consultant
from staffing.utils import staffingDates
class MarketingProductFactory(DjangoModelFactory):
code = factory.Sequence(lambda n: "MP%02d" % n)
description = factory.Iterator(["Audit", "Development", "UX", "CyberSec", "Project Management", "Datascience", "Strategy", "Devops" ])
subsidiary = factory.fuzzy.FuzzyChoice(Subsidiary.objects.all())
class Meta:
model = "staffing.MarketingProduct"
class ProdMissionFactory(DjangoModelFactory):
nature = "PROD"
billing_mode = factory.fuzzy.FuzzyChoice([m[0] for m in Mission.BILLING_MODES])
marketing_product = factory.fuzzy.FuzzyChoice(MarketingProduct.objects.all())
responsible = factory.SelfAttribute("lead.responsible")
subsidiary = factory.SelfAttribute("lead.subsidiary")
price = factory.SelfAttribute("lead.sales")
description = factory.Faker("word")
active = factory.LazyAttribute(lambda o: o.lead.state in [s[0] for s in Lead.STATES[:5]])
@factory.lazy_attribute
def probability(self):
if self.lead.state == "WON":
return 100
elif self.lead.state in ("LOST", "FORGIVEN", "SLEEP"):
return 0
else:
return 50
class Meta:
model = "staffing.Mission"
class OtherStaffingFactory(DjangoModelFactory):
consultant = factory.Iterator(Consultant.objects.all())
mission = factory.fuzzy.FuzzyChoice(Mission.objects.exclude(nature="PROD"))
staffing_date = factory.Iterator(staffingDates(4, format="datetime"))
charge = factory.fuzzy.FuzzyInteger(1, 5)
class Meta:
model = "staffing.Staffing"
django_get_or_create = ("consultant", "mission", "staffing_date",)