Skip to content

Commit

Permalink
Merge pull request #100 from plone/move-to-restapi
Browse files Browse the repository at this point in the history
move ruleset assignments to plone.restapi
  • Loading branch information
jensens authored May 10, 2022
2 parents 9843fd4 + 0527f84 commit f41fb7c
Show file tree
Hide file tree
Showing 7 changed files with 5 additions and 287 deletions.
2 changes: 2 additions & 0 deletions news/100.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Move caching ruleset assignments from here to plone.restapi and add ZCML feature here.
[jensens]
41 changes: 0 additions & 41 deletions plone/app/caching/caching.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -124,47 +124,6 @@
ruleset="plone.content.file"
/>

<!-- plone.restapi content -->
<configure zcml:condition="installed plone.restapi">

<include package="plone.restapi" />

<cache:ruleset
for="plone.restapi.services.discussion.conversation.CommentsGet"
ruleset="plone.content.itemView"
/>

<cache:ruleset
for="plone.restapi.services.actions.get.ActionsGet"
ruleset="plone.content.dynamic"
/>
<cache:ruleset
for="plone.restapi.services.breadcrumbs.get.BreadcrumbsGet"
ruleset="plone.content.dynamic"
/>
<cache:ruleset
for="plone.restapi.services.content.get.ContentGet"
ruleset="plone.content.dynamic"
/>
<cache:ruleset
for="plone.restapi.services.multilingual.pam.TranslationInfo"
ruleset="plone.content.dynamic"
/>
<cache:ruleset
for="plone.restapi.services.navigation.get.NavigationGet"
ruleset="plone.content.dynamic"
/>
<cache:ruleset
for="plone.restapi.services.querystring.get.QuerystringGet"
ruleset="plone.content.dynamic"
/>
<cache:ruleset
for="plone.restapi.services.search.get.SearchGet"
ruleset="plone.content.dynamic"
/>

</configure>

<!-- Paths to purge -->

<!-- Standard CMF content -->
Expand Down
3 changes: 3 additions & 0 deletions plone/app/caching/configure.zcml
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:meta="http://namespaces.zope.org/meta"
xmlns:zcml="http://namespaces.zope.org/zcml"
i18n_domain="plone"
>

<meta:provides feature="plone-app-caching-3" />

<include
package="z3c.zcmlhook"
file="meta.zcml"
Expand Down
12 changes: 0 additions & 12 deletions plone/app/caching/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from plone.app.testing import PloneSandboxLayer
from plone.cachepurging.interfaces import IPurger
from plone.protect.authenticator import _getKeyring
from plone.restapi.testing import PLONE_RESTAPI_DX_PAM_FIXTURE
from plone.testing import z2
from zope.component import getUtility
from zope.component import provideUtility
Expand Down Expand Up @@ -63,13 +62,7 @@ class PloneAppCaching(PloneAppCachingBase):
defaultBases = (PLONE_APP_CONTENTTYPES_FIXTURE,)


class PloneAppCachingRestAPI(PloneAppCachingBase):

defaultBases = (PLONE_RESTAPI_DX_PAM_FIXTURE,)


PLONE_APP_CACHING_FIXTURE = PloneAppCaching()
PLONE_APP_CACHING_RESTAPI_FIXTURE = PloneAppCachingRestAPI()
PLONE_APP_CACHING_INTEGRATION_TESTING = IntegrationTesting(
bases=(PLONE_APP_CACHING_FIXTURE,),
name="PloneAppCaching:Integration",
Expand All @@ -79,11 +72,6 @@ class PloneAppCachingRestAPI(PloneAppCachingBase):
name="PloneAppCaching:Functional",
)

PLONE_APP_CACHING_FUNCTIONAL_RESTAPI_TESTING = FunctionalTesting(
bases=(PLONE_APP_CACHING_RESTAPI_FIXTURE, z2.ZSERVER_FIXTURE),
name="PloneAppCachingRestAPI:Functional",
)


