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 Apr 23, 2018
1 parent d060971 commit e80ecc9
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 50 deletions.
1 change: 1 addition & 0 deletions src/collective/fingerpointing/Extensions/Install.py
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
# BBB: remove on deprecation of Plone 4.3 and 5.0
from collective.fingerpointing.config import PROJECTNAME
from plone import api

Expand Down
16 changes: 16 additions & 0 deletions src/collective/fingerpointing/testing.py
Expand Up @@ -3,6 +3,7 @@
For Plone 5 we need to install plone.app.contenttypes.
"""
from collective.fingerpointing.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 @@ -34,6 +35,21 @@
IS_BBB = api.env.plone_version().startswith(('4.3', '5.0'))


class QIBBB:
"""BBB: remove on deprecation of Plone 4.3 and 5.0."""
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


class Fixture(PloneSandboxLayer):

defaultBases = (PLONE_FIXTURE,)
Expand Down
18 changes: 6 additions & 12 deletions src/collective/fingerpointing/tests/test_controlpanel.py
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from collective.fingerpointing.config import PROJECTNAME
from collective.fingerpointing.interfaces import IFingerPointingSettings
from collective.fingerpointing.testing import INTEGRATION_TESTING
from collective.fingerpointing.testing import QIBBB
from plone import api
from plone.app.testing import logout
from plone.registry.interfaces import IRegistry
Expand All @@ -10,7 +10,7 @@
import unittest


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

layer = INTEGRATION_TESTING

Expand All @@ -37,22 +37,20 @@ def test_controlpanel_installed(self):
self.assertIn('fingerpointing', actions)

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

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

actions = [
a.getAction(self)['id'] for a in self.controlpanel.listActions()]
self.assertNotIn('fingerpointing', actions)


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

layer = INTEGRATION_TESTING

def setUp(self):
self.portal = self.layer['portal']
self.request = self.layer['request']
self.registry = getUtility(IRegistry)
self.settings = self.registry.forInterface(IFingerPointingSettings)

Expand Down Expand Up @@ -81,10 +79,7 @@ def test_audit_iterate_record_in_registry(self):
self.assertEqual(self.settings.audit_iterate, True)

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

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

records = [
IFingerPointingSettings.__identifier__ + '.audit_pas',
Expand All @@ -94,6 +89,5 @@ def test_records_removed_on_uninstall(self):
IFingerPointingSettings.__identifier__ + '.audit_registry',
IFingerPointingSettings.__identifier__ + '.audit_iterate',
]

for r in records:
self.assertNotIn(r, self.registry)
Expand Up @@ -3,10 +3,10 @@
Dexterity content types have different names.
"""
from collective.fingerpointing.config import PROJECTNAME
from collective.fingerpointing.interfaces import IFingerPointingSettings
from collective.fingerpointing.testing import INTEGRATION_TESTING
from collective.fingerpointing.testing import IS_PLONE_5
from collective.fingerpointing.testing import QIBBB
from logging import INFO
from plone import api
from plone.app.iterate.interfaces import ICheckinCheckoutPolicy
Expand All @@ -15,13 +15,14 @@
import unittest


class IterateSubscribersTestCase(unittest.TestCase):
class IterateSubscribersTestCase(unittest.TestCase, QIBBB):
"""Tests for plone.app.iterate subscribers."""

layer = INTEGRATION_TESTING

def setUp(self):
self.portal = self.layer['portal']
self.request = self.layer['request']
self._disable_lifecycle_events()

with api.env.adopt_roles(['Manager']):
Expand Down Expand Up @@ -68,9 +69,7 @@ def test_checkout_cancel(self):

def test_susbcriber_ignored_when_package_not_installed(self):
# iterate events should not raise errors if package not installed
qi = self.portal['portal_quickinstaller']
with api.env.adopt_roles(['Manager']):
qi.uninstallProducts(products=[PROJECTNAME])
self.uninstall() # BBB: QI compatibility

