summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorGael Pasgrimaud <gael@gawel.org>2013-03-27 17:18:07 +0100
committerGael Pasgrimaud <gael@gawel.org>2013-03-27 17:18:07 +0100
commitd7839348731cefe3f987e0133ad334944983600c (patch)
tree0c9d129ba22f937d395d397101bf397e889e4e68 /tests
parent8acac261c6f482f1f93e1df6b7859cc513609eac (diff)
parent744f2828377c258f694cf1a359662e965525a6b9 (diff)
downloadwebtest-d7839348731cefe3f987e0133ad334944983600c.tar.gz
merge. fixed #59
Diffstat (limited to 'tests')
-rw-r--r--tests/test_response.py18
1 files changed, 16 insertions, 2 deletions
diff --git a/tests/test_response.py b/tests/test_response.py
index c2d26b7..8579afd 100644
--- a/tests/test_response.py
+++ b/tests/test_response.py
@@ -350,10 +350,12 @@ class TestResponse(unittest.TestCase):
class TestFollow(unittest.TestCase):
- def get_redirects_app(self, count=1):
+ def get_redirects_app(self, count=1, locations=None):
"""Return an app that issues a redirect ``count`` times"""
remaining_redirects = [count] # this means "nonlocal"
+ if locations is None:
+ locations = ['/'] * count
def app(environ, start_response):
headers = [('Content-Type', str('text/html'))]
@@ -364,7 +366,8 @@ class TestFollow(unittest.TestCase):
else:
status = "302 Found"
body = b''
- headers.append(('location', str('/')))
+ nextloc = str(locations.pop(0))
+ headers.append(('location', nextloc))
remaining_redirects[0] -= 1
headers.append(('Content-Length', str(len(body))))
@@ -393,6 +396,17 @@ class TestFollow(unittest.TestCase):
# can't follow non-redirect
self.assertRaises(AssertionError, resp.follow)
+ def test_follow_relative(self):
+ app = self.get_redirects_app(2, ['hello/foo/', 'bar'])
+ resp = app.get('/')
+ self.assertEqual(resp.status_int, 302)
+ resp = resp.follow()
+ self.assertEqual(resp.status_int, 302)
+ resp = resp.follow()
+ self.assertEqual(resp.body, b'done')
+ self.assertEqual(resp.request.url, 'http://localhost/hello/foo/bar')
+
+
def test_follow_twice(self):
app = self.get_redirects_app(2)
resp = app.get('/').follow()