Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class UserSubFactory(factory.DjangoModelFactory):
- """
- Used as a related sub factory for UserProfileFactory.
- """
- class Meta:
- model = 'auth.User'
- @classmethod
- def _create(cls, model_class, *args, **kwargs):
- """Override the default ``_create`` with the create_user call. This allows setting the password directly"""
- manager = cls._get_manager(model_class)
- # The default would use ``manager.create(*args, **kwargs)``
- return manager.create_user(*args, **kwargs)
- class UserProfileFactory(factory.DjangoModelFactory):
- """
- Will be mainly used for testing, as it will always create an associated user
- with identical information to the profile.
- """
- class Meta:
- model = 'profiles.UserProfile'
- # If no company is specifically provided beforehand, perform a get_or_create for a company called rodeapps.
- company = factory.SubFactory('sibylsurveys.modules.company.factories.CompanyFactory', name='Rodeapps')
- first_name = 'John'
- last_name = 'Doe'
- username = factory.Sequence(lambda n: 'user%d' % n)
- email = factory.LazyAttribute(lambda obj: '%s@gmail.com' % obj.username)
- # This will always create a new corresponding user.
- user = factory.SubFactory(
- UserSubFactory,
- username=factory.SelfAttribute('..username'),
- first_name=factory.SelfAttribute('..first_name'),
- last_name=factory.SelfAttribute('..last_name'),
- email=factory.SelfAttribute('..email'),
- password='pass'
- )
- has_app_access = True
- has_bo_access = True
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement