ploneasgi.testing#
Test layers for code that runs Plone under ASGI.
ploneasgi is not an add-on: it ships no GenericSetup profile and installs
nothing into a site. The layer therefore does no applyProfile — it exists to
provide a committed Plone site that a worker thread can open a second
connection onto, which is the one thing this package's Plone-facing code needs
and cannot fake.
plone.app.contenttypes is a base rather than a convenience: the security
assertions need real content to be denied access to, and Document is the
cheapest real content there is.
Warning
Use FUNCTIONAL_TESTING for anything that opens a connection from
another thread. The integration layer aborts between tests instead of
committing, so a second connection sees an empty site.
A fixture that commits to work around this raises
plone.testing.zope.TestIsolationBroken — loudly, which is the safe
failure. The dangerous one is the test that needs no fixture: it passes
under either layer while proving nothing about cross-thread visibility.
INTEGRATION_TESTING is kept for single-threaded tests, where it is
considerably faster.
This module imports Plone at module scope, which the rest of ploneasgi
deliberately does not. That is fine — it is an optional import path, installed
via the testing extra — but it means nothing in the package may import it.
- class ploneasgi.testing.Layer[source]#
A plain Plone site with the
<ploneasgi:route />directive available.- setUpZope(app, configurationContext)[source]#
Make the package's ZCML directive resolvable.
Only
meta.zcml— the package has noconfigure.zcmlto load, and registering routes is the consuming project's job, not the layer's.- Parameters:
app -- The Zope application root.
configurationContext -- The ZCML configuration context.
- ploneasgi.testing.PLONEASGI_FIXTURE = <Layer 'ploneasgi.testing.Layer'>#
The shared fixture: a Plone site with
plone.app.contenttypesand the route directive'smeta.zcml. Base your own layers on it.
- ploneasgi.testing.INTEGRATION_TESTING = <Layer 'ploneasgi.testing.PloneasgiLayer:IntegrationTesting'>#
Single-threaded tests only. Aborts between tests, so a connection opened from another thread sees an empty site.
- ploneasgi.testing.FUNCTIONAL_TESTING = <Layer 'ploneasgi.testing.PloneasgiLayer:FunctionalTesting'>#
Anything that reaches Plone from another thread: native routes,
run_authenticated(), a server driven over HTTP.