Opened 13 years ago
Closed 13 years ago
#20114 closed Bug (fixed)
Failures in tests in django.contrib.auth when using custom LOGIN_URL/LOGOUT_URL
| Reported by: | Owned by: | matiasb | |
|---|---|---|---|
| Component: | contrib.auth | Version: | 1.5 |
| Severity: | Normal | Keywords: | tests |
| Cc: | Triage Stage: | Accepted | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | yes | UI/UX: | no |
Description
My LOGIN_URL on one project is set to /accounts/signin/, and upon running tests, contrib.auth fails testLoginRequired. If I move the LOGIN_URL back to /login/ this test passes just fine. Looking at contrib.auth.tests.decorators, it appears the login_url is hard-coded to /login/ in the test suite - it does allow overriding of the login_url as a function argument, but that override isn't actually happening when the tests are run.
When I attached a debugger and ran through the tests to this point, as I predicted, I saw these two values:
response['Location'] = 'http://testserver/accounts/signin/?next=/login_required/' login_url = '/login/'
While this case would have worked if my URL was /accounts/login/, it ultimately fails as tests fail if your LOGIN_URL doesn't contain /login/, despite the documentation indicating you can use any URL you wish. These test failures are new in 1.5; all tests for contrib.auth passed just fine on the same codebase before upgrading to 1.5 from 1.4.5, so I presume this was introduced with the major overhaul of contrib.auth for 1.5.
I was able to replicate the testLoginRequired failure with a fresh Django 1.5 project using the following steps:
- Add the following URLs to project urls.py:
url(r'^signin/$', 'django.contrib.auth.views.login'), url(r'^signout/$', 'django.contrib.auth.views.logout'),
- Configure LOGIN_URL and LOGOUT_URL:
LOGIN_URL = '/signin/' LOGOUT_URL = '/signout/'
- Run tests
./manage.py test auth
Result:
$ python manage.py test auth
Creating test database for alias 'default'...
..............................................................F.................................................................................s...................................
======================================================================
FAIL: testLoginRequired (django.contrib.auth.tests.decorators.LoginRequiredTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/jriley/.virtualenvs/test/local/lib/python2.7/site-packages/django/contrib/auth/tests/decorators.py", line 37, in testLoginRequired
self.assertTrue(login_url in response['Location'])
AssertionError: False is not true
----------------------------------------------------------------------
Ran 180 tests in 8.206s
FAILED (failures=1, skipped=1)
Destroying test database for alias 'default'...
It's certainly not severe; I just switched my URLs back to /login/ and /logout/ respectively, but it would be nice to have full configurability again. :)
Thank you for taking the time to look at this!
Change History (4)
comment:1 by , 13 years ago
| Easy pickings: | set |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
comment:2 by , 13 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
comment:3 by , 13 years ago
| Has patch: | set |
|---|
Proposed pull request: https://github.com/django/django/pull/952
Tests passing with SQLite.
comment:4 by , 13 years ago
| Resolution: | → fixed |
|---|---|
| Status: | assigned → closed |
Just reproduced with 1.5 and master.