Removed unnecessary test for username case sensitivity since django usernames are case sensitive by default. Also made the redirecting to the login url more dynamic by fetching the defined login_url from settings

This commit is contained in:
Arnav Choudhury 2021-02-04 15:28:08 +05:30
parent fc01e870bd
commit fc8e2ea8a2

View File

@ -1,10 +1,12 @@
import pytest import pytest
from django.conf import settings
from django.contrib import messages from django.contrib import messages
from django.contrib.auth.models import AnonymousUser from django.contrib.auth.models import AnonymousUser
from django.contrib.messages.middleware import MessageMiddleware from django.contrib.messages.middleware import MessageMiddleware
from django.contrib.sessions.middleware import SessionMiddleware from django.contrib.sessions.middleware import SessionMiddleware
from django.http.response import Http404 from django.http.response import Http404
from django.test import RequestFactory from django.test import RequestFactory
from django.urls import reverse
from {{ cookiecutter.project_slug }}.users.forms import UserChangeForm from {{ cookiecutter.project_slug }}.users.forms import UserChangeForm
from {{ cookiecutter.project_slug }}.users.models import User from {{ cookiecutter.project_slug }}.users.models import User
@ -90,13 +92,7 @@ class TestUserDetailView:
request.user = AnonymousUser() request.user = AnonymousUser()
response = user_detail_view(request, username=user.username) response = user_detail_view(request, username=user.username)
login_url = reverse(settings.LOGIN_URL)
assert response.status_code == 302 assert response.status_code == 302
assert response.url == "/accounts/login/?next=/fake-url/" assert response.url == f"{login_url}?next=/fake-url/"
def test_case_sensitivity(self, rf: RequestFactory):
request = rf.get("/fake-url/")
request.user = UserFactory(username="UserName")
with pytest.raises(Http404):
user_detail_view(request, username="username")