Simple login is not working

Issue #6 resolved
Anonymous created an issue

I am trying to use this plugin to do my test with however the simple login example shown isn't working. I am using version 1.3 of the plugin, and django 1.2.4 Here is the test

class accountViewsTestCase(WebTest): fixtures = ['test_user_data.json']

def test_login(self):
    '''used to test the login form'''

    #sanity check to make sure the data loaded
    user = User.objects.get(username="testUser")
    self.assertEqual(user.username, 'testUser')
    self.assertTrue(user.check_password('password'))

    #login to the form
    form = self.app.get(reverse('auth_login')).forms[1]
    form['username'] = 'testUser'
    form['password'] = 'password'
    resp = form.submit()
    print resp

The resp sent back is the form faling validation because the password is not valid. However if I do self.client.login(username='testUser', password='password') it comes back true. I also am successful using the plugin from the shell

This works

from django_webtest import DjangoTestApp t = DjangoTestApp() form = t.get('http://localhost:8000/accounts/login/').forms[1] form['username']='testUser' form['password']='password' resp = form.submit() resp <302 FOUND text/html location: http://localhost:8000/recipe/ no body>

I got the 302 redirection which is what I expect.

Comments (6)

  1. Anonymous

    Sorry the code came out funny so pasting again

    class accountViewsTestCase(WebTest):
        fixtures = ['test_user_data.json']
    
        def test_login(self):
            '''used to test the login form'''
    
            #sanity check to make sure the data loaded
            user = User.objects.get(username="testUser")
            self.assertEqual(user.username, 'testUser')
            self.assertTrue(user.check_password('password'))
            
            #login to the form
            form = self.app.get(reverse('auth_login')).forms[1]
            form['username'] = 'testUser'
            form['password'] = 'password'
            resp = form.submit()
            print resp
    

    This works on the shell

    >>> t = DjangoTestApp()
    >>> form = t.get('http://localhost:8000/accounts/login/').forms[1]
    >>> form['username']='testUser'
    >>> form['password']='password'
    >>> resp = form.submit()
    >>> resp
    <302 FOUND text/html location: http://localhost:8000/recipe/ no body>
    
  2. Mikhail Korobov repo owner

    There is some bad magic in a way auth is handled, and this needs to be fixed.

    The workaround is to use setup_auth = False:

    class AccountViewsTestCase(WebTest):
        setup_auth = False
        fixtures = ['test_user_data.json']
    
        def test_login(self):
            # ...
    
  3. Log in to comment