<reponame>trivenews/central
import factory
from factory import fuzzy
from django.utils import timezone
from .models import User
from ..wallet.factories import WalletFactory


class UserFactory(factory.django.DjangoModelFactory):

    class Meta:
        model = User

    username = factory.Sequence(lambda n: 'user%s' % n)
    first_name = fuzzy.FuzzyText(length=5)
    last_name = fuzzy.FuzzyText(length=10)
    email = factory.LazyAttribute(lambda o: <EMAIL>' % o.username)
    date_joined = factory.LazyFunction(timezone.now)
    wallet = factory.SubFactory(WalletFactory)

    @classmethod
    def _create(cls, *args, **kwargs):
        obj = super()._create(*args, **kwargs)
        obj.wallet.owner = obj
        obj.wallet.save()
        return obj

import factory
from factory import fuzzy
from django.utils import timezone
from .models import User
from ..wallet.factories import WalletFactory


class UserFactory(factory.django.DjangoModelFactory):

    class Meta:
        model = User

    username = factory.Sequence(lambda n: 'user%s' % n)
    first_name = fuzzy.FuzzyText(length=5)
    last_name = fuzzy.FuzzyText(length=10)
    email = factory.LazyAttribute(lambda o: <EMAIL>' % o.username)
    date_joined = factory.LazyFunction(timezone.now)
    wallet = factory.SubFactory(WalletFactory)

    @classmethod
    def _create(cls, *args, **kwargs):
        obj = super()._create(*args, **kwargs)
        obj.wallet.owner = obj
        obj.wallet.save()
        return obj