Ticket #12011: test_client_redirect_scheme.diff
File test_client_redirect_scheme.diff, 3.5 KB (added by , 15 years ago) |
---|
-
django/test/client.py
459 459 redirect_chain = response.redirect_chain 460 460 redirect_chain.append((url, response.status_code)) 461 461 462 extra = {} 463 if scheme: 464 extra['wsgi.url_scheme'] = scheme 465 462 466 # The test client doesn't handle external links, 463 467 # but since the situation is simulated in test_client, 464 468 # we fake things here by ignoring the netloc portion of the 465 469 # redirected URL. 466 response = self.get(path, QueryDict(query), follow=False )470 response = self.get(path, QueryDict(query), follow=False, **extra) 467 471 response.redirect_chain = redirect_chain 468 472 469 473 # Prevent loops -
tests/modeltests/test_client/views.py
62 62 query = '' 63 63 return HttpResponseRedirect('/test_client/get_view/' + query) 64 64 65 def view_with_secure(request): 66 "A view that indicates if the request was secure" 67 response = HttpResponse() 68 response.test_was_secure_request = request.is_secure() 69 return response 70 65 71 def double_redirect_view(request): 66 72 "A view that redirects all requests to a redirection view" 67 73 return HttpResponseRedirect('/test_client/permanent_redirect_view/') -
tests/modeltests/test_client/models.py
138 138 self.assertRedirects(response, 'http://testserver/test_client/get_view/', status_code=302, target_status_code=200) 139 139 self.assertEquals(len(response.redirect_chain), 2) 140 140 141 def test_redirect_http(self): 142 "GET a URL that redirects to an http URI" 143 response = self.client.get('/test_client/http_redirect_view/',follow=True) 144 self.assert_(not response.test_was_secure_request) 145 146 def test_redirect_https(self): 147 "GET a URL that redirects to an https URI" 148 response = self.client.get('/test_client/https_redirect_view/',follow=True) 149 self.assert_(response.test_was_secure_request) 150 141 151 def test_notfound_response(self): 142 152 "GET a URL that responds as '404:Not Found'" 143 153 response = self.client.get('/test_client/bad_view/') -
tests/modeltests/test_client/urls.py
8 8 (r'^header_view/$', views.view_with_header), 9 9 (r'^raw_post_view/$', views.raw_post_view), 10 10 (r'^redirect_view/$', views.redirect_view), 11 (r'^secure_view/$', views.view_with_secure), 11 12 (r'^permanent_redirect_view/$', redirect_to, {'url': '/test_client/get_view/'}), 12 13 (r'^temporary_redirect_view/$', redirect_to, {'url': '/test_client/get_view/', 'permanent': False}), 14 (r'^http_redirect_view/$', redirect_to, {'url': '/test_client/secure_view/'}), 15 (r'^https_redirect_view/$', redirect_to, {'url': 'https://testserver/test_client/secure_view/'}), 13 16 (r'^double_redirect_view/$', views.double_redirect_view), 14 17 (r'^bad_view/$', views.bad_view), 15 18 (r'^form_view/$', views.form_view),