def getToken(username):
ring = _getKeyring(username)
Expand Down
118 changes: 0 additions & 118 deletions plone/app/caching/tests/test_profile_with_caching_proxy.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from io import BytesIO
from plone.app.caching.interfaces import IPloneCacheSettings
from plone.app.caching.testing import PLONE_APP_CACHING_FUNCTIONAL_RESTAPI_TESTING
from plone.app.caching.testing import PLONE_APP_CACHING_FUNCTIONAL_TESTING
from plone.app.caching.tests.test_utils import normalize_etag
from plone.app.caching.tests.test_utils import stable_now
Expand All @@ -17,7 +16,6 @@
from plone.cachepurging.interfaces import IPurger
from plone.caching.interfaces import ICacheSettings
from plone.registry.interfaces import IRegistry
from plone.restapi.testing import RelativeSession
from plone.testing.z2 import Browser
from Products.CMFCore.FSFile import FSFile
from Products.CMFCore.utils import getToolByName
Expand Down Expand Up @@ -603,119 +601,3 @@ def test_stable_resources(self):
# What is the best way to test this?
# Maybe not important since the RR test exercises the same code?
pass


class TestProfileWithCachingRestAPI(unittest.TestCase):
"""This test aims to exercise the caching operations expected from the
`with-caching-proxy` profile for supported restapi calls.
"""

layer = PLONE_APP_CACHING_FUNCTIONAL_RESTAPI_TESTING

def setUp(self):
self.app = self.layer["app"]
self.portal = self.layer["portal"]

test_css = FSFile(
"test.css", os.path.join(os.path.dirname(__file__), "test.css")
)
self.portal.portal_skins.custom._setOb("test.css", test_css)

setRequest(self.portal.REQUEST)

applyProfile(self.portal, "plone.app.caching:with-caching-proxy")

self.registry = getUtility(IRegistry)

self.cacheSettings = self.registry.forInterface(ICacheSettings)
self.cachePurgingSettings = self.registry.forInterface(ICachePurgingSettings)
self.ploneCacheSettings = self.registry.forInterface(IPloneCacheSettings)

self.cacheSettings.enabled = True

self.purger = getUtility(IPurger)
self.purger.reset()

# some test content
setRoles(self.portal, TEST_USER_ID, ("Manager",))

self.portal.invokeFactory("Folder", "f1")
self.portal["f1"].title = "Folder one"
self.portal.portal_workflow.doActionFor(self.portal["f1"], "publish")

self.portal["f1"].invokeFactory("Folder", "f2")
self.portal["f1"]["f2"].title = "Folder one sub one"
self.portal.portal_workflow.doActionFor(self.portal["f1"]["f2"], "publish")

self.portal.invokeFactory("Collection", "c")
self.portal["c"].title = "A Collection"
self.portal.portal_workflow.doActionFor(self.portal["c"], "publish")

transaction.commit()

# restapi test session
self.api_session = RelativeSession(self.layer["portal"].absolute_url())
self.api_session.headers.update({"Accept": "application/json"})

def test_restapi_actions(self):
# plone.content.dynamic for plone.restapi.services.actions.get.ActionsGet
response = self.api_session.get("/f1/f2/@actions")
self.assertEqual(response.status_code, 200)
self.assertEqual(response.headers["X-Cache-Rule"], "plone.content.dynamic")
self.assertEqual(
response.headers["X-Cache-Operation"], "plone.app.caching.terseCaching"
)

def test_restapi_breadcrumbs(self):
# plone.content.dynamic for plone.restapi.services.breadcrumbs.get.BreadcrumbsGet
response = self.api_session.get("/f1/f2/@breadcrumbs")
self.assertEqual(response.status_code, 200)
self.assertEqual(response.headers["X-Cache-Rule"], "plone.content.dynamic")
self.assertEqual(
response.headers["X-Cache-Operation"], "plone.app.caching.terseCaching"
)

def test_restapi_comments(self):
# plone.content.itemView for plone.restapi.services.discussion.conversation.CommentsGet
response = self.api_session.get("/f1/f2/@comments")
self.assertEqual(response.status_code, 200)
self.assertEqual(response.headers["X-Cache-Rule"], "plone.content.itemView")
self.assertEqual(
response.headers["X-Cache-Operation"], "plone.app.caching.weakCaching"
)

def test_restapi_content(self):
# plone.content.dynamic for plone.restapi.services.content.get.ContentGet
response = self.api_session.get("/f1/f2")
self.assertEqual(response.status_code, 200)
self.assertEqual(response.headers["X-Cache-Rule"], "plone.content.dynamic")
self.assertEqual(
response.headers["X-Cache-Operation"], "plone.app.caching.terseCaching"
)

def test_restapi_navigation(self):
# plone.content.dynamic for plone.restapi.services.navigation.get.NavigationGet
response = self.api_session.get("/f1/f2/@navigation")
self.assertEqual(response.status_code, 200)
self.assertEqual(response.headers["X-Cache-Rule"], "plone.content.dynamic")
self.assertEqual(
response.headers["X-Cache-Operation"], "plone.app.caching.terseCaching"
)

def test_restapi_querystring(self):
# plone.content.dynamic for plone.restapi.services.querystring.get.QueryStringGet
response = self.api_session.get("/@querystring")
self.assertEqual(response.status_code, 200)
self.assertEqual(response.headers["X-Cache-Rule"], "plone.content.dynamic")
self.assertEqual(
response.headers["X-Cache-Operation"], "plone.app.caching.terseCaching"
)

def test_restapi_search(self):
# plone.content.dynamic for plone.restapi.services.search.get.SearchGet
response = self.api_session.get("/@search")
self.assertEqual(response.status_code, 200)
self.assertEqual(response.headers["X-Cache-Rule"], "plone.content.dynamic")
self.assertEqual(
response.headers["X-Cache-Operation"], "plone.app.caching.terseCaching"
)
115 changes: 0 additions & 115 deletions plone/app/caching/tests/test_profile_without_caching_proxy.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from plone.app.caching.interfaces import IPloneCacheSettings
from plone.app.caching.testing import PLONE_APP_CACHING_FUNCTIONAL_RESTAPI_TESTING
from plone.app.caching.testing import PLONE_APP_CACHING_FUNCTIONAL_TESTING
from plone.app.caching.tests.test_utils import normalize_etag
from plone.app.caching.tests.test_utils import stable_now
Expand All @@ -13,7 +12,6 @@
from plone.cachepurging.interfaces import ICachePurgingSettings
from plone.caching.interfaces import ICacheSettings
from plone.registry.interfaces import IRegistry
from plone.restapi.testing import RelativeSession
from plone.testing.z2 import Browser
from Products.CMFCore.FSFile import FSFile
from Products.CMFCore.utils import getToolByName
Expand Down Expand Up @@ -508,116 +506,3 @@ def test_stable_resources(self):
# What is the best way to test this?
# Maybe not important since the RR test exercises the same code?
pass


class TestProfileWithoutCachingRestAPI(unittest.TestCase):
"""This test aims to exercise the caching operations expected from the
`without-caching-proxy` profile for supported restapi calls.
"""

layer = PLONE_APP_CACHING_FUNCTIONAL_RESTAPI_TESTING

def setUp(self):
self.app = self.layer["app"]
self.portal = self.layer["portal"]

test_css = FSFile(
"test.css", os.path.join(os.path.dirname(__file__), "test.css")
)
self.portal.portal_skins.custom._setOb("test.css", test_css)

setRequest(self.portal.REQUEST)

applyProfile(self.portal, "plone.app.caching:without-caching-proxy")

self.registry = getUtility(IRegistry)

self.cacheSettings = self.registry.forInterface(ICacheSettings)
self.cachePurgingSettings = self.registry.forInterface(ICachePurgingSettings)
self.ploneCacheSettings = self.registry.forInterface(IPloneCacheSettings)

self.cacheSettings.enabled = True

# some test content
setRoles(self.portal, TEST_USER_ID, ("Manager",))

self.portal.invokeFactory("Folder", "f1")
self.portal["f1"].title = "Folder one"
self.portal.portal_workflow.doActionFor(self.portal["f1"], "publish")

self.portal["f1"].invokeFactory("Folder", "f2")
self.portal["f1"]["f2"].title = "Folder one sub one"
self.portal.portal_workflow.doActionFor(self.portal["f1"]["f2"], "publish")

self.portal.invokeFactory("Collection", "c")
self.portal["c"].title = "A Collection"
self.portal.portal_workflow.doActionFor(self.portal["c"], "publish")

transaction.commit()

# restapi test session
self.api_session = RelativeSession(self.layer["portal"].absolute_url())
self.api_session.headers.update({"Accept": "application/json"})

def test_restapi_actions(self):
# plone.content.dynamic for plone.restapi.services.actions.get.ActionsGet
response = self.api_session.get("/f1/f2/@actions")
self.assertEqual(response.status_code, 200)
self.assertEqual(response.headers["X-Cache-Rule"], "plone.content.dynamic")
self.assertEqual(
response.headers["X-Cache-Operation"], "plone.app.caching.terseCaching"
)

def test_restapi_breadcrumbs(self):
# plone.content.dynamic for plone.restapi.services.breadcrumbs.get.BreadcrumbsGet
response = self.api_session.get("/f1/f2/@breadcrumbs")
self.assertEqual(response.status_code, 200)
self.assertEqual(response.headers["X-Cache-Rule"], "plone.content.dynamic")
self.assertEqual(
response.headers["X-Cache-Operation"], "plone.app.caching.terseCaching"
)

def test_restapi_comments(self):
# plone.content.itemView for plone.restapi.services.discussion.conversation.CommentsGet
response = self.api_session.get("/f1/f2/@comments")
self.assertEqual(response.status_code, 200)
self.assertEqual(response.headers["X-Cache-Rule"], "plone.content.itemView")
self.assertEqual(
response.headers["X-Cache-Operation"], "plone.app.caching.weakCaching"
)

def test_restapi_content(self):
# plone.content.dynamic for plone.restapi.services.content.get.ContentGet
response = self.api_session.get("/f1/f2")
self.assertEqual(response.status_code, 200)
self.assertEqual(response.headers["X-Cache-Rule"], "plone.content.dynamic")
self.assertEqual(
response.headers["X-Cache-Operation"], "plone.app.caching.terseCaching"
)

def test_restapi_navigation(self):
# plone.content.dynamic for plone.restapi.services.navigation.get.NavigationGet
response = self.api_session.get("/f1/f2/@navigation")
self.assertEqual(response.status_code, 200)
self.assertEqual(response.headers["X-Cache-Rule"], "plone.content.dynamic")
self.assertEqual(
response.headers["X-Cache-Operation"], "plone.app.caching.terseCaching"
)

def test_restapi_querystring(self):
# plone.content.dynamic for plone.restapi.services.querystring.get.QueryStringGet
response = self.api_session.get("/@querystring")
self.assertEqual(response.status_code, 200)
self.assertEqual(response.headers["X-Cache-Rule"], "plone.content.dynamic")
self.assertEqual(
response.headers["X-Cache-Operation"], "plone.app.caching.terseCaching"
)

def test_restapi_search(self):
# plone.content.dynamic for plone.restapi.services.search.get.SearchGet
response = self.api_session.get("/@search")
self.assertEqual(response.status_code, 200)
self.assertEqual(response.headers["X-Cache-Rule"], "plone.content.dynamic")
self.assertEqual(
response.headers["X-Cache-Operation"], "plone.app.caching.terseCaching"
)
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
"test": [
"plone.app.contenttypes[test]",
"plone.app.testing",
"plone.restapi[test]",
]
},
entry_points="""
Expand Down

0 comments on commit f41fb7c

Please sign in to comment.