From b8d0dc73c762bedc0a36bb380cded62a7b3ea162 Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Thu, 12 Jul 2007 15:26:37 +0000 Subject: [PATCH] Fixed #4526 -- Modified the test Client login method to fail when a user is inactive. Thanks, marcin@elksoft.pl. git-svn-id: http://code.djangoproject.com/svn/django/trunk@5677 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/test/client.py | 5 +++-- .../test_client/fixtures/testdata.json | 18 ++++++++++++++++++ tests/modeltests/test_client/models.py | 6 ++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/django/test/client.py b/django/test/client.py index ed72ad8f77..b43b3910be 100644 --- a/django/test/client.py +++ b/django/test/client.py @@ -225,10 +225,11 @@ class Client: """Set the Client to appear as if it has sucessfully logged into a site. Returns True if login is possible; False if the provided credentials - are incorrect, or if the Sessions framework is not available. + are incorrect, or the user is inactive, or if the Sessions framework is + not available. """ user = authenticate(**credentials) - if user and 'django.contrib.sessions' in settings.INSTALLED_APPS: + if user and user.is_active and 'django.contrib.sessions' in settings.INSTALLED_APPS: obj = Session.objects.get_new_session_object() # Create a fake request to store login details diff --git a/tests/modeltests/test_client/fixtures/testdata.json b/tests/modeltests/test_client/fixtures/testdata.json index 5c9e415240..e9d3ebe9a8 100644 --- a/tests/modeltests/test_client/fixtures/testdata.json +++ b/tests/modeltests/test_client/fixtures/testdata.json @@ -16,5 +16,23 @@ "email": "testclient@example.com", "date_joined": "2006-12-17 07:03:31" } + }, + { + "pk": "2", + "model": "auth.user", + "fields": { + "username": "inactive", + "first_name": "Inactive", + "last_name": "User", + "is_active": false, + "is_superuser": false, + "is_staff": false, + "last_login": "2006-12-17 07:03:31", + "groups": [], + "user_permissions": [], + "password": "sha1$6efc0$f93efe9fd7542f25a7be94871ea45aa95de57161", + "email": "testclient@example.com", + "date_joined": "2006-12-17 07:03:31" + } } ] \ No newline at end of file diff --git a/tests/modeltests/test_client/models.py b/tests/modeltests/test_client/models.py index 06e574590f..91c5d8c72f 100644 --- a/tests/modeltests/test_client/models.py +++ b/tests/modeltests/test_client/models.py @@ -228,6 +228,12 @@ class ClientTest(TestCase): login = self.client.login(username='otheruser', password='nopassword') self.failIf(login) + def test_view_with_inactive_login(self): + "Request a page that is protected with @login, but use an inactive login" + + login = self.client.login(username='inactive', password='password') + self.failIf(login) + def test_session_modifying_view(self): "Request a page that modifies the session" # Session value isn't set initially