Skip to content

Commit

Permalink
Merge branch 'djay/restore_5.0.x' into djay/5.0.x_integration
Browse files Browse the repository at this point in the history
  • Loading branch information
djay committed Jul 9, 2019
2 parents 0851f0b + 1428e36 commit 4bb09f9
Showing 1 changed file with 65 additions and 54 deletions.
119 changes: 65 additions & 54 deletions src/collective/collectionfilter/tests/test_setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- coding: utf-8 -*-
"""Setup tests for this package."""
from Products.CMFCore.utils import getToolByName

from collective.collectionfilter.testing import COLLECTIVE_COLLECTIONFILTER_INTEGRATION_TESTING # noqa
from plone import api
from plone.app.testing import setRoles
Expand All @@ -12,57 +14,66 @@
try:
from Products.CMFPlone.utils import get_installer
except Exception:
no_get_installer = True

# TODO: fix tests for 5.0.x
if not no_get_installer:

class TestSetup(unittest.TestCase):
"""Test that collective.collectionfilter is properly installed."""

layer = COLLECTIVE_COLLECTIONFILTER_INTEGRATION_TESTING

def setUp(self):
"""Custom shared utility setup for tests."""
self.portal = self.layer['portal']
self.installer = get_installer(self.portal, self.layer['request'])

def test_product_installed(self):
"""Test if collective.collectionfilter is installed."""
self.assertTrue(self.installer.is_product_installed(
'collective.collectionfilter'))

def test_browserlayer(self):
"""Test that ICollectionFilterBrowserLayer is registered."""
from collective.collectionfilter.interfaces import (
ICollectionFilterBrowserLayer)
from plone.browserlayer import utils
self.assertIn(
ICollectionFilterBrowserLayer,
utils.registered_layers())

class TestUninstall(unittest.TestCase):

layer = COLLECTIVE_COLLECTIONFILTER_INTEGRATION_TESTING

def setUp(self):
self.portal = self.layer['portal']
self.installer = get_installer(self.portal, self.layer['request'])
roles_before = api.user.get_roles(TEST_USER_ID)
setRoles(self.portal, TEST_USER_ID, ['Manager'])
self.installer.uninstall_product('collective.collectionfilter')
setRoles(self.portal, TEST_USER_ID, roles_before)

def test_product_uninstalled(self):
"""Test if collective.collectionfilter is cleanly uninstalled."""
self.assertFalse(self.installer.is_product_installed(
'collective.collectionfilter'))

def test_browserlayer_removed(self):
"""Test that ICollectionFilterBrowserLayer is removed."""
from collective.collectionfilter.interfaces import \
ICollectionFilterBrowserLayer
from plone.browserlayer import utils
self.assertNotIn(
ICollectionFilterBrowserLayer,
utils.registered_layers())
# Quick shim for 5.1 api change

class get_installer(object):
def __init__(self, portal, request):
self.installer = getToolByName(portal, 'portal_quickinstaller')

def is_product_installed(self, name):
return self.installer.isProductInstalled(name)

def uninstall_product(self, name):
return self.installer.uninstallProducts([name])


class TestSetup(unittest.TestCase):
"""Test that collective.collectionfilter is properly installed."""

layer = COLLECTIVE_COLLECTIONFILTER_INTEGRATION_TESTING

def setUp(self):
"""Custom shared utility setup for tests."""
self.portal = self.layer['portal']
self.installer = get_installer(self.portal, self.layer['request'])

def test_product_installed(self):
"""Test if collective.collectionfilter is installed."""
self.assertTrue(self.installer.is_product_installed(
'collective.collectionfilter'))

def test_browserlayer(self):
"""Test that ICollectionFilterBrowserLayer is registered."""
from collective.collectionfilter.interfaces import (
ICollectionFilterBrowserLayer)
from plone.browserlayer import utils
self.assertIn(
ICollectionFilterBrowserLayer,
utils.registered_layers())


class TestUninstall(unittest.TestCase):

layer = COLLECTIVE_COLLECTIONFILTER_INTEGRATION_TESTING

def setUp(self):
self.portal = self.layer['portal']
self.installer = get_installer(self.portal, self.layer['request'])
roles_before = api.user.get_roles(TEST_USER_ID)
setRoles(self.portal, TEST_USER_ID, ['Manager'])
self.installer.uninstall_product('collective.collectionfilter')
setRoles(self.portal, TEST_USER_ID, roles_before)

def test_product_uninstalled(self):
"""Test if collective.collectionfilter is cleanly uninstalled."""
self.assertFalse(self.installer.is_product_installed(
'collective.collectionfilter'))

def test_browserlayer_removed(self):
"""Test that ICollectionFilterBrowserLayer is removed."""
from collective.collectionfilter.interfaces import \
ICollectionFilterBrowserLayer
from plone.browserlayer import utils
self.assertNotIn(
ICollectionFilterBrowserLayer,
utils.registered_layers())

0 comments on commit 4bb09f9

Please sign in to comment.