# Path: user_management/api/models.py
# MINUTE = 60
# HOUR = 60 * MINUTE
# DAY = 24 * HOUR
# DEFAULT_AUTH_TOKEN_MAX_AGE = 200 * DAY
# DEFAULT_AUTH_TOKEN_MAX_INACTIVITY = 12 * HOUR
# def update_expiry(created=None):
#     def __str__(self):
#     def save(self, *args, **kwargs):
#     def generate_key(self):
#     def update_expiry(self, commit=True):
# class AuthToken(models.Model):
# 
# Path: user_management/api/views.py
# class GetAuthToken(ObtainAuthToken):
# class UserRegister(generics.CreateAPIView):
# class PasswordResetEmail(generics.GenericAPIView):
# class OneTimeUseAPIMixin(object):
# class PasswordReset(OneTimeUseAPIMixin, generics.UpdateAPIView):
# class PasswordChange(generics.UpdateAPIView):
# class VerifyAccountView(VerifyAccountViewMixin, views.APIView):
# class ProfileDetail(generics.RetrieveUpdateDestroyAPIView):
# class UserList(generics.ListCreateAPIView):
# class UserDetail(generics.RetrieveUpdateDestroyAPIView):
# class ResendConfirmationEmail(generics.GenericAPIView):
#     def post(self, request):
#     def delete(self, request, *args, **kwargs):
#     def create(self, request, *args, **kwargs):
#     def is_invalid(self, serializer):
#     def is_valid(self, serializer):
#     def post(self, request, *args, **kwargs):
#     def initial(self, request, *args, **kwargs):
#     def get_object(self):
#     def get_object(self):
#     def initial(self, request, *args, **kwargs):
#     def post(self, request, *args, **kwargs):
#     def get_object(self):
#     def initial(self, request, *args, **kwargs):
#     def post(self, request, *args, **kwargs):
# 
# Path: user_management/api/tests/test_throttling.py
# THROTTLE_RATE_PATH = 'rest_framework.throttling.ScopedRateThrottle.THROTTLE_RATES'
# 
# Path: user_management/models/tests/factories.py
# class AuthTokenFactory(factory.DjangoModelFactory):
#     key = factory.Sequence('key{}'.format)
#     user = factory.SubFactory(UserFactory)
# 
#     class Meta:
#         model = AuthToken
# 
# 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()
# 
# Path: user_management/models/tests/models.py
# class BasicUser(BasicUserFieldsMixin, AbstractBaseUser):
#     pass
# 
# Path: user_management/models/tests/utils.py
# class APIRequestTestCase(Python2AssertMixin, BaseAPIRequestTestCase):
#     user_factory = UserFactory
# 
# Path: user_management/tests/utils.py
# def iso_8601(datetime):
#     """Convert a datetime into an iso 8601 string."""
#     if datetime is None:
#         return datetime
#     value = datetime.isoformat()
#     if value.endswith('+00:00'):
#         value = value[:-6] + 'Z'
#     return value


import datetime
import re
from collections import OrderedDict
from django.contrib.auth import get_user_model, signals
from django.contrib.auth.hashers import check_password
from django.contrib.auth.tokens import default_token_generator
from django.contrib.sites.models import Site
from django.core import mail
from django.core.cache import cache
from django.test import override_settings
from django.urls import reverse
from django.utils import timezone
from django.utils.encoding import force_bytes
from django.utils.http import urlsafe_base64_encode
from mock import MagicMock, patch
from rest_framework import status
from rest_framework.test import APIRequestFactory
from user_management.api import models, views
from user_management.api.tests.test_throttling import THROTTLE_RATE_PATH
from user_management.models.tests.factories import AuthTokenFactory, UserFactory
from user_management.models.tests.models import BasicUser
from user_management.models.tests.utils import APIRequestTestCase
from user_management.tests.utils import iso_8601



User = get_user_model()
TEST_SERVER = 'http://testserver'
SEND_METHOD = 'user_management.utils.notifications.incuna_mail.send'
EMAIL_CONTEXT = 'user_management.utils.notifications.password_reset_email_context'
REGISTRATION_SERIALIZER_META_MODEL = (
    'user_management.api.serializers.RegistrationSerializer.Meta.model'
)


class GetAuthTokenTest(APIRequestTestCase):
    model = models.AuthToken
    view_class = views.GetAuthToken

    def setUp(self):
        self.username = 'Test@example.com'
        self.password = 'myepicstrongpassword'
        self.data = {'username': self.username, 'password': self.password}

    def tearDown(self):
        cache.clear()

    def test_post(self):
        """Assert user can sign in"""

