1@factory.django.mute_signals(post_save)
2class ProfileFactory(factory.django.DjangoModelFactory):
3 class Meta:
4 model = my_models.Profile
5
6 title = 'Dr'
7 # We pass in profile=None to prevent UserFactory from creating another profile
8 # (this disables the RelatedFactory)
9 user = factory.SubFactory('app.factories.UserFactory', profile=None)
10
11@factory.django.mute_signals(post_save)
12class UserFactory(factory.django.DjangoModelFactory):
13 class Meta:
14 model = auth_models.User
15
16 username = factory.Sequence(lambda n: "user_%d" % n)
17
18 # We pass in 'user' to link the generated Profile to our just-generated User
19 # This will call ProfileFactory(user=our_new_user), thus skipping the SubFactory.
20 profile = factory.RelatedFactory(ProfileFactory, factory_related_name='user')
21