On Oct 23, 4:16 pm, Ralph <ttx...@googlemail.com> wrote: > I am using Django 1.1 with Python 2.6.1 and have a problem with > testing > views that require a login. I was hoping someone could enlighten me > were > it all goes wrong.... > > in the setup function of a unit test i am adding a user and create a > test client > > User.objects.create(username='myuser', password='mypassword') > self.client = Client() > > but get an AssertionError when i do this > self.assertEquals(self.client.login > (username='myuser',password='mypassword'), True) > as the login fails. > > The User class in django.auth.models in > the check_password method returns False. In line 182 > > is_correct = (self.password == get_hexdigest('md5', '', raw_password)) > > self.password is at this stage "mypassword" and will be > compared to a hexdigest so that the comparison will return False. > Authentification > works fine outside the tests. Is there anything in the settings > that I need to adjust to get this to work? Thanks
Look at the documentation for authentication - don't use User.objects.create() but User.objects.create_user(), as this takes care of hashing the password. -- DR. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---