mardi 30 avril 2019

Testing if user is not login, redirect to login page

Just testing if my application will redirect to the login page if the user is not logged in. The url /confirmation/TEST01 where TEST01 is a reverse url. It should redirect to /accounts/login/?next=/confirmation/TEST01

But I am getting an error:

AssertionError: 404 != 302 : Response didn't redirect as expected: Response code was 404 (expected 302)

Test.py

def test_redirect_to_login(self):
    response = self.client.get('/confirmation/TEST01/')
    self.assertRedirects(response, '/accounts/login/?next=/confirmation/TEST01', status_code=302, target_status_code=404, fetch_redirect_response=True)

Terminal

[30/Apr/2019 08:45:01] "GET /confirmation/XZC456 HTTP/1.1" 302 0
Not Found: /accounts/login/
[30/Apr/2019 08:45:01] "GET /accounts/login/?next=/confirmation/XZC456 HTTP/1.1" 404 2386

Aucun commentaire:

Enregistrer un commentaire