#20114: Failures in tests in django.contrib.auth when using custom LOGIN_URL/LOGOUT_URL ------------------------------+-------------------- Reporter: jriley@… | Owner: nobody Type: Bug | Status: new Component: contrib.auth | Version: 1.5 Severity: Normal | Keywords: tests Triage Stage: Unreviewed | Has patch: 0 Easy pickings: 0 | UI/UX: 0 ------------------------------+-------------------- 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! -- Ticket URL: <https://code.djangoproject.com/ticket/20114> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.