Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #12011 -- Modified the test client to preserve the request sche…

…me on a redirect. Thanks to tgardner for the report and patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12419 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 79857802b8f2cd01fe469a3b2fef918d48767a92 1 parent 23d3450
Russell Keith-Magee authored February 13, 2010
6  django/test/client.py
@@ -470,11 +470,15 @@ def _handle_redirects(self, response):
470 470
             redirect_chain = response.redirect_chain
471 471
             redirect_chain.append((url, response.status_code))
472 472
 
  473
+            extra = {}
  474
+            if scheme:
  475
+                extra['wsgi.url_scheme'] = scheme
  476
+
473 477
             # The test client doesn't handle external links,
474 478
             # but since the situation is simulated in test_client,
475 479
             # we fake things here by ignoring the netloc portion of the
476 480
             # redirected URL.
477  
-            response = self.get(path, QueryDict(query), follow=False)
  481
+            response = self.get(path, QueryDict(query), follow=False, **extra)
478 482
             response.redirect_chain = redirect_chain
479 483
 
480 484
             # Prevent loops
10  tests/modeltests/test_client/models.py
@@ -138,6 +138,16 @@ def test_follow_redirect(self):
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.assertFalse(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.assertTrue(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/')
3  tests/modeltests/test_client/urls.py
@@ -8,8 +8,11 @@
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),
6  tests/modeltests/test_client/views.py
@@ -63,6 +63,12 @@ def redirect_view(request):
63 63
         query = ''
64 64
     return HttpResponseRedirect('/test_client/get_view/' + query)
65 65
 
  66
+def view_with_secure(request):
  67
+    "A view that indicates if the request was secure"
  68
+    response = HttpResponse()
  69
+    response.test_was_secure_request = request.is_secure()
  70
+    return response
  71
+
66 72
 def double_redirect_view(request):
67 73
     "A view that redirects all requests to a redirection view"
68 74
     return HttpResponseRedirect('/test_client/permanent_redirect_view/')

0 notes on commit 7985780

Please sign in to comment.
Something went wrong with that request. Please try again.