diff options
| author | Theron Luhn <theron@luhn.com> | 2020-12-11 09:22:15 -0800 |
|---|---|---|
| committer | Theron Luhn <theron@luhn.com> | 2020-12-11 09:22:15 -0800 |
| commit | ea25ec5cd5715ab3dcf266a968166425e279927a (patch) | |
| tree | fc288c38e1fdad9605926f0b5f79f045d5b794b0 /docs/tutorials | |
| parent | 43bd1a16de441d971bb6e1f3f6dbae055394e324 (diff) | |
| download | pyramid-ea25ec5cd5715ab3dcf266a968166425e279927a.tar.gz pyramid-ea25ec5cd5715ab3dcf266a968166425e279927a.tar.bz2 pyramid-ea25ec5cd5715ab3dcf266a968166425e279927a.zip | |
Revert "Remove `app_request` from wiki2 tests."
This reverts commit 86cb46d4d977d3a948308326bee628421cab93ea.
Diffstat (limited to 'docs/tutorials')
| -rw-r--r-- | docs/tutorials/wiki2/src/authentication/tests/conftest.py | 23 | ||||
| -rw-r--r-- | docs/tutorials/wiki2/src/authorization/tests/conftest.py | 23 | ||||
| -rw-r--r-- | docs/tutorials/wiki2/src/basiclayout/tests/conftest.py | 23 | ||||
| -rw-r--r-- | docs/tutorials/wiki2/src/installation/tests/conftest.py | 23 | ||||
| -rw-r--r-- | docs/tutorials/wiki2/src/models/tests/conftest.py | 23 | ||||
| -rw-r--r-- | docs/tutorials/wiki2/src/tests/tests/conftest.py | 23 | ||||
| -rw-r--r-- | docs/tutorials/wiki2/src/views/tests/conftest.py | 23 | ||||
| -rw-r--r-- | docs/tutorials/wiki2/tests.rst | 3 |
8 files changed, 164 insertions, 0 deletions
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 @@ -80,6 +81,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): """ A lightweight dummy request. diff --git a/docs/tutorials/wiki2/src/authorization/tests/conftest.py b/docs/tutorials/wiki2/src/authorization/tests/conftest.py index 57e86ac1c..347180600 100644 --- a/docs/tutorials/wiki2/src/authorization/tests/conftest.py +++ b/docs/tutorials/wiki2/src/authorization/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 @@ -80,6 +81,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): """ A lightweight dummy request. diff --git a/docs/tutorials/wiki2/src/basiclayout/tests/conftest.py b/docs/tutorials/wiki2/src/basiclayout/tests/conftest.py index 57e86ac1c..347180600 100644 --- a/docs/tutorials/wiki2/src/basiclayout/tests/conftest.py +++ b/docs/tutorials/wiki2/src/basiclayout/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 @@ -80,6 +81,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): """ A lightweight dummy request. diff --git a/docs/tutorials/wiki2/src/installation/tests/conftest.py b/docs/tutorials/wiki2/src/installation/tests/conftest.py index 57e86ac1c..347180600 100644 --- a/docs/tutorials/wiki2/src/installation/tests/conftest.py +++ b/docs/tutorials/wiki2/src/installation/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 @@ -80,6 +81,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): """ A lightweight dummy request. diff --git a/docs/tutorials/wiki2/src/models/tests/conftest.py b/docs/tutorials/wiki2/src/models/tests/conftest.py index 57e86ac1c..347180600 100644 --- a/docs/tutorials/wiki2/src/models/tests/conftest.py +++ b/docs/tutorials/wiki2/src/models/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 @@ -80,6 +81,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): """ A lightweight dummy request. diff --git a/docs/tutorials/wiki2/src/tests/tests/conftest.py b/docs/tutorials/wiki2/src/tests/tests/conftest.py index 651643e8c..45d33bb92 100644 --- a/docs/tutorials/wiki2/src/tests/tests/conftest.py +++ b/docs/tutorials/wiki2/src/tests/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 @@ -121,6 +122,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): """ A lightweight dummy request. diff --git a/docs/tutorials/wiki2/src/views/tests/conftest.py b/docs/tutorials/wiki2/src/views/tests/conftest.py index 57e86ac1c..347180600 100644 --- a/docs/tutorials/wiki2/src/views/tests/conftest.py +++ b/docs/tutorials/wiki2/src/views/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 @@ -80,6 +81,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): """ A lightweight dummy request. diff --git a/docs/tutorials/wiki2/tests.rst b/docs/tutorials/wiki2/tests.rst index 4ea2e2e15..dce14cf9b 100644 --- a/docs/tutorials/wiki2/tests.rst +++ b/docs/tutorials/wiki2/tests.rst @@ -63,6 +63,9 @@ Per-test fixtures The ``testapp`` is able to mutate the request environ such that the ``dbsession`` and ``tm`` fixtures are injected and used by any code that's touching ``request.dbsession`` and ``request.tm``. The ``testapp`` maintains a cookiejar, so it can be used to share state across requests, as well as the transaction database connection. +- ``app_request`` - a :class:`pyramid.request.Request` object that can be used for more lightweight tests versus the full ``testapp``. + The ``app_request`` can be passed to view functions and other code that need a fully functional request object. + - ``dummy_request`` - a :class:`pyramid.testing.DummyRequest` object that is very lightweight. This is a great object to pass to view functions that have minimal side-effects as it'll be fast and simple. |
