Skip to content

Commit

Permalink
In PloneSandboxLayer make profile upgrade versions persistent.
Browse files Browse the repository at this point in the history
This way installed profile versions get reset in teardown.

Initially I added push and pop support for the various GS registries,
but somehow that is handled fine already.
  • Loading branch information
mauritsvanrees committed Sep 6, 2016
1 parent 8dbbe78 commit 63c5177
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ Breaking changes:

New features:

- *add item here*
- In PloneSandboxLayer make profile upgrade versions persistent. This
way installed profile versions get reset in teardown. [maurits]

Bug fixes:

Expand Down
19 changes: 19 additions & 0 deletions plone/app/testing/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,21 @@ def popGlobalRegistry(portal):
return previous


def persist_profile_upgrade_versions(portal):
"""Persist the profile_upgrade_versions of portal_setup.
Until at least Products.GenericSetup 1.8.3 this is a standard
non-persistent dictionary, which means a transaction rollback does
not rollback changes to this dictionary. So we make it a persistent
mapping. Call this once in layer setup and you have easy rollback.
"""
from persistent.mapping import PersistentMapping
puv = portal.portal_setup._profile_upgrade_versions
if isinstance(puv, PersistentMapping):
return
portal.portal_setup._profile_upgrade_versions = PersistentMapping(puv)


@contextlib.contextmanager
def ploneSite(db=None, connection=None, environ=None):
"""Context manager for working with the Plone portal during layer setup::
Expand Down Expand Up @@ -325,6 +340,10 @@ def setUp(self):
# and other global component registry changes are sandboxed
pushGlobalRegistry(portal)

# Persist GenericSetup profile upgrade versions for easy
# rollback.
persist_profile_upgrade_versions(portal)

# Make sure zope.security checkers can be set up and torn down
# reliably

Expand Down
10 changes: 10 additions & 0 deletions plone/app/testing/helpers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ need to tear that down as well.
...
... with helpers.ploneSite() as portal:
...
... # Persist GenericSetup profile upgrade versions for easy rollback.
... helpers.persist_profile_upgrade_versions(portal)
...
... # Push a new component registry so that ZCML registations
... # and other global component registry changes are sandboxed
... helpers.pushGlobalRegistry(portal)
Expand Down Expand Up @@ -133,9 +136,12 @@ having taken effect.
We should also see our product installation in the quickinstaller tool
and the results of the profile having been applied.

>>> from Products.GenericSetup.tool import UNKNOWN
>>> with helpers.ploneSite() as portal:
... print portal['portal_quickinstaller'].isProductInstalled('plone.resource')
... portal.portal_setup.getLastVersionForProfile('plone.resource:default') == UNKNOWN
True
False

Let's now simulate a test.

Expand Down Expand Up @@ -199,9 +205,11 @@ should not.
... print portal.title
... print portal['portal_quickinstaller'].isProductInstalled('plone.resource')
... 'folder1' in portal.objectIds()
... portal.portal_setup.getLastVersionForProfile('plone.resource:default') == UNKNOWN
New title
True
False
False

We'll now tear down just the ``HELPER_DEMOS_INTEGRATION_TESTING`` layer. At this
point, we should still have a Plone site, but none of the persistent or
Expand All @@ -217,6 +225,8 @@ component architecture changes from our layer.
>>> with helpers.ploneSite() as portal:
... print portal.title
... print portal['portal_quickinstaller'].isProductInstalled('plone.resource')
... # This should be True, but is False:
... # portal.portal_setup.getLastVersionForProfile('plone.resource:default') == UNKNOWN
Plone site
False

Expand Down

0 comments on commit 63c5177

Please sign in to comment.