Answers for "factory subfactory"

0

factory subfactory

class UserFactory(factory.django.DjangoModelFactory):
    class Meta:
        model = models.User

    name = "John"
    lang = factory.SelfAttribute('country.lang')
    country = factory.SubFactory(CountryFactory)

class CompanyFactory(factory.django.DjangoModelFactory):
    class Meta:
        model = models.Company

    name = "ACME, Inc."
    country = factory.SubFactory(CountryFactory)
    # use ".." to go a step back and access to CompanyFactory attrs
    owner = factory.SubFactory(UserFactory, country=factory.SelfAttribute('..country'))
Posted by: Guest on February-13-2020

Python Answers by Framework

Browse Popular Code Answers by Language