import hashlib
import string

from django.utils.crypto import get_random_string

import factory

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
