gpt4 book ai didi

python - 如何在测试中遵循 Pyramid 重定向?

转载 作者:太空宇宙 更新时间:2023-11-03 15:23:39 26 4
gpt4 key购买 nike

我有一个返回如下的 View :

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

我正在编写测试,但我如何遵循上面代码的重定向?我仍然得到 HTTPFound 对象及其 response.request,它应该是发起响应的请求,但没有给我。

到目前为止,这是我的测试代码:

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

在这里,响应是 HTTPFound 但我如何按照重定向到主页?

最佳答案

我意识到这不是使用 DummyRequest

我会推荐功能测试,因为 WebTest 使它更容易执行和管理。

在返回重定向的响应中,您可以调用 follow 来跟随完整请求。

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

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

关于python - 如何在测试中遵循 Pyramid 重定向?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10773404/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com