Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt the tests for Plone 6 #1251

Merged
merged 1 commit into from
Oct 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/1251.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Adapt the test to cope with the fact the since Plone 6 the Plone site root is cataloged [ale-rt]
24 changes: 20 additions & 4 deletions src/plone/restapi/tests/test_blocks_searchable_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ def test_search_text(self):
self.assertEqual(json_response["items_total"], 1)
self.assertEqual(json_response["items"][0]["Title"], "A document")

query = {"SearchableText": "Plone", "metadata_fields": "Title"}
query = {
"SearchableText": "Plone",
"metadata_fields": "Title",
"portal_type": "Document",
}
response = self.api_session.get("/@search", params=query)
json_response = response.json()
self.assertEqual(json_response["items_total"], 1)
Expand Down Expand Up @@ -184,18 +188,30 @@ def test_index_searchableText_value(self):

self.assertEqual(response.status_code, 204)

query = {"SearchableText": "Volto", "metadata_fields": "Title"}
query = {
"SearchableText": "Volto",
"metadata_fields": "Title",
"portal_type": "Document",
}
response = self.api_session.get("/@search", params=query)
json_response = response.json()
self.assertEqual(json_response["items_total"], 0)

query = {"SearchableText": "Plone", "metadata_fields": "Title"}
query = {
"SearchableText": "Plone",
"metadata_fields": "Title",
"portal_type": "Document",
}
response = self.api_session.get("/@search", params=query)
json_response = response.json()
self.assertEqual(json_response["items_total"], 1)
self.assertEqual(json_response["items"][0]["Title"], "A document")

query = {"SearchableText": "custom", "metadata_fields": "Title"}
query = {
"SearchableText": "custom",
"metadata_fields": "Title",
"portal_type": "Document",
}
response = self.api_session.get("/@search", params=query)
json_response = response.json()
self.assertEqual(json_response["items_total"], 1)
Expand Down
37 changes: 33 additions & 4 deletions src/plone/restapi/tests/test_search.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from datetime import date
from DateTime import DateTime
from pkg_resources import get_distribution
from pkg_resources import parse_version
from plone import api
from plone.app.discussion.interfaces import IDiscussionSettings
from plone.app.layout.navigation.interfaces import INavigationRoot
Expand All @@ -21,6 +23,13 @@
import unittest


HAS_PLONE_6 = parse_version(
get_distribution("Products.CMFPlone").version
) >= parse_version(
"6.0.0a1"
)


class TestSearchFunctional(unittest.TestCase):

layer = PLONE_RESTAPI_DX_FUNCTIONAL_TESTING
Expand Down Expand Up @@ -620,7 +629,12 @@ def test_uuid_index_query(self):
def test_respect_access_inactive_permission(self):
# admin can see everything
response = self.api_session.get("/@search", params={}).json()
self.assertEqual(response["items_total"], 6)
if HAS_PLONE_6:
# Since Plone 6 the Plone site is indexed ...
self.assertEqual(response["items_total"], 7)
else:
# ... before it was not
self.assertEqual(response["items_total"], 6)
response = self.api_session.get(
"/@search", params={"Title": "Lorem Ipsum"}
).json()
Expand All @@ -630,7 +644,12 @@ def test_respect_access_inactive_permission(self):
self.api_session.auth = ("editoruser", "secret")

response = self.api_session.get("/@search", params={}).json()
self.assertEqual(response["items_total"], 3)
if HAS_PLONE_6:
# Since Plone 6 the Plone site is indexed ...
self.assertEqual(response["items_total"], 4)
else:
# ... before it was not
self.assertEqual(response["items_total"], 3)
response = self.api_session.get(
"/@search", params={"Title": "Lorem Ipsum"}
).json()
Expand All @@ -644,7 +663,12 @@ def test_respect_access_inactive_permission(self):

#  portal-enabled Editor can see expired contents
response = self.api_session.get("/@search", params={}).json()
self.assertEqual(response["items_total"], 6)
if HAS_PLONE_6:
# Since Plone 6 the Plone site is indexed ...
self.assertEqual(response["items_total"], 7)
else:
# ... before it was not
self.assertEqual(response["items_total"], 6)
response = self.api_session.get(
"/@search", params={"Title": "Lorem Ipsum"}
).json()
Expand All @@ -653,7 +677,12 @@ def test_respect_access_inactive_permission(self):
# local-enabled Editor can only access expired contents inside folder
self.api_session.auth = ("localeditor", "secret")
response = self.api_session.get("/@search", params={}).json()
self.assertEqual(response["items_total"], 1)
if HAS_PLONE_6:
# Since Plone 6 the Plone site is indexed ...
self.assertEqual(response["items_total"], 2)
else:
# ... before it was not
self.assertEqual(response["items_total"], 1)
response = self.api_session.get(
"/@search", params={"path": "/plone/folder"}
).json()
Expand Down
20 changes: 20 additions & 0 deletions src/plone/restapi/tests/test_serializer_catalog.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from DateTime import DateTime
from pkg_resources import get_distribution
from pkg_resources import parse_version
from plone.dexterity.utils import createContentInContainer
from plone.restapi.interfaces import ISerializeToJson
from plone.restapi.interfaces import ISerializeToJsonSummary
Expand All @@ -10,6 +12,13 @@
import unittest


HAS_PLONE_6 = parse_version(
get_distribution("Products.CMFPlone").version
) >= parse_version(
"6.0.0a1"
)


class TestCatalogSerializers(unittest.TestCase):

layer = PLONE_RESTAPI_DX_INTEGRATION_TESTING
Expand Down Expand Up @@ -43,11 +52,22 @@ def test_lazy_cat_serialization_empty_resultset(self):
{"@id": "http://nohost", "items": [], "items_total": 0}, results
)

@unittest.skipUnless(HAS_PLONE_6, "Since Plone 6 the Plone site is indexed ...")
def test_lazy_map_serialization(self):
# Test serialization of a Products.ZCatalog.Lazy.LazyMap
lazy_map = self.catalog()
results = getMultiAdapter((lazy_map, self.request), ISerializeToJson)()

self.assertDictContainsSubset({"@id": "http://nohost"}, results)
self.assertDictContainsSubset({"items_total": 3}, results)
self.assertEqual(3, len(results["items"]))

@unittest.skipIf(HAS_PLONE_6, "... before it was not")
def test_lazy_map_serialization_plone5(self):
# Test serialization of a Products.ZCatalog.Lazy.LazyMap
lazy_map = self.catalog()
results = getMultiAdapter((lazy_map, self.request), ISerializeToJson)()

self.assertDictContainsSubset({"@id": "http://nohost"}, results)
self.assertDictContainsSubset({"items_total": 2}, results)
self.assertEqual(2, len(results["items"]))
Expand Down