# Path: user_management/api/models.py
# class AuthToken(models.Model):
#     """
#     Model for auth tokens with added functionality of controlling
#     expiration time of tokens.
# 
#     Similar to DRF's model but with extra `expires` field.
# 
#     It also has FK (not OneToOne relation) to user as the user can have
#     many tokens (multiple devices) in order to token expiration to work.
#     """
#     key = models.CharField(max_length=40, primary_key=True)
#     user = models.ForeignKey(
#         settings.AUTH_USER_MODEL,
#         related_name='authtoken',
#         on_delete=models.CASCADE,
#     )
#     created = models.DateTimeField(default=timezone.now, editable=False)
#     expires = models.DateTimeField(default=update_expiry, editable=False)
# 
#     def __str__(self):
#         return self.key
# 
#     def save(self, *args, **kwargs):
#         if not self.key:
#             self.key = self.generate_key()
#         return super(AuthToken, self).save(*args, **kwargs)
# 
#     def generate_key(self):
#         return binascii.hexlify(os.urandom(20)).decode()
# 
#     def update_expiry(self, commit=True):
#         """Update token's expiration datetime on every auth action."""
#         self.expires = update_expiry(self.created)
#         if commit:
#             self.save()
# 
# Path: user_management/models/tests/models.py
# class VerifyEmailUser(VerifyEmailMixin, AbstractBaseUser):
#     pass


import factory
from django.contrib.auth import get_user_model
from user_management.api.models import AuthToken
from user_management.models.tests.models import VerifyEmailUser




class UserFactory(factory.DjangoModelFactory):
    name = factory.Sequence('Test User {}'.format)
    email = factory.Sequence('email{}@example.com'.format)
    is_active = True

    class Meta:
        model = get_user_model()

    @factory.post_generation
    def password(self, create, extracted='default password', **kwargs):
        self.raw_password = extracted
        self.set_password(self.raw_password)
        if create:
            self.save()


class VerifyEmailUserFactory(UserFactory):
    email_verified = False

    class Meta:

# Path: user_management/api/models.py
# class AuthToken(models.Model):
#     """
#     Model for auth tokens with added functionality of controlling
#     expiration time of tokens.
# 
#     Similar to DRF's model but with extra `expires` field.
# 
#     It also has FK (not OneToOne relation) to user as the user can have
#     many tokens (multiple devices) in order to token expiration to work.
#     """
#     key = models.CharField(max_length=40, primary_key=True)
#     user = models.ForeignKey(
#         settings.AUTH_USER_MODEL,
#         related_name='authtoken',
#         on_delete=models.CASCADE,
#     )
#     created = models.DateTimeField(default=timezone.now, editable=False)
#     expires = models.DateTimeField(default=update_expiry, editable=False)
# 
#     def __str__(self):
#         return self.key
# 
#     def save(self, *args, **kwargs):
#         if not self.key:
#             self.key = self.generate_key()
#         return super(AuthToken, self).save(*args, **kwargs)
# 
#     def generate_key(self):
#         return binascii.hexlify(os.urandom(20)).decode()
# 
#     def update_expiry(self, commit=True):
#         """Update token's expiration datetime on every auth action."""
#         self.expires = update_expiry(self.created)
#         if commit:
#             self.save()
# 
# Path: user_management/models/tests/models.py
# class VerifyEmailUser(VerifyEmailMixin, AbstractBaseUser):
#     pass


# Path: user_management/models/tests/factories.py
import factory
from django.contrib.auth import get_user_model
from user_management.api.models import AuthToken
from user_management.models.tests.models import VerifyEmailUser





class UserFactory(factory.DjangoModelFactory):
    name = factory.Sequence('Test User {}'.format)
    email = factory.Sequence('email{}@example.com'.format)
    is_active = True

    class Meta:
        model = get_user_model()

    @factory.post_generation
    def password(self, create, extracted='default password', **kwargs):
        self.raw_password = extracted
        self.set_password(self.raw_password)
        if create:
            self.save()


class VerifyEmailUserFactory(UserFactory):
    email_verified = False

    class Meta:

        model = VerifyEmailUser