|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +"""Setup tests for this package.""" |
| 3 | +from cusy.cms.testing import INTEGRATION_TESTING |
| 4 | +from plone import api |
| 5 | +from plone.app.testing import setRoles |
| 6 | +from plone.app.testing import TEST_USER_ID |
| 7 | + |
| 8 | +import unittest |
| 9 | + |
| 10 | + |
| 11 | +try: |
| 12 | + from Products.CMFPlone.utils import get_installer |
| 13 | +except ImportError: |
| 14 | + get_installer = None |
| 15 | + |
| 16 | + |
| 17 | +class TestSetup(unittest.TestCase): |
| 18 | + """Validate that `cusy.cms` is properly installed.""" |
| 19 | + |
| 20 | + layer = INTEGRATION_TESTING |
| 21 | + |
| 22 | + def setUp(self): |
| 23 | + """Custom shared utility setup for tests.""" |
| 24 | + self.portal = self.layer["portal"] |
| 25 | + if get_installer: |
| 26 | + self.installer = get_installer(self.portal, self.layer["request"]) |
| 27 | + else: |
| 28 | + self.installer = api.portal.get_tool("portal_quickinstaller") |
| 29 | + roles_before = api.user.get_roles(TEST_USER_ID) |
| 30 | + setRoles(self.portal, TEST_USER_ID, ["Manager"]) |
| 31 | + self.installer.installProducts(["cusy.cms.packages.subsites"]) |
| 32 | + setRoles(self.portal, TEST_USER_ID, roles_before) |
| 33 | + |
| 34 | + def test_product_installed(self): |
| 35 | + """Validate that `cusy.cms.packages.subsites` is installed.""" |
| 36 | + self.assertTrue(self.installer.isProductInstalled("cusy.cms.packages.subsites")) |
| 37 | + |
| 38 | + def test_browserlayer(self): |
| 39 | + """Validate that the browser layer is registered.""" |
| 40 | + from cusy.cms.packages.subsites.interfaces import ICusyCmsSubsitesLayer |
| 41 | + from plone.browserlayer import utils |
| 42 | + |
| 43 | + self.assertIn(ICusyCmsSubsitesLayer, utils.registered_layers()) |
| 44 | + |
| 45 | + def test_collective_lineage_installed(self): |
| 46 | + """Validate that `collective.lineage` is installed.""" |
| 47 | + self.assertTrue( |
| 48 | + self.installer.isProductInstalled("collective.lineage"), |
| 49 | + ) |
| 50 | + |
| 51 | + def test_lineage_controlpanels_installed(self): |
| 52 | + """Validate that `lineage.controlpanels` is installed.""" |
| 53 | + self.assertTrue(self.installer.isProductInstalled("lineage.controlpanels")) |
| 54 | + |
| 55 | + def test_lineage_registry_installed(self): |
| 56 | + """Validate that `lineage.registry` is installed.""" |
| 57 | + self.assertTrue(self.installer.isProductInstalled("lineage.registry")) |
| 58 | + |
| 59 | + def test_lineage_themeselection_installed(self): |
| 60 | + """Validate that `lineage.themeselection` is installed.""" |
| 61 | + self.assertTrue(self.installer.isProductInstalled("lineage.themeselection")) |
| 62 | + |
| 63 | + |
| 64 | +class TestUninstall(unittest.TestCase): |
| 65 | + |
| 66 | + layer = INTEGRATION_TESTING |
| 67 | + |
| 68 | + def setUp(self): |
| 69 | + self.portal = self.layer["portal"] |
| 70 | + if get_installer: |
| 71 | + self.installer = get_installer(self.portal, self.layer["request"]) |
| 72 | + else: |
| 73 | + self.installer = api.portal.get_tool("portal_quickinstaller") |
| 74 | + roles_before = api.user.get_roles(TEST_USER_ID) |
| 75 | + setRoles(self.portal, TEST_USER_ID, ["Manager"]) |
| 76 | + self.installer.installProducts(["cusy.cms.packages.subsites"]) |
| 77 | + self.installer.uninstallProducts(["cusy.cms.packages.subsites"]) |
| 78 | + setRoles(self.portal, TEST_USER_ID, roles_before) |
| 79 | + |
| 80 | + def test_product_uninstalled(self): |
| 81 | + """Validate that `cusy.cms.packages.subsites` is cleanly uninstalled.""" |
| 82 | + self.assertFalse( |
| 83 | + self.installer.isProductInstalled("cusy.cms.packages.subsites") |
| 84 | + ) |
| 85 | + |
| 86 | + def test_browserlayer_removed(self): |
| 87 | + """Validate that the browser layer is removed.""" |
| 88 | + from cusy.cms.packages.subsites.interfaces import ICusyCmsSubsitesLayer |
| 89 | + from plone.browserlayer import utils |
| 90 | + |
| 91 | + self.assertNotIn(ICusyCmsSubsitesLayer, utils.registered_layers()) |
0 commit comments