# Path: user_management/models/tests/factories.py
# class UserFactory(factory.DjangoModelFactory):
#     class Meta:
# class VerifyEmailUserFactory(UserFactory):
#     class Meta:
# class AuthTokenFactory(factory.DjangoModelFactory):
#     class Meta:
#     def password(self, create, extracted='default password', **kwargs):
# 
# Path: user_management/models/tests/utils.py
# class APIRequestTestCase(Python2AssertMixin, BaseAPIRequestTestCase):
# class RequestTestCase(Python2AssertMixin, BaseRequestTestCase):
# 
# 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()


from user_management.models.tests import factories, utils
from ..models import AuthToken


class TestAuthToken(utils.APIRequestTestCase):
    model = AuthToken

    def test_fields(self):
        fields = {field.name for field in self.model._meta.get_fields()}

        expected = (
            # Inherited from subclassed model
            'key',
            'user',
            'created',

            'expires',
        )

        self.assertCountEqual(fields, expected)

    def test_unicode(self):
        uni_key = 'OSSUM'
        obj = self.model(key=uni_key)
        self.assertEqual(str(obj), uni_key)

    def test_multiple_tokens(self):

# Path: user_management/models/tests/factories.py
# class UserFactory(factory.DjangoModelFactory):
#     class Meta:
# class VerifyEmailUserFactory(UserFactory):
#     class Meta:
# class AuthTokenFactory(factory.DjangoModelFactory):
#     class Meta:
#     def password(self, create, extracted='default password', **kwargs):
# 
# Path: user_management/models/tests/utils.py
# class APIRequestTestCase(Python2AssertMixin, BaseAPIRequestTestCase):
# class RequestTestCase(Python2AssertMixin, BaseRequestTestCase):
# 
# 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/api/tests/test_models.py
from user_management.models.tests import factories, utils
from ..models import AuthToken



class TestAuthToken(utils.APIRequestTestCase):
    model = AuthToken

    def test_fields(self):
        fields = {field.name for field in self.model._meta.get_fields()}

        expected = (
            # Inherited from subclassed model
            'key',
            'user',
            'created',

            'expires',
        )

        self.assertCountEqual(fields, expected)

    def test_unicode(self):
        uni_key = 'OSSUM'
        obj = self.model(key=uni_key)
        self.assertEqual(str(obj), uni_key)

    def test_multiple_tokens(self):

        user = factories.UserFactory.create()