Skip to content

Commit

Permalink
Merge pull request #99 from plone/install-caching-50-alpha
Browse files Browse the repository at this point in the history
Install plone.app.caching in 5.0 alpha, if available.
  • Loading branch information
jensens authored Nov 6, 2016
2 parents 53868e7 + f8bc1f4 commit 50b7c1a
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ New features:

Bug fixes:

- Install plone.app.caching in 5.0 alpha if available.
When it is already installed, upgrade it.
[maurits]

- Install plone.app.theming in 5.0 alpha.
When it is already installed, upgrade it.
[maurits]
Expand Down
28 changes: 28 additions & 0 deletions plone/app/upgrade/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@
from os.path import abspath
from os.path import dirname
from os.path import join
from plone.app.testing import PloneSandboxLayer
from plone.app.testing import PLONE_FIXTURE
from plone.app.testing import FunctionalTesting
from plone.app.testing.bbb import PTC_FIXTURE
from plone.app.testing.bbb import PloneTestCase
from Products.CMFCore.interfaces import IActionCategory
from Products.CMFCore.interfaces import IActionInfo
from Products.CMFCore.tests.base.testcase import WarningInterceptor
from Products.CMFCore.utils import getToolByName
from Products.GenericSetup.context import TarballImportContext
from zope.configuration import xmlconfig
from zope.site.hooks import setSite

import transaction
Expand All @@ -17,8 +22,31 @@
#


class UpgradeTestCaseFixture(PloneSandboxLayer):

defaultBases = (PLONE_FIXTURE,)

def setUpZope(self, app, configurationContext):
# In 5.0 alpha we install or upgrade plone.app.caching,
# so it must be available to Zope.
import plone.app.caching
xmlconfig.file(
'configure.zcml',
plone.app.caching,
context=configurationContext
)


UPGRADE_TEST_CASE_FIXTURE = UpgradeTestCaseFixture()
UPGRADE_FUNCTIONAL_TESTING = FunctionalTesting(
bases=(PTC_FIXTURE, UPGRADE_TEST_CASE_FIXTURE),
name='UpgradeTestCase:Functional')


class MigrationTest(PloneTestCase):

layer = UPGRADE_FUNCTIONAL_TESTING

def removeActionFromTool(
self,
action_id,
Expand Down
39 changes: 39 additions & 0 deletions plone/app/upgrade/v50/alphas.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import logging
import pkg_resources

from Acquisition import aq_parent, aq_base
from Products.CMFCore.utils import getToolByName
Expand All @@ -22,6 +23,13 @@
from zope.component.hooks import getSite
from zope.schema.interfaces import ConstraintNotSatisfied

try:
pkg_resources.get_distribution('plone.app.caching')
except pkg_resources.DistributionNotFound:
HAS_CACHING = False
else:
HAS_CACHING = True
from plone.app.caching.interfaces import IPloneCacheSettings

logger = logging.getLogger('plone.app.upgrade')

Expand Down Expand Up @@ -72,6 +80,7 @@ def to50alpha1(context):

upgrade_keyring(context)
installOrUpgradePloneAppTheming(context)
installOrUpgradePloneAppCaching(context)


def installOrUpgradePloneAppTheming(context):
Expand All @@ -92,6 +101,36 @@ def installOrUpgradePloneAppTheming(context):
portal_setup.upgradeProfile(profile_id)


def installOrUpgradePloneAppCaching(context):
"""Install plone.app.caching if not installed yet.
Plone 5.0 installs it by default,
and hides it from the add-ons control panel.
Upgrade it for good measure if it is already installed.
Note: plone.app.caching is required by Plone, not by
Products.CMFPlone, so it may not be available.
"""
if not HAS_CACHING:
return
profile_id = 'profile-plone.app.caching:default'
portal_setup = getToolByName(context, 'portal_setup')
if not portal_setup.profileExists(profile_id):
# During tests, the package may be there, but the zcml may not have
# been loaded, so the profile is not available.
return
registry = getUtility(IRegistry)
try:
registry.forInterface(IPloneCacheSettings)
except KeyError:
# plone.app.caching not yet installed
portal_setup.runAllImportStepsFromProfile(profile_id)
else:
# Might as well upgrade it if needed.
portal_setup.upgradeProfile(profile_id)


def lowercase_email_login(context):
"""If email is used as login name, lowercase the login names.
"""
Expand Down
12 changes: 12 additions & 0 deletions plone/app/upgrade/v50/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,24 @@
from plone.app.testing import PLONE_FIXTURE
from plone.testing.z2 import FunctionalTesting, login
from zope.component.hooks import setSite
from zope.configuration import xmlconfig
import os


class RealUpgradeLayer(PloneSandboxLayer):
defaultBases = (PLONE_FIXTURE,)

def setUpZope(self, app, configurationContext):
# load ZCML
# In 5.0 alpha we install or upgrade plone.app.caching,
# so it must be available to Zope..
import plone.app.caching
xmlconfig.file(
'configure.zcml',
plone.app.caching,
context=configurationContext
)

def setUpPloneSite(self, portal):
app = portal.aq_parent
login(app['acl_users'], 'admin')
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
test=[
'zope.site',
'mock',
'plone.app.caching',
'plone.app.testing',
'plone.app.theming',
]
Expand Down

0 comments on commit 50b7c1a

Please sign in to comment.