Skip to content

Commit

Permalink
Manage deprecation of CMFQuickInstallerTool on Plone >= 5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
hvelarde committed Jul 4, 2018
1 parent 61f382d commit 0231e79
Show file tree
Hide file tree
Showing 12 changed files with 52 additions and 113 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ before_script:
- firefox -v
script:
- bin/code-analysis
- bin/test
- CATALOG_OPTIMIZATION_DISABLED=true bin/test
- bin/pylint --py3k --disable=no-absolute-import src/collective/nitf
after_success:
- pip install coverage
Expand Down
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ There's a frood who really knows where his towel is.
This version disables usage of Latest Sectionable NITF portlet.
Remove manually all Latest Sectionable NITF portlets before upgrading.

- Manage deprecation of CMFQuickInstallerTool on Plone >= 5.1;
remove needless tile registration/removal when using plone.app.tiles >= 3.0.0.
[hvelarde]

- Fix package dependencies.
[hvelarde]

Expand Down
18 changes: 0 additions & 18 deletions src/collective/nitf/Extensions/Install.py

This file was deleted.

1 change: 0 additions & 1 deletion src/collective/nitf/Extensions/__init__.py

This file was deleted.

2 changes: 0 additions & 2 deletions src/collective/nitf/configure.zcml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser"
xmlns:five="http://namespaces.zope.org/five"
xmlns:i18n="http://namespaces.zope.org/i18n"
xmlns:zcml="http://namespaces.zope.org/zcml"
i18n_domain="collective.nitf">

<five:registerPackage package="." />
<i18n:registerTranslations directory="locales" />

<include file="dependencies.zcml" />
Expand Down
21 changes: 5 additions & 16 deletions src/collective/nitf/profiles.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,17 @@
title="collective.nitf"
description="A Dexterity-based content type inspired on the News Industry Text Format specification."
directory="profiles/default"
provides="Products.GenericSetup.interfaces.EXTENSION" />
provides="Products.GenericSetup.interfaces.EXTENSION"
post_handler="collective.nitf.setuphandlers.run_after"
/>

<genericsetup:registerProfile
name="uninstall"
title="collective.nitf uninstall"
directory="profiles/uninstall"
description="Uninstall profile for the collective.nitf package."
provides="Products.GenericSetup.interfaces.EXTENSION" />

<genericsetup:importStep
name="collective.nitf"
title="collective.nitf special import handlers"
description=""
handler="collective.nitf.setuphandlers.import_various" />

<genericsetup:upgradeStep
title="Add catalog indexes"
description=""
source="1000"
destination="1001"
handler="collective.nitf.setuphandlers.add_catalog_indexes"
profile="collective.nitf:default" />
provides="Products.GenericSetup.interfaces.EXTENSION"
/>

<utility
factory=".setuphandlers.NonInstallable"
Expand Down
11 changes: 0 additions & 11 deletions src/collective/nitf/profiles/default/registry.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,4 @@
</value>
<value key="group" i18n:translate="">NITF</value>
</records>

<record name="plone.app.tiles">
<field type="plone.registry.field.List">
<title>Tiles</title>
<value_type type="plone.registry.field.TextLine" />
</field>
<value purge="false">
<element>collective.nitf</element>
</value>
</record>

</registry>
22 changes: 4 additions & 18 deletions src/collective/nitf/setuphandlers.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# -*- coding: utf-8 -*-
from collective.nitf.config import PROJECTNAME
from collective.nitf.logger import logger
from plone import api
from Products.CMFPlone.interfaces import INonInstallable
from Products.CMFQuickInstallerTool import interfaces as BBB
from zope.interface import implementer

import logging


@implementer(BBB.INonInstallable) # BBB: Plone 4.3
@implementer(INonInstallable)
Expand All @@ -32,7 +30,7 @@ class Empty:
pass


def add_catalog_indexes(context, logger=None):
def add_catalog_indexes():
""" Method to add our wanted indexes to the portal_catalog. See
http://maurits.vanrees.org/weblog/archive/2009/12/catalog for more
information.
Expand All @@ -46,10 +44,6 @@ def extras(title, index_type='Okapi BM25 Rank',
extras.lexicon_id = lexicon_id
return extras

if logger is None:
# Called as upgrade step: define our own logger
logger = logging.getLogger(PROJECTNAME)

profile = 'profile-collective.nitf:default'
setup = api.portal.get_tool('portal_setup')
setup.runImportStepFromProfile(profile, 'catalog')
Expand Down Expand Up @@ -82,13 +76,5 @@ def extras(title, index_type='Okapi BM25 Rank',
catalog.manage_reindexIndex(ids=indexables)


def import_various(context):
""" Import step for configuration that is not handled in XML files.
"""
# Only run step if a flag file is present
if context.readDataFile('collective.nitf.marker.txt') is None:
return

logger = context.getLogger(PROJECTNAME)
site = context.getSite()
add_catalog_indexes(site, logger)
def run_after(context):
add_catalog_indexes()
18 changes: 18 additions & 0 deletions src/collective/nitf/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Tile for collective.cover is only tested in Plone 4.3.
"""
from collective.nitf.config import PROJECTNAME
from plone import api
from plone.app.robotframework.testing import AUTOLOGIN_LIBRARY_FIXTURE
from plone.app.testing import FunctionalTesting
Expand Down Expand Up @@ -37,6 +38,23 @@
HAS_COVER = True

IS_PLONE_5 = api.env.plone_version().startswith('5')
IS_BBB = api.env.plone_version().startswith('4.3')