# Path: user_management/api/models.py
# MINUTE = 60
# HOUR = 60 * MINUTE
# DAY = 24 * HOUR
# DEFAULT_AUTH_TOKEN_MAX_AGE = 200 * DAY
# DEFAULT_AUTH_TOKEN_MAX_INACTIVITY = 12 * HOUR
# def update_expiry(created=None):
#     def __str__(self):
#     def save(self, *args, **kwargs):
#     def generate_key(self):
#     def update_expiry(self, commit=True):
# class AuthToken(models.Model):
# 
# Path: user_management/api/views.py
# class GetAuthToken(ObtainAuthToken):
# class UserRegister(generics.CreateAPIView):
# class PasswordResetEmail(generics.GenericAPIView):
# class OneTimeUseAPIMixin(object):
# class PasswordReset(OneTimeUseAPIMixin, generics.UpdateAPIView):
# class PasswordChange(generics.UpdateAPIView):
# class VerifyAccountView(VerifyAccountViewMixin, views.APIView):
# class ProfileDetail(generics.RetrieveUpdateDestroyAPIView):
# class UserList(generics.ListCreateAPIView):
# class UserDetail(generics.RetrieveUpdateDestroyAPIView):
# class ResendConfirmationEmail(generics.GenericAPIView):
#     def post(self, request):
#     def delete(self, request, *args, **kwargs):
#     def create(self, request, *args, **kwargs):
#     def is_invalid(self, serializer):
#     def is_valid(self, serializer):
#     def post(self, request, *args, **kwargs):
#     def initial(self, request, *args, **kwargs):
#     def get_object(self):
#     def get_object(self):
#     def initial(self, request, *args, **kwargs):
#     def post(self, request, *args, **kwargs):
#     def get_object(self):
#     def initial(self, request, *args, **kwargs):
#     def post(self, request, *args, **kwargs):
# 
# Path: user_management/api/tests/test_throttling.py
# THROTTLE_RATE_PATH = 'rest_framework.throttling.ScopedRateThrottle.THROTTLE_RATES'
# 
# Path: user_management/models/tests/factories.py
# class AuthTokenFactory(factory.DjangoModelFactory):
#     key = factory.Sequence('key{}'.format)
#     user = factory.SubFactory(UserFactory)
# 
#     class Meta:
#         model = AuthToken
# 
# 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()
# 
# Path: user_management/models/tests/models.py
# class BasicUser(BasicUserFieldsMixin, AbstractBaseUser):
#     pass
# 
# Path: user_management/models/tests/utils.py
# class APIRequestTestCase(Python2AssertMixin, BaseAPIRequestTestCase):
#     user_factory = UserFactory
# 
# Path: user_management/tests/utils.py
# def iso_8601(datetime):
#     """Convert a datetime into an iso 8601 string."""
#     if datetime is None:
#         return datetime
#     value = datetime.isoformat()
#     if value.endswith('+00:00'):
#         value = value[:-6] + 'Z'
#     return value


# Path: user_management/api/tests/test_views.py
import datetime
import re
from collections import OrderedDict
from django.contrib.auth import get_user_model, signals
from django.contrib.auth.hashers import check_password
from django.contrib.auth.tokens import default_token_generator
from django.contrib.sites.models import Site
from django.core import mail
from django.core.cache import cache
from django.test import override_settings
from django.urls import reverse
from django.utils import timezone
from django.utils.encoding import force_bytes
from django.utils.http import urlsafe_base64_encode
from mock import MagicMock, patch
from rest_framework import status
from rest_framework.test import APIRequestFactory
from user_management.api import models, views
from user_management.api.tests.test_throttling import THROTTLE_RATE_PATH
from user_management.models.tests.factories import AuthTokenFactory, UserFactory
from user_management.models.tests.models import BasicUser
from user_management.models.tests.utils import APIRequestTestCase
from user_management.tests.utils import iso_8601




User = get_user_model()
TEST_SERVER = 'http://testserver'
SEND_METHOD = 'user_management.utils.notifications.incuna_mail.send'
EMAIL_CONTEXT = 'user_management.utils.notifications.password_reset_email_context'
REGISTRATION_SERIALIZER_META_MODEL = (
    'user_management.api.serializers.RegistrationSerializer.Meta.model'
)


class GetAuthTokenTest(APIRequestTestCase):
    model = models.AuthToken
    view_class = views.GetAuthToken

    def setUp(self):
        self.username = 'Test@example.com'
        self.password = 'myepicstrongpassword'
        self.data = {'username': self.username, 'password': self.password}

    def tearDown(self):
        cache.clear()

    def test_post(self):
        """Assert user can sign in"""

        UserFactory.create(email=self.username, password=self.password)