Browse Source

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.
merge-requests/126/merge
Deimos 4 years ago
parent
commit
3026d066d3
  1. 7
      tildes/tests/conftest.py

7
tildes/tests/conftest.py

@ -2,7 +2,6 @@
# SPDX-License-Identifier: AGPL-3.0-or-later # SPDX-License-Identifier: AGPL-3.0-or-later
import os import os
from http.cookiejar import CookieJar
from pyramid import testing from pyramid import testing
from pyramid.paster import get_app, get_appsettings from pyramid.paster import get_app, get_appsettings
@ -210,7 +209,7 @@ def base_app(overall_redis_session, sdb):
@fixture(scope="session") @fixture(scope="session")
def webtest(base_app): def webtest(base_app):
"""Create a webtest TestApp and log in as the SessionUser account in it.""" """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) # fetch the login page, fill in the form, and submit it (sets the cookie)
login_page = app.get("/login") login_page = app.get("/login")
@ -221,7 +220,7 @@ def webtest(base_app):
yield app yield app
@fixture(scope="session")
@fixture(scope="function")
def webtest_loggedout(base_app): 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) yield TestApp(base_app, extra_environ=WEBTEST_EXTRA_ENVIRON)
Loading…
Cancel
Save