From ea25ec5cd5715ab3dcf266a968166425e279927a Mon Sep 17 00:00:00 2001 From: Theron Luhn Date: Fri, 11 Dec 2020 09:22:15 -0800 Subject: Revert "Remove `app_request` from wiki2 tests." This reverts commit 86cb46d4d977d3a948308326bee628421cab93ea. --- .../wiki2/src/authentication/tests/conftest.py | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'docs/tutorials/wiki2/src/authentication') diff --git a/docs/tutorials/wiki2/src/authentication/tests/conftest.py b/docs/tutorials/wiki2/src/authentication/tests/conftest.py index 57e86ac1c..347180600 100644 --- a/docs/tutorials/wiki2/src/authentication/tests/conftest.py +++ b/docs/tutorials/wiki2/src/authentication/tests/conftest.py @@ -3,6 +3,7 @@ import alembic.config import alembic.command import os from pyramid.paster import get_appsettings +from pyramid.scripting import prepare from pyramid.testing import DummyRequest, testConfig import pytest import transaction @@ -79,6 +80,28 @@ def testapp(app, tm, dbsession): return testapp +@pytest.fixture +def app_request(app, tm, dbsession): + """ + A real request. + + This request is almost identical to a real request but it has some + drawbacks in tests as it's harder to mock data and is heavier. + + """ + env = prepare(registry=app.registry) + request = env['request'] + request.host = 'example.com' + + # without this, request.dbsession will be joined to the same transaction + # manager but it will be using a different sqlalchemy.orm.Session using + # a separate database transaction + request.dbsession = dbsession + request.tm = tm + + yield request + env['closer']() + @pytest.fixture def dummy_request(tm, dbsession): """ -- cgit v1.2.3