summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2007-08-31 11:37:28 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2007-08-31 11:37:28 +0000
commit5ad08583e166b63fff12fc87fa84528e946ac6ad (patch)
treec4a53942a6d6b55d85e8680c06860e134a96a699 /tests
parentd09d1428f885ce4686dfe6fc20b091f3b8e66de7 (diff)
Fixed #4968 -- Added assertRedirects handling for paths with GET data. Thanks for the patch, Ivan Sagalaev.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@6031 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
-rw-r--r--tests/modeltests/test_client/models.py11
-rw-r--r--tests/modeltests/test_client/views.py7
-rw-r--r--tests/regressiontests/test_client_regress/models.py8
3 files changed, 23 insertions, 3 deletions
diff --git a/tests/modeltests/test_client/models.py b/tests/modeltests/test_client/models.py
index e1f3987847..200a71f6f9 100644
--- a/tests/modeltests/test_client/models.py
+++ b/tests/modeltests/test_client/models.py
@@ -86,6 +86,13 @@ class ClientTest(TestCase):
# Check that the response was a 302 (redirect)
self.assertRedirects(response, '/test_client/get_view/')
+
+ def test_redirect_with_query(self):
+ "GET a URL that redirects with given GET parameters"
+ response = self.client.get('/test_client/redirect_view/', {'var': 'value'})
+
+ # Check if parameters are intact
+ self.assertRedirects(response, '/test_client/get_view/?var=value')
def test_permanent_redirect(self):
"GET a URL that redirects permanently elsewhere"
@@ -224,7 +231,7 @@ class ClientTest(TestCase):
# Get the page without logging in. Should result in 302.
response = self.client.get('/test_client/login_protected_view/')
- self.assertRedirects(response, '/accounts/login/')
+ self.assertRedirects(response, '/accounts/login/?next=/test_client/login_protected_view/')
# Log in
self.client.login(username='testclient', password='password')
@@ -261,7 +268,7 @@ class ClientTest(TestCase):
# Request a page that requires a login
response = self.client.get('/test_client/login_protected_view/')
- self.assertRedirects(response, '/accounts/login/')
+ self.assertRedirects(response, '/accounts/login/?next=/test_client/login_protected_view/')
def test_session_modifying_view(self):
"Request a page that modifies the session"
diff --git a/tests/modeltests/test_client/views.py b/tests/modeltests/test_client/views.py
index 81b4a2f283..3fc638b230 100644
--- a/tests/modeltests/test_client/views.py
+++ b/tests/modeltests/test_client/views.py
@@ -48,7 +48,12 @@ def raw_post_view(request):
def redirect_view(request):
"A view that redirects all requests to the GET view"
- return HttpResponseRedirect('/test_client/get_view/')
+ if request.GET:
+ from urllib import urlencode
+ query = '?' + urlencode(request.GET, True)
+ else:
+ query = ''
+ return HttpResponseRedirect('/test_client/get_view/' + query)
def double_redirect_view(request):
"A view that redirects all requests to a redirection view"
diff --git a/tests/regressiontests/test_client_regress/models.py b/tests/regressiontests/test_client_regress/models.py
index e17770cd03..e85544f285 100644
--- a/tests/regressiontests/test_client_regress/models.py
+++ b/tests/regressiontests/test_client_regress/models.py
@@ -112,6 +112,14 @@ class AssertRedirectsTests(TestCase):
self.assertRedirects(response, '/test_client/get_view/')
except AssertionError, e:
self.assertEquals(str(e), "Response didn't redirect as expected: Response code was 301 (expected 302)")
+
+ def test_lost_query(self):
+ "An assertion is raised if the redirect location doesn't preserve GET parameters"
+ response = self.client.get('/test_client/redirect_view/', {'var': 'value'})
+ try:
+ self.assertRedirects(response, '/test_client/get_view/')
+ except AssertionError, e:
+ self.assertEquals(str(e), "Response redirected to '/test_client/get_view/?var=value', expected '/test_client/get_view/'")
def test_incorrect_target(self):
"An assertion is raised if the response redirects to another target"