admin管理员组文章数量:1287849
How to test POST request, especially to an endpoint which checks for csrf token?
@pytest.mark.asyncio
async def test_fibonacci_pass(client):
response = await client.post('/fibonacci', data=b"n=10", follow_redirects=True)
assert response.headers['content-type'] == "text/html; charset=utf-8"
assert response != ""
assert response.status_code == HTTPStatus.OK, 'FibonacciController failed'
Snippet of controller endpoint code:
if request.method == "POST":
data = await request.get_data()
params = parse_qs(data.decode('utf-8'))
Test console output:
E AssertionError: FibonacciController failed
E assert 400 == <HTTPStatus.OK: 200>
E + where 400 = <Response [400 BAD REQUEST]>.status_code
E + and <HTTPStatus.OK: 200> = HTTPStatus.OK
test/fibonaccicontroller_test.py:16: AssertionError
------------------------------------------------------------------------------------- Captured log call --------------------------------------------------------------------------------------
INFO flask_wtf.csrf:csrf.py:263 The CSRF token is missing.
I am not suer if the AssertionError
is due to missing csrf_token
as it shows up as INFO
instead of being at least a warning.
本文标签: python pytest quart post request with csrf tokenStack Overflow
版权声明:本文标题:python pytest quart post request with csrf token - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741319189a2372105.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论