Ticket #16040: 16040.patch
File 16040.patch, 3.5 KB (added by , 13 years ago) |
---|
-
tests/regressiontests/test_client_regress/models.py
335 335 '/test_client_regress/no_template_view/', 301, 200) 336 336 self.assertEqual(len(response.redirect_chain), 3) 337 337 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 338 350 def test_redirect_chain_on_non_redirect_page(self): 339 351 "An assertion is raised if the original page couldn't be retrieved as expected" 340 352 # This page will redirect with code 301, not 302 -
tests/regressiontests/test_client_regress/urls.py
19 19 (r'^circular_redirect_1/$', RedirectView.as_view(url='/test_client_regress/circular_redirect_2/')), 20 20 (r'^circular_redirect_2/$', RedirectView.as_view(url='/test_client_regress/circular_redirect_3/')), 21 21 (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/')), 22 23 (r'^set_session/$', views.set_session_view), 23 24 (r'^check_session/$', views.check_session_view), 24 25 (r'^request_methods/$', views.request_methods_view), -
django/test/client.py
552 552 response.redirect_chain = [] 553 553 while response.status_code in (301, 302, 303, 307): 554 554 url = response['Location'] 555 scheme, netloc, path, query, fragment = urlsplit(url)556 557 555 redirect_chain = response.redirect_chain 558 556 redirect_chain.append((url, response.status_code)) 559 557 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) 562 565 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) 568 567 response.redirect_chain = redirect_chain 569 568 570 569 # Prevent loops