def test_follow_redirect(self):
env = create_environ('/', base_url='http://localhost')
c = Client(redirect_with_get_app)
appiter, code, headers = c.open(environ_overrides=env, follow_redirects=True)
self.assert_strict_equal(code, '200 OK')
self.assert_strict_equal(b''.join(appiter), b'current url: http://localhost/some/redirect/')
# Test that the :cls:`Client` is aware of user defined response wrappers
c = Client(redirect_with_get_app, response_wrapper=BaseResponse)
resp = c.get('/', follow_redirects=True)
self.assert_strict_equal(resp.status_code, 200)
self.assert_strict_equal(resp.data, b'current url: http://localhost/some/redirect/')
# test with URL other than '/' to make sure redirected URL's are correct
c = Client(redirect_with_get_app, response_wrapper=BaseResponse)
resp = c.get('/first/request', follow_redirects=True)
self.assert_strict_equal(resp.status_code, 200)
self.assert_strict_equal(resp.data, b'current url: http://localhost/some/redirect/')
评论列表
文章目录