﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
20114	Failures in tests in django.contrib.auth when using custom LOGIN_URL/LOGOUT_URL	jriley@…	matiasb	"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:

1. Add the following URLs to project urls.py:
{{{
url(r'^signin/$', 'django.contrib.auth.views.login'),
url(r'^signout/$', 'django.contrib.auth.views.logout'),
}}}
2. Configure LOGIN_URL and LOGOUT_URL:
{{{
LOGIN_URL = '/signin/'
LOGOUT_URL = '/signout/'
}}}
3. 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!"	Bug	closed	contrib.auth	1.5	Normal	fixed	tests		Accepted	1	0	0	0	1	0
