Commit 3026d066 authored by Deimos's avatar Deimos

Set function scope for logged-out webtest fixture

I mistakenly assumed that not setting the cookiejar argument when
creating a webtest TestApp would mean that no cookies would be retained
between requests, but that's wrong. If you don't pass a cookiejar, it
just automatically creates one for you. Because of this, logged-out
webtests would end up being logged-in after any test logged in.

This reduces the webtest_loggedout fixture's scope to function-level so
that it will be re-initiated on every test instead. It also stops
passing a cookiejar for the logged-in webtest, since that's unnecessary.
parent 6f272fcd
......@@ -2,7 +2,6 @@
# SPDX-License-Identifier: AGPL-3.0-or-later
import os
from http.cookiejar import CookieJar
from pyramid import testing
from pyramid.paster import get_app, get_appsettings
......@@ -210,7 +209,7 @@ def base_app(overall_redis_session, sdb):
@fixture(scope="session")
def webtest(base_app):
"""Create a webtest TestApp and log in as the SessionUser account in it."""
app = TestApp(base_app, extra_environ=WEBTEST_EXTRA_ENVIRON, cookiejar=CookieJar())
app = TestApp(base_app, extra_environ=WEBTEST_EXTRA_ENVIRON)
# fetch the login page, fill in the form, and submit it (sets the cookie)
login_page = app.get("/login")
......@@ -221,7 +220,7 @@ def webtest(base_app):
yield app
@fixture(scope="session")
@fixture(scope="function")
def webtest_loggedout(base_app):
"""Create a logged-out webtest TestApp (no cookies retained)."""
"""Create a logged-out webtest TestApp (function scope, so no state is retained)."""
yield TestApp(base_app, extra_environ=WEBTEST_EXTRA_ENVIRON)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment