Ticket #5938: testclient_login_without_password.diff
File testclient_login_without_password.diff, 2.5 KB (added by , 17 years ago) |
---|
-
tests/regressiontests/test_client_regress/models.py
261 261 # Check that assertRedirects uses the original client, not the 262 262 # default client. 263 263 self.assertRedirects(response, "http://testserver/test_client_regress/get_view/") 264 265 def test_login_with_user_instance(self): 266 "Check login_user(): Log in without a password." 267 from django.contrib.auth.models import User 268 c = Client() 269 login = c.login_user(User.objects.get(username='testclient')) 270 self.failUnless(login, 'Could not log in') 271 -
django/test/client.py
3 3 from cStringIO import StringIO 4 4 from urlparse import urlparse 5 5 from django.conf import settings 6 from django.contrib.auth import authenticate, login 6 from django.contrib.auth import authenticate, login, get_backends 7 7 from django.core.handlers.base import BaseHandler 8 8 from django.core.handlers.wsgi import WSGIRequest 9 9 from django.core.signals import got_request_exception … … 245 245 not available. 246 246 """ 247 247 user = authenticate(**credentials) 248 return self.login_user(user) 249 250 def login_user(self, user): 251 if user and not hasattr(user, "backend"): 252 backend=get_backends()[0] 253 user.backend = "%s.%s" % (backend.__module__, backend.__class__.__name__) 248 254 if user and user.is_active and 'django.contrib.sessions' in settings.INSTALLED_APPS: 249 255 engine = __import__(settings.SESSION_ENGINE, {}, {}, ['']) 250 256 -
docs/testing.txt
552 552 conditions. You'll need to create users as part of the test suite -- either 553 553 manually (using the Django model API) or with a test fixture. 554 554 555 ``login_user(user)`` 556 **New in Django development version** 557 558 Like ``login()`` but you can use a user instance (without using a password):: 559 560 >>> c = Client() 561 >>> if c.login_user(User.objects.get(username='admin')): 562 >>> ... 563 555 564 ``logout()`` 556 565 **New in Django development version** 557 566