#5938: test.Client.login_user(user_instance)
-------------------------------------------------------+--------------------
Reporter: Thomas Güttler <[EMAIL PROTECTED]> | Owner:
nobody
Status: closed | Milestone:
Component: Unit test system | Version: SVN
Resolution: wontfix | Keywords:
Stage: Design decision needed | Has_patch: 1
Needs_docs: 0 | Needs_tests: 0
Needs_better_patch: 0 |
-------------------------------------------------------+--------------------
Changes (by guettli):
* cc: [EMAIL PROTECTED] (added)
Comment:
I still think this patch is useful. I have a bunch of read only tests
which I run against the production system.
And I don't want to store the password in my code.
Since I try to not modify django code I found this dirty solution:
{{{
def fake_authenticate(user):
assert isinstance(user, User), user
if not hasattr(user, "backend"):
backend=get_backends()[0]
user.backend = "%s.%s" % (backend.__module__,
backend.__class__.__name__)
return user
def client_login_user(client, user):
# Change to django code base was rejected
(http://code.djangoproject.com/ticket/5938).
# Dirty hack to login user-object without knowing his password.
# Not threadsafe.
assert isinstance(user, User), user
assert isinstance(client, Client), client
from django.test import client as client_module
orig_authenticate=client_module.authenticate
try:
client_module.authenticate=fake_authenticate
client.login(user=user)
finally:
client_module.authenticate=orig_authenticate
return user
}}}
--
Ticket URL: <http://code.djangoproject.com/ticket/5938#comment:4>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---