There are a few things which are confusing me here:1. I can remove get_cookie and get_csrf_token and just hard-code 'dummy_csrf_token' into login / post(), and it still works. Am I missing something here?
2. I don't get all the CSRF behaviour here. Isn't it generated on the server side and webtest is client side only? How can it make Pyramid accept a "dummy_csrf_token" as a CSRF token? Is there some magic in CookieCSRFStoragePolicy or WebTest?
3. Do I understand right that using CookieCSRFStoragePolicy is required for webtest CSRF to work?
On 9 Feb 2021, at 1:38, zsol...@gmail.com wrote:
I'd like to use webtest to test my application's responses with an
authenticated user. I tried everything with mocking, monkeypatch, etc. but
couldn't figure out. I see that there is testing_securitypolicy but I have
no idea how could I integrate it with webtest.
Kotti’s test suite uses a pytest marker for running tests with an authenticated user. The webtest fixture monkey patches pyramid.authentication.AuthTktAuthenticationPolicy.unauthenticated_userid (https://github.com/Kotti/Kotti/blob/master/kotti/tests/__init__.py#L296). It can be used like this: https://github.com/Kotti/Kotti/blob/master/kotti/tests/test_functional.py#L218.
HTH,
Andreas