Ticket #24276: 24276-test.diff

File 24276-test.diff, 2.9 KB (added by Tim Graham, 10 years ago)
  • django/contrib/auth/decorators.py

    diff --git a/django/contrib/auth/decorators.py b/django/contrib/auth/decorators.py
    index 9b2504b..dbc10ab 100644
    a b def user_passes_test(test_func, login_url=None, redirect_field_name=REDIRECT_FIE  
    2121            if test_func(request.user):
    2222                return view_func(request, *args, **kwargs)
    2323            path = request.build_absolute_uri()
    24             resolved_login_url = resolve_url(login_url or settings.LOGIN_URL)
     24            resolved_login_url = resolve_url(login_url or settings.LOGIN_URL, *args, **kwargs)
    2525            # If the login url is the same scheme and net location then just
    2626            # use the path as the "next" url.
    2727            login_scheme, login_netloc = urlparse(resolved_login_url)[:2]
  • tests/urlpatterns_reverse/reverse_lazy_urls.py

    diff --git a/tests/urlpatterns_reverse/reverse_lazy_urls.py b/tests/urlpatterns_reverse/reverse_lazy_urls.py
    index 694b23f..8ab7f97 100644
    a b from .views import LazyRedirectView, empty_view, login_required_view  
    55urlpatterns = [
    66    url(r'^redirected_to/$', empty_view, name='named-lazy-url-redirected-to'),
    77    url(r'^login/$', empty_view, name='some-login-page'),
    8     url(r'^login_required_view/$', login_required_view),
     8    url(r'^(\d{4})/login_required_view/$', login_required_view),
    99    url(r'^redirect/$', LazyRedirectView.as_view()),
    1010]
  • tests/urlpatterns_reverse/tests.py

    diff --git a/tests/urlpatterns_reverse/tests.py b/tests/urlpatterns_reverse/tests.py
    index f7f8fcc..ea76258 100644
    a b class ReverseLazyTest(TestCase):  
    317317
    318318    def test_user_permission_with_lazy_reverse(self):
    319319        User.objects.create_user('alfred', 'alfred@example.com', password='testpw')
    320         response = self.client.get('/login_required_view/')
    321         self.assertRedirects(response, "/login/?next=/login_required_view/", status_code=302)
     320        response = self.client.get('/1986/login_required_view/')
     321        self.assertRedirects(response, "/login/?next=/1986/login_required_view/", status_code=302)
    322322        self.client.login(username='alfred', password='testpw')
    323323        response = self.client.get('/login_required_view/')
    324324        self.assertEqual(response.status_code, 200)
  • tests/urlpatterns_reverse/views.py

    diff --git a/tests/urlpatterns_reverse/views.py b/tests/urlpatterns_reverse/views.py
    index 9fd2ad1..e0a04ef 100644
    a b class LazyRedirectView(RedirectView):  
    4949    url = reverse_lazy('named-lazy-url-redirected-to')
    5050
    5151
    52 @user_passes_test(lambda u: u.is_authenticated(), login_url=reverse_lazy('some-login-page'))
     52@user_passes_test(lambda u: u.is_authenticated(), login_url='some-login-page')
    5353def login_required_view(request):
    5454    return HttpResponse('Hello you')
    5555
Back to Top