summaryrefslogtreecommitdiff
path: root/tests/modeltests
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2009-02-27 13:14:59 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2009-02-27 13:14:59 +0000
commite735fe7160d786efeb2e8bea595174c1a68409a2 (patch)
tree006d378625943718f66d6c3791c7401a345378ce /tests/modeltests
parente20f09c2d047d782b4b471b2e8cf4a910b338db6 (diff)
Fixed #4476 -- Added a ``follow`` option to the test client request methods. This implements browser-like behavior for the test client, following redirect chains when a 30X response is received. Thanks to Marc Fargas and Keith Bussell for their work on this.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@9911 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/modeltests')
-rw-r--r--tests/modeltests/test_client/models.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/tests/modeltests/test_client/models.py b/tests/modeltests/test_client/models.py
index b975d139c6..dfc84169f3 100644
--- a/tests/modeltests/test_client/models.py
+++ b/tests/modeltests/test_client/models.py
@@ -70,13 +70,13 @@ class ClientTest(TestCase):
self.assertEqual(response.context['data'], '37')
self.assertEqual(response.template.name, 'POST Template')
self.failUnless('Data received' in response.content)
-
+
def test_response_headers(self):
"Check the value of HTTP headers returned in a response"
response = self.client.get("/test_client/header_view/")
-
+
self.assertEquals(response['X-DJANGO-TEST'], 'Slartibartfast')
-
+
def test_raw_post(self):
"POST raw data (with a content type) to a view"
test_doc = """<?xml version="1.0" encoding="utf-8"?><library><book><title>Blink</title><author>Malcolm Gladwell</author></book></library>"""
@@ -132,6 +132,12 @@ class ClientTest(TestCase):
# the attempt to get the redirection location returned 301 when retrieved
self.assertRedirects(response, 'http://testserver/test_client/permanent_redirect_view/', target_status_code=301)
+ def test_follow_redirect(self):
+ "A URL that redirects can be followed to termination."
+ response = self.client.get('/test_client/double_redirect_view/', follow=True)
+ 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_notfound_response(self):
"GET a URL that responds as '404:Not Found'"
response = self.client.get('/test_client/bad_view/')