Ticket #11223: views_with_tests.diff

File views_with_tests.diff, 2.6 KB (added by Brandon M Height, 14 years ago)

Patch w/ Tests

  • django/contrib/auth/tests/views.py

    diff --git a/django/contrib/auth/tests/views.py b/django/contrib/auth/tests/views.py
    index 530956a..836d912 100644
    a b class LogoutTest(AuthViewsTestCase):  
    333333        response = self.client.get('/logout/')
    334334        self.assertTrue('site' in response.context)
    335335
     336    def test_11223(self):
     337        # Bug 11223
     338        self.login()
     339        response = self.client.get('/logout/next_page/')
     340        self.assertEqual(response.status_code, 302)
     341        self.assert_(response['Location'].endswith('/somewhere/'))
     342
     343        response = self.client.get('/logout/?next=/login/')
     344        self.assertEqual(response.status_code, 302)
     345        self.assert_(response['Location'].endswith('/login/'))
     346       
     347        self.confirm_logged_out()
     348
    336349    def test_logout_with_next_page_specified(self):
    337350        "Logout with next_page option given redirects to specified resource"
    338351        self.login()
  • django/contrib/auth/views.py

    diff --git a/django/contrib/auth/views.py b/django/contrib/auth/views.py
    index c34a4a3..19edb70 100644
    a b def logout(request, next_page=None,  
    7474    "Logs out the user and displays 'You are logged out' message."
    7575    from django.contrib.auth import logout
    7676    logout(request)
     77    redirect_to = request.REQUEST.get(redirect_field_name, '')
     78    if redirect_to:
     79        return HttpResponseRedirect(redirect_to)
     80
    7781    if next_page is None:
    78         redirect_to = request.REQUEST.get(redirect_field_name, '')
    79         if redirect_to:
    80             return HttpResponseRedirect(redirect_to)
    81         else:
    82             current_site = get_current_site(request)
    83             context = {
    84                 'site': current_site,
    85                 'site_name': current_site.name,
    86                 'title': _('Logged out')
    87             }
    88             context.update(extra_context or {})
    89             return render_to_response(template_name, context,
    90                                       context_instance=RequestContext(request, current_app=current_app))
     82        current_site = get_current_site(request)
     83        context = {
     84            'site': current_site,
     85            'site_name': current_site.name,
     86            'title': _('Logged out')
     87        }
     88        context.update(extra_context or {})
     89        return render_to_response(template_name, context,
     90                                  context_instance=RequestContext(request, current_app=current_app))
    9191    else:
    9292        # Redirect to this page until the session has been cleared.
    9393        return HttpResponseRedirect(next_page or request.path)
Back to Top