wc = ICheckinCheckoutPolicy(self.doc).checkout(self.folder)
ICheckinCheckoutPolicy(wc).cancelCheckout()
11 changes: 4 additions & 7 deletions src/collective/fingerpointing/tests/test_lifecycle_subscriber.py
Expand Up @@ -4,24 +4,24 @@
Events are slightly different among Archetypes and Dexterity.
Also, Dexterity content types have different names.
"""
from collective.fingerpointing.config import PROJECTNAME
from collective.fingerpointing.testing import INTEGRATION_TESTING
from collective.fingerpointing.testing import IS_PLONE_5
from collective.fingerpointing.testing import QIBBB
from logging import INFO
from plone import api
from testfixtures import LogCapture

import unittest


class LifeCycleSubscribersTestCase(unittest.TestCase):

class LifeCycleSubscribersTestCase(unittest.TestCase, QIBBB):
"""Tests content type life cycle subscribers."""

layer = INTEGRATION_TESTING

def setUp(self):
self.portal = self.layer['portal']
self.request = self.layer['request']
with api.env.adopt_roles(['Manager']):
self.folder = api.content.create(self.portal, 'Folder', 'folder')

Expand Down Expand Up @@ -97,10 +97,7 @@ def test_image_lifecicle(self):
def test_susbcriber_ignored_when_package_not_installed(self):
# content type life cycle events should not raise errors
# if package is not installed
qi = self.portal['portal_quickinstaller']

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

obj = api.content.create(self.folder, 'Folder', 'foo')
obj.reindexObject()
Expand Down
13 changes: 4 additions & 9 deletions src/collective/fingerpointing/tests/test_pas_subscriber.py
@@ -1,9 +1,8 @@
# -*- coding: utf-8 -*-
"""Tests for lifecycle subscriber."""
from collective.fingerpointing.config import PROJECTNAME
from collective.fingerpointing.testing import INTEGRATION_TESTING
from collective.fingerpointing.testing import QIBBB
from logging import INFO
from plone import api
from Products.PlonePAS.events import UserLoggedInEvent
from Products.PlonePAS.events import UserLoggedOutEvent
from Products.PluggableAuthService.events import GroupDeleted
Expand All @@ -15,13 +14,13 @@
import unittest


class PasSubscribersTestCase(unittest.TestCase):

class PasSubscribersTestCase(unittest.TestCase, QIBBB):
"""Tests for PluggableAuthService subscribers."""

layer = INTEGRATION_TESTING

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

def test_user_login(self):
Expand Down Expand Up @@ -67,11 +66,7 @@ def test_group_removed(self):
def test_susbcriber_ignored_when_package_not_installed(self):
# authentication events should not raise errors
# if package is not installed
portal = self.layer['portal']
qi = portal['portal_quickinstaller']

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

event = UserLoggedInEvent(self.request)
notify(event)
Expand Down
11 changes: 4 additions & 7 deletions src/collective/fingerpointing/tests/test_registry_subscriber.py
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
from collective.fingerpointing.config import PROJECTNAME
from collective.fingerpointing.testing import INTEGRATION_TESTING
from collective.fingerpointing.testing import QIBBB
from logging import INFO
from plone import api
from plone.app.discussion.interfaces import IDiscussionSettings
Expand All @@ -13,14 +13,14 @@
import unittest


class RegistrySubscribersTestCase(unittest.TestCase):

class RegistrySubscribersTestCase(unittest.TestCase, QIBBB):
"""Tests for plone.app.registry subscribers."""

layer = INTEGRATION_TESTING

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

def test_record_modified(self):
with LogCapture('collective.fingerpointing', level=INFO) as log:
Expand All @@ -43,10 +43,7 @@ def test_new_record_modified(self):
def test_susbcriber_ignored_when_package_not_installed(self):
# registry events should not raise errors
# if package is not installed
qi = self.portal['portal_quickinstaller']

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

record = IDiscussionSettings.__identifier__ + '.globally_enabled'
api.portal.set_registry_record(record, False)
23 changes: 18 additions & 5 deletions src/collective/fingerpointing/tests/test_setup.py
Expand Up @@ -3,21 +3,30 @@
from collective.fingerpointing.config import PROJECTNAME
from collective.fingerpointing.interfaces import IBrowserLayer
from collective.fingerpointing.testing import INTEGRATION_TESTING
from collective.fingerpointing.testing import IS_BBB
from collective.fingerpointing.testing import QIBBB
from plone.browserlayer.utils import registered_layers

import unittest


class InstallTestCase(unittest.TestCase):

"""Ensure product is properly installed."""

layer = INTEGRATION_TESTING

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

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

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

Expand Down Expand Up @@ -49,18 +58,22 @@ def test_show_log_permission(self):
self.assertListEqual(roles, expected)


class UninstallTestCase(unittest.TestCase):

class UninstallTestCase(unittest.TestCase, QIBBB):
"""Ensure product is properly uninstalled."""

layer = INTEGRATION_TESTING

def setUp(self):
self.portal = self.layer['portal']
self.qi = self.portal['portal_quickinstaller']
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 Down
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
"""Tests for workflow subscriber."""
from collective.fingerpointing.config import PROJECTNAME
from collective.fingerpointing.interfaces import IFingerPointingSettings
from collective.fingerpointing.testing import INTEGRATION_TESTING
from collective.fingerpointing.testing import IS_PLONE_5
from collective.fingerpointing.testing import QIBBB
from logging import INFO
from plone import api
from plone.app.testing import setRoles
Expand All @@ -13,14 +13,14 @@
import unittest


class WorkflowSubscribersTestCase(unittest.TestCase):

class WorkflowSubscribersTestCase(unittest.TestCase, QIBBB):
"""Tests content type life cycle subscribers."""

layer = INTEGRATION_TESTING

def setUp(self):
self.portal = self.layer['portal']
self.request = self.layer['request']
setRoles(self.portal, TEST_USER_ID, ['Manager'])

# disable lifecycle audit
Expand Down Expand Up @@ -51,8 +51,7 @@ def test_workflow_transitions(self):

def test_susbcriber_ignored_when_package_not_installed(self):
# events should not raise errors if package is not installed
qi = self.portal['portal_quickinstaller']
qi.uninstallProducts(products=[PROJECTNAME])
self.uninstall() # BBB: QI compatibility

obj = api.content.create(self.portal, 'News Item', 'foo')
api.content.transition(obj=obj, transition='submit')
Expand Down

0 comments on commit e80ecc9

Please sign in to comment.