简体   繁体   中英

How to follow Pyramid redirect on tests?

I have a view which returns like:

headers = remember(request, str(user.id))
return HTTPFound(location=request.route_url('home'), headers=headers)

and I'm writing a test but how do I follow the redirect from the code above? I still get the HTTPFound object and also its response.request which is supposed to be the request which initiated the response is giving me None.

Here's what my test code looks so far:

request = testing.DummyRequest(
    post=MultiDict(email='me@gmail.com', password='random'))
response = login(request)

here, response is the HTTPFound but how do I follow the redirect to home?

I realize that this isn't using DummyRequest

I would recommend functional testing because WebTest makes it easier to do, and managing.

On the response that returns a redirect you can call follow to follow the full request.

http://webtest.pythonpaste.org/en/latest/index.html

redirect_response = self.testapp.post(
    '/signup', params=post_params, status=302)
full_response = redirect_response.follow()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM