diff --git a/news/1983.internal b/news/1983.internal new file mode 100644 index 000000000..b3e2146d3 --- /dev/null +++ b/news/1983.internal @@ -0,0 +1 @@ +Consolidate test layers so PAM, Iterate, Blocks, and Workflows all share `PLONE_RESTAPI_DX_FIXTURE` as base, reducing redundant layer setup time. @jensens diff --git a/src/plone/restapi/testing.py b/src/plone/restapi/testing.py index a6da8c215..b24cb1389 100644 --- a/src/plone/restapi/testing.py +++ b/src/plone/restapi/testing.py @@ -3,7 +3,6 @@ from plone.app.contenttypes.testing import PLONE_APP_CONTENTTYPES_FIXTURE from plone.app.i18n.locales.interfaces import IContentLanguages from plone.app.i18n.locales.interfaces import IMetadataLanguages -from plone.app.iterate.testing import PLONEAPPITERATEDEX_FIXTURE from plone.app.testing import applyProfile from plone.app.testing import FunctionalTesting from plone.app.testing import IntegrationTesting @@ -174,33 +173,11 @@ def setUpPloneSite(self, portal): class PloneRestApiDXPAMLayer(PloneSandboxLayer): - defaultBases = (DATE_TIME_FIXTURE, PLONE_APP_CONTENTTYPES_FIXTURE) - - def setUpZope(self, app, configurationContext): - import plone.restapi - - xmlconfig.file("configure.zcml", plone.restapi, context=configurationContext) - xmlconfig.file("testing.zcml", plone.restapi, context=configurationContext) - - zope.installProduct(app, "plone.restapi") + defaultBases = (PLONE_RESTAPI_DX_FIXTURE,) def setUpPloneSite(self, portal): - portal.acl_users.userFolderAddUser( - SITE_OWNER_NAME, SITE_OWNER_PASSWORD, ["Manager"], [] - ) - login(portal, SITE_OWNER_NAME) - setRoles(portal, TEST_USER_ID, ["Manager"]) - - set_supported_languages(portal) if portal.portal_setup.profileExists("plone.app.multilingual:default"): applyProfile(portal, "plone.app.multilingual:default") - applyProfile(portal, "plone.restapi:default") - applyProfile(portal, "plone.restapi:testing") - add_catalog_indexes(portal, DX_TYPES_INDEXES) - set_available_languages() - enable_request_language_negotiation(portal) - states = portal.portal_workflow["simple_publication_workflow"].states - states["published"].title = "Published with accent é" # noqa: E501 PLONE_RESTAPI_DX_PAM_FIXTURE = PloneRestApiDXPAMLayer() @@ -238,15 +215,34 @@ class PloneRestApiCachingLayer(PloneAppCachingBase): class PloneRestApiDXIterateLayer(PloneSandboxLayer): - defaultBases = (PLONEAPPITERATEDEX_FIXTURE,) + defaultBases = (PLONE_RESTAPI_DX_FIXTURE,) def setUpZope(self, app, configurationContext): - import plone.restapi + import plone.app.iterate - xmlconfig.file("configure.zcml", plone.restapi, context=configurationContext) - xmlconfig.file("testing.zcml", plone.restapi, context=configurationContext) + self.loadZCML(package=plone.app.iterate) + # Newer plone.app.iterate has tests ZCML + try: + import plone.app.iterate.tests - zope.installProduct(app, "plone.restapi") + self.loadZCML(package=plone.app.iterate.tests) + except (ImportError, FileNotFoundError): + pass + + def setUpPloneSite(self, portal): + applyProfile(portal, "plone.app.iterate:default") + # Profile name changed in newer plone.app.iterate + if portal.portal_setup.profileExists("plone.app.iterate.tests:testingdx"): + applyProfile(portal, "plone.app.iterate.tests:testingdx") + elif portal.portal_setup.profileExists("plone.app.iterate:testingdx"): + applyProfile(portal, "plone.app.iterate:testingdx") + # Disable automatic versioning of Documents. + versioning_behavior = { + "plone.app.versioningbehavior.behaviors.IVersionable", + "plone.versioning", + } + fti = portal.portal_types["Document"] + fti.behaviors = tuple(set(fti.behaviors).difference(versioning_behavior)) PLONE_RESTAPI_ITERATE_FIXTURE = PloneRestApiDXIterateLayer() diff --git a/src/plone/restapi/tests/test_boolean_value.py b/src/plone/restapi/tests/test_boolean_value.py index ea38772e0..fd5abc1d0 100644 --- a/src/plone/restapi/tests/test_boolean_value.py +++ b/src/plone/restapi/tests/test_boolean_value.py @@ -1,12 +1,12 @@ from plone.restapi.deserializer import boolean_value -from plone.restapi.testing import PLONE_RESTAPI_DX_FUNCTIONAL_TESTING +from plone.restapi.testing import PLONE_RESTAPI_DX_INTEGRATION_TESTING import unittest class TestBooleanValue(unittest.TestCase): - layer = PLONE_RESTAPI_DX_FUNCTIONAL_TESTING + layer = PLONE_RESTAPI_DX_INTEGRATION_TESTING def test_true_bool(self): self.assertTrue(boolean_value(True)) diff --git a/src/plone/restapi/tests/test_dxfield_publication.py b/src/plone/restapi/tests/test_dxfield_publication.py index 9ef2b8c59..7c1c201d2 100644 --- a/src/plone/restapi/tests/test_dxfield_publication.py +++ b/src/plone/restapi/tests/test_dxfield_publication.py @@ -3,7 +3,6 @@ from plone.restapi.interfaces import IDeserializeFromJson from plone.restapi.interfaces import ISerializeToJson from plone.restapi.testing import PLONE_RESTAPI_DX_INTEGRATION_TESTING -from transaction import commit from zope.component import getMultiAdapter from zope.component import getUtility @@ -45,8 +44,6 @@ def setUp(self): self.app = self.layer["app"] self.portal = self.layer["portal"] - commit() - def tearDown(self): os.environ["TZ"] = "UTC" time.tzset() diff --git a/src/plone/restapi/tests/test_indexers.py b/src/plone/restapi/tests/test_indexers.py index 671a6836b..8ed8fa205 100644 --- a/src/plone/restapi/tests/test_indexers.py +++ b/src/plone/restapi/tests/test_indexers.py @@ -1,5 +1,5 @@ from plone.dexterity.interfaces import IDexterityFTI -from plone.restapi.testing import PLONE_RESTAPI_BLOCKS_FUNCTIONAL_TESTING +from plone.restapi.testing import PLONE_RESTAPI_BLOCKS_INTEGRATION_TESTING from Products.CMFCore.utils import getToolByName from uuid import uuid4 from zope.component import queryUtility @@ -89,7 +89,7 @@ class TestSearchableTextIndexer(unittest.TestCase): - layer = PLONE_RESTAPI_BLOCKS_FUNCTIONAL_TESTING + layer = PLONE_RESTAPI_BLOCKS_INTEGRATION_TESTING def setUp(self): self.portal = self.layer["portal"]