class CommunicationMessage Factory DjangoModelFactory class Meta model

 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
class CommunicationMessageFactory(DjangoModelFactory):
class Meta:
model = CommunicationMessage
sub_matter = factory.SubFactory(SubMatterFactory)
sender = factory.SubFactory(UserFactory)
subject = factory.Sequence(lambda n: 'Message {0}'.format(n))
body = factory.Sequence(lambda n: 'Just text {0}'.format(n))
@factory.post_generation
def user_recipients(self, create, extracted, **kwargs):
if not create:
return
if extracted:
for user in extracted:
self.user_recipients.add(user)
@factory.post_generation
def contact_recipients(self, create, extracted, **kwargs):
if not create:
return
if extracted:
for contact in extracted:
self.contact_recipients.add(contact)
CommunicationMessageFactory(user_recipients=[user])