Skip to content

Commit b9febd4

Browse files
authored
Merge pull request #132 from plone/enrich-docstrings
Enrich public API docstrings for autodoc and IDE help
2 parents 4520722 + 820f2f6 commit b9febd4

4 files changed

Lines changed: 76 additions & 7 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Enrich the docstrings of the public testing helpers and layer classes
2+
(``login``, ``logout``, ``setRoles``, ``applyProfile``,
3+
``cleanUpMultiPlugins``, ``IntegrationTesting``, ``FunctionalTesting``)
4+
with parameter descriptions and behaviour notes.
5+
This makes them usable as an autodoc API reference and improves IDE help.
6+
[jensens]

src/plone/app/testing/cleanup.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@
1616

1717

1818
def cleanUpMultiPlugins():
19+
"""Remove PAS MultiPlugin registrations left in the global registry.
20+
21+
Registered as a ``zope.testing`` cleanup handler, so it runs
22+
automatically between test layers and keeps global PluggableAuthService
23+
state from leaking from one layer into the next. Plugins that
24+
GenericSetup's own cleanup handler already manages are left untouched.
25+
"""
1926
try:
2027
from Products.PluggableAuthService.PluggableAuthService import MultiPlugins
2128

src/plone/app/testing/helpers.py

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,39 @@
2222

2323

2424
def login(portal, userName):
25-
"""Log in as the given user in the given Plone site"""
25+
"""Log in as the named user in the given Plone site.
26+
27+
Subsequent operations run as this user until :func:`logout` is called
28+
or the test tears down.
29+
30+
:param portal: the Plone site to log in to.
31+
:param userName: the login name of the user to become, for example
32+
:data:`TEST_USER_NAME`. This is the login name, not the user id.
33+
"""
2634

2735
zope.login(portal["acl_users"], userName)
2836

2937

3038
def logout():
31-
"""Log out, i.e. become anonymous"""
39+
"""Log out, so that subsequent operations run as the anonymous user.
40+
41+
The inverse of :func:`login`.
42+
"""
3243

3344
zope.logout()
3445

3546

3647
def setRoles(portal, userId, roles):
37-
"""Set the given user's roles to a tuple of roles."""
48+
"""Set a user's global roles to exactly the given roles.
49+
50+
Replaces the user's current roles rather than adding to them.
51+
52+
:param portal: the Plone site.
53+
:param userId: the id of the user whose roles to set, for example
54+
:data:`TEST_USER_ID`. This is the user id, not the login name.
55+
:param roles: the roles the user should have, as a sequence of role
56+
names, for example ``["Manager"]``.
57+
"""
3858

3959
userFolder = portal["acl_users"]
4060
zope.setRoles(userFolder, userId, roles)
@@ -105,8 +125,25 @@ def applyProfile(
105125
archive=None,
106126
blacklisted_steps=None,
107127
):
108-
"""Install an extension profile into the portal. The profile name
109-
should be a package name and a profile name, e.g. 'my.product:default'.
128+
"""Install a GenericSetup extension profile into the portal.
129+
130+
Runs every import step of the profile as the site owner, then rebuilds
131+
the current skin. Use this to install an add-on into the test site,
132+
typically from a layer's ``setUpPloneSite`` or directly in a test.
133+
134+
:param portal: the Plone site to install the profile into.
135+
:param profileName: the profile id in ``package:profile`` form, for
136+
example ``"my.product:default"``. Give it without the ``profile-``
137+
prefix; that is added internally.
138+
:param purge_old: passed through to GenericSetup. When ``None`` (the
139+
default) GenericSetup decides; ``True`` purges existing settings
140+
before importing, ``False`` keeps them.
141+
:param ignore_dependencies: when ``True``, run only the profile's own
142+
import steps and skip the profiles it depends on.
143+
:param archive: an optional GenericSetup archive (tarball) to import
144+
from instead of the profile directory.
145+
:param blacklisted_steps: an optional sequence of import step ids to
146+
skip.
110147
"""
111148

112149
from AccessControl import getSecurityManager

src/plone/app/testing/layers.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,11 +398,30 @@ def testTearDown(self):
398398

399399

400400
class IntegrationTesting(PloneTestLifecycle, zope.IntegrationTesting):
401-
"""Plone version of the integration testing layer"""
401+
"""Testing layer for integration tests.
402+
403+
Wraps a Plone site fixture with per-test isolation: each test runs
404+
inside a transaction that is rolled back on tear-down, so tests do not
405+
see each other's changes. Derive one from your fixture with
406+
``IntegrationTesting(bases=(MY_FIXTURE,), name=...)``.
407+
408+
Use this for in-process tests. When a test makes a real HTTP request,
409+
use :class:`FunctionalTesting` instead.
410+
"""
402411

403412

404413
class FunctionalTesting(PloneTestLifecycle, zope.FunctionalTesting):
405-
"""Plone version of the functional testing layer"""
414+
"""Testing layer for functional tests.
415+
416+
Like :class:`IntegrationTesting`, but each test runs against a stacked
417+
``DemoStorage`` and may commit real transactions, which a separate
418+
process such as a browser or HTTP client can then see. The storage is
419+
discarded on tear-down.
420+
421+
Use this when a request has to travel over the network, for example a
422+
REST API or browser test. Add ``WSGI_SERVER_FIXTURE`` to the bases so a
423+
server is running. For in-process tests, use :class:`IntegrationTesting`.
424+
"""
406425

407426

408427
class ZServerFunctionalTesting(PloneZServerTestLifecycle, zserver.FunctionalTesting):

0 commit comments

Comments
 (0)