summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2010-02-13 12:32:01 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2010-02-13 12:32:01 +0000
commitbf11ab2b212de5bfee143d6e53584434d85b32a7 (patch)
treedb75190a242656f6dd7aaca140ecd3efb1b09b9a
parent0e9f1553e1e5766559b077483ae445af11d9bb82 (diff)
[1.1.X] Fixed #12011 -- Modified the test client to preserve the request scheme on a redirect. Thanks to tgardner for the report and patch.
Backport of r12419 from trunk. git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@12421 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/test/client.py6
-rw-r--r--tests/modeltests/test_client/models.py10
-rw-r--r--tests/modeltests/test_client/urls.py3
-rw-r--r--tests/modeltests/test_client/views.py6
4 files changed, 24 insertions, 1 deletions
diff --git a/django/test/client.py b/django/test/client.py
index d56472c1ae..60dcfb4309 100644
--- a/django/test/client.py
+++ b/django/test/client.py
@@ -465,11 +465,15 @@ class Client(object):
redirect_chain = response.redirect_chain
redirect_chain.append((url, response.status_code))
+ extra = {}
+ if scheme:
+ extra['wsgi.url_scheme'] = scheme
+
# The test client doesn't handle external links,
# but since the situation is simulated in test_client,
# we fake things here by ignoring the netloc portion of the
# redirected URL.
- response = self.get(path, QueryDict(query), follow=False)
+ response = self.get(path, QueryDict(query), follow=False, **extra)
response.redirect_chain = redirect_chain
# Prevent loops
diff --git a/tests/modeltests/test_client/models.py b/tests/modeltests/test_client/models.py
index c8f1d42725..c51323d843 100644
--- a/tests/modeltests/test_client/models.py
+++ b/tests/modeltests/test_client/models.py
@@ -138,6 +138,16 @@ class ClientTest(TestCase):
self.assertRedirects(response, 'http://testserver/test_client/get_view/', status_code=302, target_status_code=200)
self.assertEquals(len(response.redirect_chain), 2)
+ def test_redirect_http(self):
+ "GET a URL that redirects to an http URI"
+ response = self.client.get('/test_client/http_redirect_view/',follow=True)
+ self.assertFalse(response.test_was_secure_request)
+
+ def test_redirect_https(self):
+ "GET a URL that redirects to an https URI"
+ response = self.client.get('/test_client/https_redirect_view/',follow=True)
+ self.assertTrue(response.test_was_secure_request)
+
def test_notfound_response(self):
"GET a URL that responds as '404:Not Found'"
response = self.client.get('/test_client/bad_view/')
diff --git a/tests/modeltests/test_client/urls.py b/tests/modeltests/test_client/urls.py
index 3c84a768a0..9e0eabe7de 100644
--- a/tests/modeltests/test_client/urls.py
+++ b/tests/modeltests/test_client/urls.py
@@ -8,8 +8,11 @@ urlpatterns = patterns('',
(r'^header_view/$', views.view_with_header),
(r'^raw_post_view/$', views.raw_post_view),
(r'^redirect_view/$', views.redirect_view),
+ (r'^secure_view/$', views.view_with_secure),
(r'^permanent_redirect_view/$', redirect_to, {'url': '/test_client/get_view/'}),
(r'^temporary_redirect_view/$', redirect_to, {'url': '/test_client/get_view/', 'permanent': False}),
+ (r'^http_redirect_view/$', redirect_to, {'url': '/test_client/secure_view/'}),
+ (r'^https_redirect_view/$', redirect_to, {'url': 'https://testserver/test_client/secure_view/'}),
(r'^double_redirect_view/$', views.double_redirect_view),
(r'^bad_view/$', views.bad_view),
(r'^form_view/$', views.form_view),
diff --git a/tests/modeltests/test_client/views.py b/tests/modeltests/test_client/views.py
index 111c72e7f5..fff19f02e6 100644
--- a/tests/modeltests/test_client/views.py
+++ b/tests/modeltests/test_client/views.py
@@ -62,6 +62,12 @@ def redirect_view(request):
query = ''
return HttpResponseRedirect('/test_client/get_view/' + query)
+def view_with_secure(request):
+ "A view that indicates if the request was secure"
+ response = HttpResponse()
+ response.test_was_secure_request = request.is_secure()
+ return response
+
def double_redirect_view(request):
"A view that redirects all requests to a redirection view"
return HttpResponseRedirect('/test_client/permanent_redirect_view/')