43 lines
1.2 KiB
Python
Executable File
43 lines
1.2 KiB
Python
Executable File
import factory
|
|
from faker import Factory as FakerFactory
|
|
|
|
from outbo.apps.authentication import models
|
|
from tests.factories.organizations import (
|
|
AgencyOrganizationFactory,
|
|
ClientOrganizationFactory,
|
|
SupplierOrganizationFactory,
|
|
)
|
|
|
|
faker = FakerFactory.create()
|
|
|
|
|
|
class UserFactory(factory.django.DjangoModelFactory):
|
|
username = factory.LazyAttribute(lambda x: faker.profile()["username"])
|
|
first_name = factory.LazyAttribute(lambda x: faker.first_name())
|
|
last_name = factory.LazyAttribute(lambda x: faker.last_name())
|
|
email = factory.LazyAttribute(lambda x: faker.profile()["mail"])
|
|
is_staff = False
|
|
is_superuser = False
|
|
password = "password"
|
|
|
|
@classmethod
|
|
def _create(cls, model_class, *args, **kwargs):
|
|
manager = cls._get_manager(model_class)
|
|
return manager.create_user(*args, **kwargs)
|
|
|
|
class Meta:
|
|
model = models.User
|
|
django_get_or_create = ("username",)
|
|
|
|
|
|
class AgencyUserFactory(UserFactory):
|
|
organization = factory.SubFactory(AgencyOrganizationFactory)
|
|
|
|
|
|
class ClientUserFactory(UserFactory):
|
|
organization = factory.SubFactory(ClientOrganizationFactory)
|
|
|
|
|
|
class SupplierUserFactory(UserFactory):
|
|
organization = factory.SubFactory(SupplierOrganizationFactory)
|