From f3c054d13d29a4065ff8b26d7b8ea900f8aa3d69 Mon Sep 17 00:00:00 2001 From: Christoph Ladurner Date: Wed, 4 Dec 2024 22:07:44 +0100 Subject: [PATCH] fix: cookie_app and users not using same app * the problem is since cookie_app and users use different app one closes the connection to the database first which is bad --- tests/conftest.py | 17 +++-------------- tests/test_invenio_accounts.py | 4 ++-- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 93b62aee..633273f8 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -119,6 +119,8 @@ def _app_factory(config=None): ACCOUNTS_SETTINGS_TEMPLATE="invenio_accounts/settings/base.html", ACCOUNTS_COVER_TEMPLATE="invenio_accounts/base_cover.html", WEBPACKEXT_MANIFEST_LOADER=MockManifestLoader, + SESSION_COOKIE_SECURE=True, + SESSION_COOKIE_DOMAIN="example.com", ) app.config.update(config or {}) @@ -213,6 +215,7 @@ def api(request): ), SERVER_NAME="localhost", TESTING=True, + SESSION_COOKIE_DOMAIN="localhost", ) ) @@ -277,20 +280,6 @@ def task_app(request): return app -@pytest.fixture -def cookie_app(request): - """Flask application enabled.""" - app = _app_factory( - dict( - SESSION_COOKIE_SECURE=True, - SESSION_COOKIE_DOMAIN="example.com", - ) - ) - InvenioAccounts(app) - _database_setup(app, request) - return app - - @pytest.fixture def admin_view(app): """Admin view fixture.""" diff --git a/tests/test_invenio_accounts.py b/tests/test_invenio_accounts.py index 40dcb20d..057c4313 100644 --- a/tests/test_invenio_accounts.py +++ b/tests/test_invenio_accounts.py @@ -222,11 +222,11 @@ def test_configuration(base_app): assert "deadbeef" == app.config["ACCOUNTS_USE_CELERY"] -def test_cookies(cookie_app, users): +def test_cookies(app, users): """Test cookies set on login.""" u = users[0] - with cookie_app.test_client() as client: + with app.test_client() as client: res = client.post( url_for_security("login"), data=dict(email=u["email"], password=u["password"], remember=True),