test.Client problems logging in (now fixed)
If you’re creating a test user for a unit test, do it this way:
newuser=User.objects.create_user('john', '[email protected]', 'johnpassword')
rather than this:
newuser=User(username="john",email="[email protected]",password="johnpassword")
The latter looks correct, but you’ll get problems logging in since Django stores the hash of the password in the db, not the clear text.
Another gotcha is that the client.login() function only works with pages where you can’t get at them until you have logged in - if the page is available to AnonymousUser, then login() will always fail.