Opened 15 years ago

Closed 15 years ago

Last modified 12 years ago

#10747 closed (fixed)

django.contrib.auth logout test fails after [10332]

Reported by: Matthew Flanagan <mattimustang@…> Owned by: nobody
Component: contrib.auth Version: 1.1-beta
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The test_logout_default fails for me when I run my projects test suite. I have django.contrib.auth in my INSTALLED_APPS. The traceback is (note this is a red-herring):

======================================================================
ERROR: Logout without next_page option renders the default template
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/xxx/django/django/contrib/auth/tests/views.py", line 208, in test_logout_default
    response = self.client.get('/logout_test/')
  File "/xxx/django/django/test/client.py", line 280, in get
    response = self.request(**r)
  File "/xxx/vendor/django/django/test/client.py", line 224, in request
    response = self.handler(environ)
  File "/xxx/vendor/django/django/test/client.py", line 68, in __call__
    response = self.get_response(request)
  File "/xxx/vendor/django/django/core/handlers/base.py", line 122, in get_response
    return self.handle_uncaught_exception(request, resolver, sys.exc_info())
  File "/xxx/nong/vendor/django/django/core/handlers/base.py", line 165, in handle_uncaught_exception
    callback, param_dict = resolver.resolve500()
  File "/xxx/vendor/django/django/core/urlresolvers.py", line 229, in resolve500
    return self._resolve_special('500')
  File "/xxx/vendor/django/django/core/urlresolvers.py", line 218, in _resolve_special
    callback = getattr(self.urlconf_module, 'handler%s' % view_type)
AttributeError: 'module' object has no attribute 'handler500'

----------------------------------------------------------------------

Which template the logout view uses depends on your INSTALLED_APPS list order and whether or not you have your own registration/logged_out.html, which I do.

The traceback above is a red-herring because what is happening is that the logout view is finding my project's registration/logged_out.html template which has a few {% url ... %}'s in it but the test runner is unable to resolve all those other urls thus causing a 500 error.

After investigating I discovered two things:

  1. django.contrib.auth.urls has a ^logout/$ url regex and django.contrib.auth.tests.urls imports urlpatterns from django.contrib.auth.urls and appends to it a list of test URLs including an identical ^logout/$ regex. If you renamed the latter to ^logout_test/$ and update 2 tests to use it then you will be assured that you are testing what you intended.
  1. The test suite's ^logout_test/$ url should also define which template_name it uses so it won't try to load any old registration/logged_out.html and fail.

The patch attached fixes this.

Attachments (3)

10747.diff (2.5 KB ) - added by Matthew Flanagan <mattimustang@…> 15 years ago.
fix for logout test failing
10747v2.diff (2.5 KB ) - added by Matthew Flanagan <mattimustang@…> 15 years ago.
fix for broken diff
10747v3.diff (1.4 KB ) - added by Matthew Flanagan <mattimustang@…> 15 years ago.
real fix

Download all attachments as: .zip

Change History (6)

by Matthew Flanagan <mattimustang@…>, 15 years ago

Attachment: 10747.diff added

fix for logout test failing

by Matthew Flanagan <mattimustang@…>, 15 years ago

Attachment: 10747v2.diff added

fix for broken diff

comment:1 by Matthew Flanagan <mattimustang@…>, 15 years ago

I don't know what I was smoking when I opened this ticket but test.urls doesn't redefine /logout/ (i must have added that myself late the other night). The v3 patch attached is far better by just adding a setUp and tearDown to tweak TEMPLATE_DIRS. If I don't add this fixI still get the same traceback as I have another registration/logged_out.html elsewhere in my project.

by Matthew Flanagan <mattimustang@…>, 15 years ago

Attachment: 10747v3.diff added

real fix

comment:2 by Jacob, 15 years ago

Resolution: fixed
Status: newclosed

(In [10482]) Fixed #10747: fixed the auth tests to ignore broken user-supplied login/logout templates.

comment:3 by Jacob, 12 years ago

milestone: 1.1

Milestone 1.1 deleted

Note: See TracTickets for help on using tickets.
Back to Top