39 lines
982 B
Python
39 lines
982 B
Python
import hashlib
|
|
import string
|
|
|
|
from django.utils.crypto import get_random_string
|
|
|
|
import factory
|
|
|
|
from registration.models import RegistrationProfile
|
|
|
|
from newsreader.accounts.models import User
|
|
|
|
|
|
def get_activation_key():
|
|
random_string = get_random_string(length=32, allowed_chars=string.printable)
|
|
return hashlib.sha1(random_string.encode("utf-8")).hexdigest()
|
|
|
|
|
|
class UserFactory(factory.django.DjangoModelFactory):
|
|
email = factory.Faker("email")
|
|
password = factory.Faker("password")
|
|
|
|
is_staff = False
|
|
is_active = True
|
|
|
|
@classmethod
|
|
def _create(cls, model_class, *args, **kwargs):
|
|
manager = cls._get_manager(model_class)
|
|
return manager.create_user(*args, **kwargs)
|
|
|
|
class Meta:
|
|
model = User
|
|
|
|
|
|
class RegistrationProfileFactory(factory.django.DjangoModelFactory):
|
|
user = factory.SubFactory(UserFactory)
|
|
activation_key = factory.LazyFunction(get_activation_key)
|
|
|
|
class Meta:
|
|
model = RegistrationProfile
|