# Path: user_management/models/tests/factories.py
# class VerifyEmailUserFactory(UserFactory):
#     email_verified = False
# 
#     class Meta:
#         model = VerifyEmailUser
# 
# Path: user_management/models/tests/models.py
# class VerifyEmailUser(VerifyEmailMixin, AbstractBaseUser):
#     pass
# 
# Path: user_management/models/tests/utils.py
# class RequestTestCase(Python2AssertMixin, BaseRequestTestCase):
#     user_factory = UserFactory


from django.test import override_settings
from user_management.models.tests.factories import VerifyEmailUserFactory
from user_management.models.tests.models import VerifyEmailUser
from user_management.models.tests.utils import RequestTestCase
from .. import views




@override_settings(AUTH_USER_MODEL='tests.VerifyEmailUser')
class TestVerifyUserEmailView(RequestTestCase):
    view_class = views.VerifyUserEmailView

    def test_get(self):
        """A user clicks the link in their email and activates their account."""
        user = VerifyEmailUserFactory.create(email_verified=False)
        token = user.generate_validation_token()

        request = self.create_request('get', auth=False)
        view = self.view_class.as_view()
        response = view(request, token=token)
        self.assertEqual(response.status_code, 302)

        self.assertEqual(response.url, '/accounts/login/')


# Path: user_management/models/tests/factories.py
# class VerifyEmailUserFactory(UserFactory):
#     email_verified = False
# 
#     class Meta:
#         model = VerifyEmailUser
# 
# Path: user_management/models/tests/models.py
# class VerifyEmailUser(VerifyEmailMixin, AbstractBaseUser):
#     pass
# 
# Path: user_management/models/tests/utils.py
# class RequestTestCase(Python2AssertMixin, BaseRequestTestCase):
#     user_factory = UserFactory


# Path: user_management/ui/tests/test_views.py
from django.test import override_settings
from user_management.models.tests.factories import VerifyEmailUserFactory
from user_management.models.tests.models import VerifyEmailUser
from user_management.models.tests.utils import RequestTestCase
from .. import views





@override_settings(AUTH_USER_MODEL='tests.VerifyEmailUser')
class TestVerifyUserEmailView(RequestTestCase):
    view_class = views.VerifyUserEmailView

    def test_get(self):
        """A user clicks the link in their email and activates their account."""
        user = VerifyEmailUserFactory.create(email_verified=False)
        token = user.generate_validation_token()

        request = self.create_request('get', auth=False)
        view = self.view_class.as_view()
        response = view(request, token=token)
        self.assertEqual(response.status_code, 302)

        self.assertEqual(response.url, '/accounts/login/')


        user = VerifyEmailUser.objects.get(pk=user.pk)