Refs #21831 -- Softened the TestClient dependency on contrib.auth.
This is to prevent an import of django.test causing an import (and thus an implicit checks regisration) for an app that may not be in `INSTALLED_APPS`. Better fixes may be possible when #20915 and/or #21829 are addressed. Thanks to @carljm for the report.
This commit is contained in:
parent
8efd20f96d
commit
56516ade5e
|
@ -10,7 +10,6 @@ from io import BytesIO
|
||||||
|
|
||||||
from django.apps import apps
|
from django.apps import apps
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.auth import authenticate, login, logout, get_user_model
|
|
||||||
from django.core.handlers.base import BaseHandler
|
from django.core.handlers.base import BaseHandler
|
||||||
from django.core.handlers.wsgi import WSGIRequest
|
from django.core.handlers.wsgi import WSGIRequest
|
||||||
from django.core.signals import (request_started, request_finished,
|
from django.core.signals import (request_started, request_finished,
|
||||||
|
@ -548,6 +547,7 @@ class Client(RequestFactory):
|
||||||
are incorrect, or the user is inactive, or if the sessions framework is
|
are incorrect, or the user is inactive, or if the sessions framework is
|
||||||
not available.
|
not available.
|
||||||
"""
|
"""
|
||||||
|
from django.contrib.auth import authenticate, login
|
||||||
user = authenticate(**credentials)
|
user = authenticate(**credentials)
|
||||||
if (user and user.is_active and
|
if (user and user.is_active and
|
||||||
apps.is_installed('django.contrib.sessions')):
|
apps.is_installed('django.contrib.sessions')):
|
||||||
|
@ -587,6 +587,7 @@ class Client(RequestFactory):
|
||||||
|
|
||||||
Causes the authenticated user to be logged out.
|
Causes the authenticated user to be logged out.
|
||||||
"""
|
"""
|
||||||
|
from django.contrib.auth import get_user_model, logout
|
||||||
# Create a fake request that goes through request middleware
|
# Create a fake request that goes through request middleware
|
||||||
request = self.request().wsgi_request
|
request = self.request().wsgi_request
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue