[Fixed]-Wrong Behaviour doing tests on Django

1👍

The remote authentication url expects the credentials as headers, but your local login view expects them as POST data. Your test passes the credentials as headers to your local view.

As a result, the form is passed an empty dictionary (request.POST contains no actual data), and the form is invalid. You get an empty form as a response, without any redirects.

You have to simply pass the credentials as post data to your local view:

def testLogin(self):
    client = Client()
    data = {'username': 'user', 'password': 'password'}
    response = self.client.post('/login/', data=data, secure=True, follow=True)
    assert (response.status_code == 200)
    self.assertRedirects(response, '/menu/', status_code=301, target_status_code=200)
👤knbk

Leave a comment