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 Mar 13, 2019
1 parent 196dbf9 commit 0d1bbc7
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 21 deletions.
1 change: 1 addition & 0 deletions src/collective/lazysizes/Extensions/Install.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
# BBB: remove on deprecation of Plone 4.3
from collective.lazysizes.config import PROJECTNAME
from plone import api

Expand Down
20 changes: 20 additions & 0 deletions src/collective/lazysizes/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
For Plone 5 we need to install plone.app.contenttypes.
"""
from collective.lazysizes.config import PROJECTNAME
from plone import api
from plone.app.robotframework.testing import AUTOLOGIN_LIBRARY_FIXTURE
from plone.app.testing import FunctionalTesting
from plone.app.testing import IntegrationTesting
Expand All @@ -19,6 +21,24 @@
else:
from plone.app.contenttypes.testing import PLONE_APP_CONTENTTYPES_FIXTURE as PLONE_FIXTURE

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


class Fixture(PloneSandboxLayer):

Expand Down
23 changes: 9 additions & 14 deletions src/collective/lazysizes/tests/test_controlpanel.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# -*- coding: utf-8 -*-
from collective.lazysizes.config import PROJECTNAME
from collective.lazysizes.interfaces import ILazySizesSettings
from collective.lazysizes.testing import INTEGRATION_TESTING
from plone import api
from collective.lazysizes.testing import QIBBB
from plone.app.testing import logout
from plone.registry.interfaces import IRegistry
from zope.component import getUtility

import unittest


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

layer = INTEGRATION_TESTING

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

def test_controlpanel_view_is_protected(self):
Expand All @@ -30,22 +30,20 @@ def test_controlpanel_installed(self):
self.assertIn('lazysizes', actions)

def test_controlpanel_removed_on_uninstall(self):
qi = self.portal['portal_quickinstaller']
self.uninstall() # BBB: QI compatibility

with api.env.adopt_roles(['Manager']):
qi.uninstallProducts(products=[PROJECTNAME])

actions = [a.getAction(self)['id']
for a in self.controlpanel.listActions()]
actions = [
a.getAction(self)['id'] for a in self.controlpanel.listActions()]
self.assertNotIn('lazysizes', 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(ILazySizesSettings)

Expand All @@ -58,10 +56,7 @@ def test_css_class_blacklist_record_in_registry(self):
self.assertEqual(self.settings.css_class_blacklist, set([]))

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 = [
ILazySizesSettings.__identifier__ + '.lazyload_authenticated',
Expand Down
25 changes: 18 additions & 7 deletions src/collective/lazysizes/tests/test_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
from collective.lazysizes.config import PROJECTNAME
from collective.lazysizes.interfaces import ILazySizesLayer
from collective.lazysizes.testing import INTEGRATION_TESTING
from plone import api
from collective.lazysizes.testing import IS_BBB
from collective.lazysizes.testing import QIBBB
from plone.browserlayer.utils import registered_layers

import unittest
Expand All @@ -21,8 +22,16 @@ class InstallTestCase(unittest.TestCase):

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.is_product_installed(PROJECTNAME))

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

Expand All @@ -43,20 +52,22 @@ def test_version(self):
setup_tool.getLastVersionForProfile(profile), (u'10',))


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']

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 Down

0 comments on commit 0d1bbc7

Please sign in to comment.