Skip to content

Commit

Permalink
Revert "Fix plone.api.content.find to respect object_provides "not" q…
Browse files Browse the repository at this point in the history
…ueries."

This reverts commit 92a7875.
  • Loading branch information
thet committed Feb 26, 2021
1 parent 92a7875 commit 8f65333
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 97 deletions.
3 changes: 0 additions & 3 deletions news/452.bugfix

This file was deleted.

33 changes: 8 additions & 25 deletions src/plone/api/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,35 +594,18 @@ def _parse_object_provides_query(query):
query for multiple values
(eg. `{'query': [Iface1, Iface2], 'operator': 'or'}`)
"""
ifaces = query
operator = 'or'
query_not = []

ifaces = query
if isinstance(query, dict):
ifaces = query.get('query', [])
operator = query.get('operator', operator)
query_not = query.get('not', [])
# KeywordIndex also supports "range",
# but that's not useful for querying object_provides

if not isinstance(ifaces, (list, tuple)):
ifaces = [ifaces]
ifaces = [getattr(x, '__identifier__', x) for x in ifaces]

if not isinstance(query_not, (list, tuple)):
query_not = [query_not]
query_not = [getattr(x, '__identifier__', x) for x in query_not]

result = {}

if ifaces:
result['query'] = ifaces
result['operator'] = operator

if query_not:
result['not'] = query_not
ifaces = query.get('query', [])
elif not isinstance(query, (list, tuple)):
ifaces = [query]

return result
return {
'query': [getattr(x, '__identifier__', x) for x in ifaces],
'operator': operator,
}


def find(context=None, depth=None, **kwargs):
Expand Down
69 changes: 0 additions & 69 deletions src/plone/api/tests/test_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from OFS.event import ObjectWillBeMovedEvent
from OFS.interfaces import IObjectWillBeMovedEvent
from plone import api
from plone.api.content import _parse_object_provides_query
from plone.api.content import NEW_LINKINTEGRITY
from plone.api.tests.base import INTEGRATION_TESTING
from plone.app.layout.navigation.interfaces import INavigationRoot
Expand Down Expand Up @@ -1050,74 +1049,6 @@ def test_find_interface_dict(self):
)
self.assertEqual(len(brains), 1)

def test_find_interface_dict__include_not_query(self):
"""Check if not query in object_provides is functional.
"""

brains_all = api.content.find(
object_provides={'query': IContentish.__identifier__},
)

alsoProvides(self.portal.events, INavigationRoot)
self.portal.events.reindexObject(idxs=['object_provides'])

brains = api.content.find(
object_provides={
'query': IContentish.__identifier__,
'not': INavigationRoot.__identifier__
},
)

self.assertEqual(len(brains_all) - len(brains), 1)

def test_find_interface_dict__all_options(self):
""" Check for all options in a object_provides query are correctly
transformed.
"""
parser = _parse_object_provides_query

self.assertDictEqual(
parser({'query': IContentish}),
{'query': [IContentish.__identifier__], 'operator': 'or'},
)

self.assertDictEqual(
parser(
{
'query': [IContentish, INavigationRoot.__identifier__],
'operator': 'and'
}
),
{
'query': [IContentish.__identifier__, INavigationRoot.__identifier__],
'operator': 'and'
},
)

self.assertDictEqual(
parser({'not': IContentish}),
{'not': [IContentish.__identifier__]},
)

self.assertDictEqual(
parser({'not': [IContentish, INavigationRoot.__identifier__]}),
{'not': [IContentish.__identifier__, INavigationRoot.__identifier__]},
)

self.assertDictEqual(
parser({'not': IContentish}),
{'not': [IContentish.__identifier__]},
)

self.assertDictEqual(
parser({'query': IContentish, 'operator': 'and', 'not': INavigationRoot}),
{
'query': [IContentish.__identifier__],
'operator': 'and',
'not': [INavigationRoot.__identifier__],
},
)

def test_find_dict(self):
# Pass arguments using dict
path = '/'.join(self.portal.about.getPhysicalPath())
Expand Down

0 comments on commit 8f65333

Please sign in to comment.