# Path: pyfreebilling/users/views.py
# class UserDetailView(LoginRequiredMixin, DetailView):
# class UserListView(LoginRequiredMixin, ListView):
# class UserUpdateView(LoginRequiredMixin, UpdateView):
# class UserRedirectView(LoginRequiredMixin, RedirectView):
#     def get_success_url(self):
#     def get_object(self):
#     def form_valid(self, form):
#     def get_redirect_url(self):


import pytest
from django.contrib.auth.models import AnonymousUser
from django.http.response import Http404
from django.test import RequestFactory
from pyfreebilling.users.models import User
from pyfreebilling.users.tests.factories import UserFactory
from pyfreebilling.users.views import (
    UserRedirectView,
    UserUpdateView,
    user_detail_view,
)
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.username}/"

    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):

# Path: pyfreebilling/users/views.py
# class UserDetailView(LoginRequiredMixin, DetailView):
# class UserListView(LoginRequiredMixin, ListView):
# class UserUpdateView(LoginRequiredMixin, UpdateView):
# class UserRedirectView(LoginRequiredMixin, RedirectView):
#     def get_success_url(self):
#     def get_object(self):
#     def form_valid(self, form):
#     def get_redirect_url(self):


# Path: pyfreebilling/users/tests/test_views.py
import pytest
from django.contrib.auth.models import AnonymousUser
from django.http.response import Http404
from django.test import RequestFactory
from pyfreebilling.users.models import User
from pyfreebilling.users.tests.factories import UserFactory
from pyfreebilling.users.views import (
    UserRedirectView,
    UserUpdateView,
    user_detail_view,
)

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.username}/"

    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()