Skip to content

Commit

Permalink
testing: imported and upgraded Plone 5.1 instance has no rr tools any…
Browse files Browse the repository at this point in the history
…more
  • Loading branch information
ksuess committed Feb 9, 2019
1 parent c5f73fe commit cb8e066
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 19 deletions.
3 changes: 2 additions & 1 deletion plone/app/upgrade/v40/alphas.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,8 @@ def cleanUpToolRegistry(context):
required = toolset._required.copy()
existing = portal.keys()
changed = False
for name, info in required.items():
items = list(required.items())
for name, info in items:
if name not in existing:
del required[name]
changed = True
Expand Down
5 changes: 2 additions & 3 deletions plone/app/upgrade/v50/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,13 @@ def setUpZope(self, app, configurationContext):
def setUpPloneSite(self, portal):
app = portal.aq_parent
login(app['acl_users'], 'admin')

# import old ZEXP
try:
path = os.path.join(os.path.abspath(
os.path.dirname(__file__)), 'data', 'test-full.zexp')
app._importObjectFromFile(path, verify=0)
except BaseException:
logger.exception('Failed to import ZEXP from old site.')
except Exception as e:
logger.exception('Failed to import ZEXP from old site. ({})'.format(e))
else:
# run upgrades
self['portal'] = portal = app.test
Expand Down
3 changes: 1 addition & 2 deletions plone/app/upgrade/v50/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import six
import unittest


try:
from Products.CMFPlone.factory import _IMREALLYPLONE5
_IMREALLYPLONE5 # pyflakes
Expand Down Expand Up @@ -179,7 +178,7 @@ def test_fix_double_smaxage(self):


def test_suite():
# Skip these tests on Plone 4
# Skip these tests if not Plone 5.0 or 5.1
from unittest import TestSuite, makeSuite
if not six.PY2 or not PLONE_5:
return TestSuite()
Expand Down
21 changes: 18 additions & 3 deletions plone/app/upgrade/v52/alphas.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
from BTrees.OOBTree import OOBTree
from plone.app.upgrade.utils import cleanUpSkinsTool
from plone.app.upgrade.utils import loadMigrationProfile
<<<<<<< HEAD
from plone.dexterity.interfaces import IDexterityFTI
=======
from plone.app.upgrade.v40.alphas import cleanUpToolRegistry
>>>>>>> remove portal tools and configuration registry. testing
from plone.folder.nogopip import manage_addGopipIndex
from plone.registry.interfaces import IRegistry
from Products.CMFCore.utils import getToolByName
Expand Down Expand Up @@ -36,6 +33,23 @@ def migrate_gopipindex(context):
manage_addGopipIndex(catalog, 'getObjPositionInParent')


def remove_legacy_resource_registries(context):
"""Remove portal_css and portal_javascripts."""
portal_url = getToolByName(context, 'portal_url')
portal = portal_url.getPortalObject()

tools_to_remove = [
'portal_css',
'portal_javascripts',
]

# remove obsolete tools
tools = [t for t in tools_to_remove if t in portal]
portal.manage_delObjects(tools)

cleanUpToolRegistry(context)


def rebuild_memberdata(context):
# MemberData has changed radically, see plone/Products.PlonePAS#24
# This results in a bug in upgraded sites: plone/Products.CMFPlone#2722
Expand Down Expand Up @@ -111,6 +125,7 @@ def to52alpha1(context):

cleanup_resources()
migrate_gopipindex(context)
remove_legacy_resource_registries(context)
rebuild_memberdata(context)
fix_core_behaviors_in_ftis(context)
remove_portal_tools(context)
Binary file added plone/app/upgrade/v52/data/test-full-5_1.zexp
Binary file not shown.
62 changes: 62 additions & 0 deletions plone/app/upgrade/v52/testing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# -*- coding: utf-8 -*-
from plone.app.testing import PLONE_FIXTURE
from plone.app.testing import PloneSandboxLayer
from plone.app.upgrade.utils import loadMigrationProfile
from plone.testing.z2 import FunctionalTesting
from plone.testing.z2 import login
from zope.component.hooks import setSite

import logging
import os


logger = logging.getLogger(__file__)


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
# self.loadZCML(
# name='configure.zcml',
# package=plone.app.caching,
# )

def setUpPloneSite(self, portal):
app = portal.aq_parent
login(app['acl_users'], 'admin')
# import old ZEXP
try:
path = os.path.join(os.path.abspath(
os.path.dirname(__file__)), 'data', 'test-full-5_1.zexp')
app._importObjectFromFile(path, verify=0)
except Exception as e:
import pdb; pdb.set_trace()
logger.exception('Failed to import ZEXP from old site. ({})'.format(e))
else:
# run upgrades
self['portal'] = portal = app.test
setSite(portal)
if get_distribution('Products.CMFPlone').version >= '5.2':
# for 5.2 we need tools as utilities
loadMigrationProfile(
portal.portal_setup,
'profile-plone.app.upgrade.v52:to52alpha1',
steps=['componentregistry'])
portal.portal_migration.upgrade(swallow_errors=False)
setSite(None)

def tearDownPloneSite(self, portal):
try:
del self['portal']
except KeyError:
pass


REAL_UPGRADE_FIXTURE = RealUpgradeLayer()
REAL_UPGRADE_FUNCTIONAL = FunctionalTesting(
bases=(REAL_UPGRADE_FIXTURE,), name='plone.app.upgrade:5.1 -> 5.2')
18 changes: 8 additions & 10 deletions plone/app/upgrade/v52/tests.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# -*- coding: utf-8 -*-

from plone.app.upgrade.v50.testing import REAL_UPGRADE_FUNCTIONAL
from plone.app.upgrade.v52.testing import REAL_UPGRADE_FUNCTIONAL
from plone.testing.z2 import Browser
from pkg_resources import get_distribution

import unittest

PLONE_52 = get_distribution('Products.CMFPlone').version >= '5.2'
PLONE_51 = get_distribution('Products.CMFPlone').version >= '5.1'


class TestFunctionalMigrations(unittest.TestCase):
Expand All @@ -17,27 +17,25 @@ class TestFunctionalMigrations(unittest.TestCase):
layer = REAL_UPGRADE_FUNCTIONAL

def setUp(self):
self.portal = self.layer['app'].test
self.portal = self.layer['app'].plone

def testFullyUpgraded(self):
self.assertFalse(self.portal.portal_migration.needUpgrading())

def testCanRenderHomepage(self):
browser = Browser(self.layer['app'])
browser.open('http://nohost/test')
self.assertTrue('Welcome' in browser.contents)
portalURL = self.portal.absolute_url()
browser.open(portalURL)
self.assertTrue('Plone' in browser.contents)

def testToolsAreRemoved(self):
self.assertFalse('portal_css' in self.portal)
self.assertFalse('portal_javascripts' in self.portal)


def test_suite():
# Skip these tests on Plone < 5.2

print("PLONE_52 {}").format(PLONE_52) # debug
import pdb; pdb.set_trace()
if not PLONE_52:
# Skip these tests on Plone < 5.1
if not PLONE_51:
return unittest.TestSuite()

suite = unittest.TestSuite()
Expand Down

0 comments on commit cb8e066

Please sign in to comment.