Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #4526 -- Modified the test Client login method to fail when a u…

…ser is inactive. Thanks, marcin@elksoft.pl.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@5677 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit b8d0dc73c762bedc0a36bb380cded62a7b3ea162 1 parent b9232cd
Russell Keith-Magee authored July 12, 2007
5  django/test/client.py
@@ -225,10 +225,11 @@ def login(self, **credentials):
225 225
         """Set the Client to appear as if it has sucessfully logged into a site.
226 226
 
227 227
         Returns True if login is possible; False if the provided credentials
228  
-        are incorrect, or if the Sessions framework is not available.
  228
+        are incorrect, or the user is inactive, or if the Sessions framework is
  229
+        not available.
229 230
         """
230 231
         user = authenticate(**credentials)
231  
-        if user and 'django.contrib.sessions' in settings.INSTALLED_APPS:
  232
+        if user and user.is_active and 'django.contrib.sessions' in settings.INSTALLED_APPS:
232 233
             obj = Session.objects.get_new_session_object()
233 234
 
234 235
             # Create a fake request to store login details
18  tests/modeltests/test_client/fixtures/testdata.json
@@ -16,5 +16,23 @@
16 16
             "email": "testclient@example.com", 
17 17
             "date_joined": "2006-12-17 07:03:31"
18 18
         }
  19
+    },
  20
+    {
  21
+        "pk": "2", 
  22
+        "model": "auth.user", 
  23
+        "fields": {
  24
+            "username": "inactive", 
  25
+            "first_name": "Inactive", 
  26
+            "last_name": "User", 
  27
+            "is_active": false, 
  28
+            "is_superuser": false, 
  29
+            "is_staff": false, 
  30
+            "last_login": "2006-12-17 07:03:31", 
  31
+            "groups": [], 
  32
+            "user_permissions": [], 
  33
+            "password": "sha1$6efc0$f93efe9fd7542f25a7be94871ea45aa95de57161", 
  34
+            "email": "testclient@example.com", 
  35
+            "date_joined": "2006-12-17 07:03:31"
  36
+        }
19 37
     }
20 38
 ]
6  tests/modeltests/test_client/models.py
@@ -228,6 +228,12 @@ def test_view_with_bad_login(self):
228 228
         login = self.client.login(username='otheruser', password='nopassword')
229 229
         self.failIf(login)
230 230
 
  231
+    def test_view_with_inactive_login(self):
  232
+        "Request a page that is protected with @login, but use an inactive login"
  233
+
  234
+        login = self.client.login(username='inactive', password='password')
  235
+        self.failIf(login)
  236
+
231 237
     def test_session_modifying_view(self):
232 238
         "Request a page that modifies the session"
233 239
         # Session value isn't set initially

0 notes on commit b8d0dc7

Please sign in to comment.
Something went wrong with that request. Please try again.