class QIBBB:
"""BBB: remove on deprecation of Plone 4.3."""
def uninstall(self):
if IS_BBB:
qi = self.portal['portal_quickinstaller']
with api.env.adopt_roles(['Manager']):
qi.uninstallProducts([PROJECTNAME])
else:
from Products.CMFPlone.utils import get_installer
qi = get_installer(self.portal, self.request)
with api.env.adopt_roles(['Manager']):
qi.uninstall_product(PROJECTNAME)
return qi


# set of images to be used on tests
IMAGES = (
Expand Down
39 changes: 20 additions & 19 deletions src/collective/nitf/tests/test_setup.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
from collective.nitf.config import PROJECTNAME
from collective.nitf.testing import HAS_COVER
from collective.nitf.testing import INTEGRATION_TESTING
from collective.nitf.testing import IS_BBB
from collective.nitf.testing import IS_PLONE_5
from plone import api
from collective.nitf.testing import QIBBB
from plone.browserlayer.utils import registered_layers

import unittest
Expand All @@ -18,16 +18,24 @@
CSS = '++resource++collective.nitf/nitf.css'


class InstallTestCase(unittest.TestCase):
class InstallTestCase(unittest.TestCase, QIBBB):

layer = INTEGRATION_TESTING

def setUp(self):
self.portal = self.layer['portal']
self.qi = self.portal['portal_quickinstaller']

@unittest.skipIf(IS_BBB, 'Plone >= 5.1')
def test_installed(self):
self.assertTrue(self.qi.isProductInstalled(PROJECTNAME))
from Products.CMFPlone.utils import get_installer
qi = get_installer(self.portal, self.request)
self.assertTrue(qi.is_product_installed(PROJECTNAME))

@unittest.skipUnless(IS_BBB, 'Plone < 5.1')
def test_installed_BBB(self):
qi = getattr(self.portal, 'portal_quickinstaller')
self.assertTrue(qi.isProductInstalled(PROJECTNAME))

def test_dependencies_installed(self):
for p in DEPENDENCIES:
Expand Down Expand Up @@ -68,24 +76,22 @@ def test_cssregistry(self):
resource_ids = self.portal.portal_css.getResourceIds()
self.assertIn(CSS, resource_ids)

@unittest.skipUnless(HAS_COVER, 'plone.app.tiles must be installed')
def test_tile(self):
tiles = api.portal.get_registry_record('plone.app.tiles')
self.assertIn(u'collective.nitf', tiles)


class UninstallTest(unittest.TestCase):
class UninstallTest(unittest.TestCase, QIBBB):

layer = INTEGRATION_TESTING

def setUp(self):
self.portal = self.layer['portal']
self.qi = self.portal['portal_quickinstaller']

with api.env.adopt_roles(['Manager']):
self.qi.uninstallProducts(products=[PROJECTNAME])
self.request = self.layer['request']
self.qi = self.uninstall() # BBB: QI compatibility

@unittest.skipIf(IS_BBB, 'Plone >= 5.1')
def test_uninstalled(self):
self.assertFalse(self.qi.is_product_installed(PROJECTNAME))

@unittest.skipUnless(IS_BBB, 'Plone < 5.1')
def test_uninstalled_BBB(self):
self.assertFalse(self.qi.isProductInstalled(PROJECTNAME))

def test_addon_layer_removed(self):
Expand All @@ -102,11 +108,6 @@ def test_cssregistry_removed(self):
resource_ids = self.portal.portal_css.getResourceIds()
self.assertNotIn(CSS, resource_ids)

@unittest.skipUnless(HAS_COVER, 'plone.app.tiles must be installed')
def test_tile_removed(self):
tiles = api.portal.get_registry_record('plone.app.tiles')
self.assertNotIn(u'collective.nitf', tiles)

# FIXME: https://github.com/collective/collective.nitf/issues/168
@unittest.expectedFailure
def test_link_workflow_restored(self):
Expand Down
17 changes: 0 additions & 17 deletions src/collective/nitf/tests/test_upgrades.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
from six.moves import range # noqa: I001
from collective.nitf.Extensions.Install import remove_tile
from collective.nitf.testing import INTEGRATION_TESTING
from collective.nitf.testing import IS_PLONE_5
from plone import api
Expand Down Expand Up @@ -287,22 +286,6 @@ def test_reindex_news_articles(self):
results = api.content.find(portal_type='collective.nitf.content')
self.assertEqual(len(results), 10) # no failure and catalog unaffected

def test_nitf_tile_registry_from_1x_to_2x(self):
# check if the upgrade step is registered
title = u'Miscellaneous'
step = self.get_upgrade_step(title)
self.assertIsNotNone(step)

# simulate state on previous version, because profiles/default registers
# this tile, so we remove it first.
remove_tile(self.portal)
tiles = api.portal.get_registry_record('plone.app.tiles')
self.assertNotIn(u'collective.nitf', tiles)

self.execute_upgrade_step(step)
tiles = api.portal.get_registry_record('plone.app.tiles')
self.assertIn(u'collective.nitf', tiles)


class to2001TestCase(UpgradeTestCaseBase):

Expand Down
10 changes: 0 additions & 10 deletions src/collective/nitf/upgrades/v2000/profile/registry.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,4 @@
<record name="collective.nitf.controlpanel.INITFCharCountSettings.title_max_chars" delete="true" />
<record name="collective.nitf.controlpanel.INITFCharCountSettings.title_optimal_chars" delete="true" />
<record name="collective.nitf.controlpanel.INITFSettings.relatable_content_types" delete="true" />

<record name="plone.app.tiles">
<field type="plone.registry.field.List">
<title>Tiles</title>
<value_type type="plone.registry.field.TextLine" />
</field>
<value purge="false">
<element>collective.nitf</element>
</value>
</record>
</registry>

0 comments on commit 0231e79

Please sign in to comment.