Tuesday, March 27, 2012

TestCase Client.login() fails

I'm trying to write a unit test that will verify that the login form authenticates a user. Whenever I run 'manage.py test' the runner fails with this message:
AssertionError: False is not True

tests.py
from django.test import TestCase
from django.test.client import Client
from django.contrib.auth.models import User

class TestAccountLogin(TestCase):
    def setUp(self):
        self.client = Client()

    def test_login(self):
        user = User.objects.create_user('test', 'test@test.com', 't3stp@s$')
        response = self.client.login(username=user.username, password=user.password)
        self.assertTrue(response)

After creating the user, I can verify that user.is_active is in fact True, but unfortunately response returns False. Both 'django.contrib.auth.middleware.AuthenticationMiddleware' and 'django.contrib.auth' are declared in settings.py.

Any thoughts?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/5zI85qKS4acJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment