text: import pytest
  from django.contrib.auth.models import AnonymousUser
  from django.http.response import Http404
  from django.test import RequestFactory
  
  from dj_starter.users.models import User
  from dj_starter.users.tests.factories import UserFactory
  from dj_starter.users.views import (
      UserRedirectView,
      UserUpdateView,
      user_detail_view,
  )
  
  pytestmark = pytest.mark.django_db
  
  
  class TestUserUpdateView:
      """
      TODO:
          extracting view initialization code as class-scoped fixture
          would be great if only pytest-django supported non-function-scoped
          fixture db access -- this is a work-in-progress for now:
          https://github.com/pytest-dev/pytest-django/pull/258
      """
  
      def test_get_success_url(self, user: User, rf: RequestFactory):
          view = UserUpdateView()
          request = rf.get("/fake-url/")
          request.user = user
  
          view.request = request
  
          assert view.get_success_url() == f"/users/{user.email}/"
  
      def test_get_object(self, user: User, rf: RequestFactory):
          view = UserUpdateView()
          request = rf.get("/fake-url/")
          request.user = user
  
          view.request = request
  
          assert view.get_object() == user
  
  
  class TestUserRedirectView:
      def test_get_redirect_url(self, user: User, rf: RequestFactory):
          view = UserRedirectView()
          request = rf.get("/fake-url")
          request.user = user
  
          view.request = request
  
          assert view.get_redirect_url() == f"/users/{user.email}/"
  
  
  class TestUserDetailView:
      def test_authenticated(self, user: User, rf: RequestFactory):
          request = rf.get("/fake-url/")
          request.user = UserFactory()
  
          response = user_detail_view(request, email=user.email)
  
          assert response.status_code == 200
  
      def test_not_authenticated(self, user: User, rf: RequestFactory):
          request = rf.get("/fake-url/")
          request.user = AnonymousUser()  # type: ignore
  
          response = user_detail_view(request, email=user.email)
  
          assert response.status_code == 302
          assert response.url == f"/accounts/login/?next=/fake-url/"
  
      def test_case_sensitivity(self, rf: RequestFactory):
          request = rf.get("/fake-url/")
          request.user = UserFactory(email="email")
  
          with pytest.raises(Http404):
              user_detail_view(request, email="email")
  