2👍
While the 302 / 301 reasoning is explained in the notes, the reason the test is failing in the first place may be because your LOGIN_URL path is missing the trailing slash:
LOGIN_URL = '/account/login/'
Without a trailing slash, django will attempt to redirect due to the default setting of APPEND_SLASH.
This will result in the test failing for the reason described.
2👍
The code for the assertRedirects
method shows that the error message:
AssertionError: 301 != 200 : Couldn't retrieve redirection page '/accounts/sign_in'
is shown after the assertion method tries to follow the initial redirect to the login page. It expects the response status code to that second call to be whatever the target_status_code
method parameter is set to (it defaults to 200
).
You can stop the assertion error by either setting the target_status_code
method parameter to 301
, or by setting the parameter fetch_redirect_response=False
which will stop the attempt to follow the initial redirect.
- [Django]-Using Django ORM inside Tornado, "syncdb" doesn't work
- [Django]-Testing django with mongoengine
- [Django]-Limiting the content of TextField in django templates