Code

Ticket #8713: test-client.diff

File test-client.diff, 1.4 KB (added by Piotr Lewandowski <django@…>, 6 years ago)
Line 
1Index: django/test/client.py
2===================================================================
3--- django/test/client.py       (revision 8773)
4+++ django/test/client.py       (working copy)
5@@ -7,7 +7,6 @@
6     from StringIO import StringIO
7 
8 from django.conf import settings
9-from django.contrib.auth import authenticate, login
10 from django.core.handlers.base import BaseHandler
11 from django.core.handlers.wsgi import WSGIRequest
12 from django.core.signals import got_request_exception
13@@ -289,12 +288,15 @@
14         Sets the Client to appear as if it has successfully logged into a site.
15 
16         Returns True if login is possible; False if the provided credentials
17-        are incorrect, or the user is inactive, or if the sessions framework is
18-        not available.
19+        are incorrect, or the user is inactive, or if the sessions or auth
20+        framework is not available.
21         """
22+        if 'django.contrib.auth' not in settings.INSTALLED_APPS \
23+        or 'django.contrib.sessions' not in settings.INSTALLED_APPS:
24+            return False
25+        from django.contrib.auth import authenticate, login
26         user = authenticate(**credentials)
27-        if user and user.is_active \
28-                and 'django.contrib.sessions' in settings.INSTALLED_APPS:
29+        if user and user.is_active:
30             engine = __import__(settings.SESSION_ENGINE, {}, {}, [''])
31 
32             # Create a fake request to store login details.