Ticket #16040: 16040.patch

File 16040.patch, 3.5 KB (added by Aymeric Augustin, 13 years ago)
  • tests/regressiontests/test_client_regress/models.py

     
    335335            '/test_client_regress/no_template_view/', 301, 200)
    336336        self.assertEqual(len(response.redirect_chain), 3)
    337337
     338    def test_redirect_to_different_host(self):
     339        "The test client will preserve scheme, host and port changes"
     340        response = self.client.get('/test_client_regress/redirect_other_host/', follow=True)
     341        self.assertRedirects(response,
     342            'https://otherserver:8443/test_client_regress/no_template_view/',
     343            status_code=301, target_status_code=200)
     344        # can't user is_secure() or get_host() because response.request is a
     345        # dictionary, not an HttpRequest
     346        self.assertEqual(response.request.get('wsgi.url_scheme'), 'https')
     347        self.assertEqual(response.request.get('SERVER_NAME'), 'otherserver')
     348        self.assertEqual(response.request.get('SERVER_PORT'), '8443')
     349
    338350    def test_redirect_chain_on_non_redirect_page(self):
    339351        "An assertion is raised if the original page couldn't be retrieved as expected"
    340352        # This page will redirect with code 301, not 302
  • tests/regressiontests/test_client_regress/urls.py

     
    1919    (r'^circular_redirect_1/$', RedirectView.as_view(url='/test_client_regress/circular_redirect_2/')),
    2020    (r'^circular_redirect_2/$', RedirectView.as_view(url='/test_client_regress/circular_redirect_3/')),
    2121    (r'^circular_redirect_3/$', RedirectView.as_view(url='/test_client_regress/circular_redirect_1/')),
     22    (r'^redirect_other_host/$', RedirectView.as_view(url='https://otherserver:8443/test_client_regress/no_template_view/')),
    2223    (r'^set_session/$', views.set_session_view),
    2324    (r'^check_session/$', views.check_session_view),
    2425    (r'^request_methods/$', views.request_methods_view),
  • django/test/client.py

     
    552552        response.redirect_chain = []
    553553        while response.status_code in (301, 302, 303, 307):
    554554            url = response['Location']
    555             scheme, netloc, path, query, fragment = urlsplit(url)
    556 
    557555            redirect_chain = response.redirect_chain
    558556            redirect_chain.append((url, response.status_code))
    559557
    560             if scheme:
    561                 extra['wsgi.url_scheme'] = scheme
     558            url = urlsplit(url)
     559            if url.scheme:
     560                extra['wsgi.url_scheme'] = url.scheme
     561            if url.hostname:
     562                extra['SERVER_NAME'] = url.hostname
     563            if url.port:
     564                extra['SERVER_PORT'] = str(url.port)
    562565
    563             # The test client doesn't handle external links,
    564             # but since the situation is simulated in test_client,
    565             # we fake things here by ignoring the netloc portion of the
    566             # redirected URL.
    567             response = self.get(path, QueryDict(query), follow=False, **extra)
     566            response = self.get(url.path, QueryDict(url.query), follow=False, **extra)
    568567            response.redirect_chain = redirect_chain
    569568
    570569            # Prevent loops
Back to Top