Skip to content

Commit d03886c

Browse files
mauritsvanreeswesleybl
authored andcommitted
Fix tests for not queries in Products.ZCatalog 7.2.0+.
See for example this [failure on Jenkins](https://jenkins.plone.org/job/pull-request-6.2-3.13/426/testReport/junit/plone.app.querystring.tests.testQueryBuilder/TestQuerybuilder/testMakeQueryWithMultipleSubjectNot/). The test created two content items with Subjects, and querying for all items without a specific Subject. This used to return 1 item. But now it returns 2, because the Plone Site object is also returned, which has no Subject set. This object used to be ignored in the catalog. See zopefoundation/Products.ZCatalog#148 What is a bit strange, is that the 'not' query does not return any results when I run it at the beginning of this test, so before any item with this Subject has been set. That might be a problem in ZCatalog still.
1 parent d0deaaa commit d03886c

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

news/+130d79d1.tests.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix tests for ``not`` queries in ``Products.ZCatalog`` 7.2.0+. [maurits]

src/plone/app/querystring/tests/testQueryBuilder.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,12 @@ def testMakeQueryWithSubjectNot(self):
123123
}
124124
]
125125
results = self.querybuilder._makequery(query=query)
126-
self.assertEqual(len(results), 1)
127-
self.assertEqual(results[0].getURL(), "http://nohost/plone/testfolder")
126+
# We used to expect 1 result. But in fact the Plone Site should also
127+
# be in the results. This happens since Products.ZCatalog 7.2.0.
128+
self.assertEqual(
129+
sorted([brain.getURL() for brain in results]),
130+
["http://nohost/plone", "http://nohost/plone/testfolder"],
131+
)
128132

129133
def testMakeQueryWithMultipleSubject(self):
130134
self.testpage.setSubject(["Lorem"])
@@ -153,8 +157,12 @@ def testMakeQueryWithMultipleSubjectNot(self):
153157
}
154158
]
155159
results = self.querybuilder._makequery(query=query)
156-
self.assertEqual(len(results), 1)
157-
self.assertEqual(results[0].getURL(), "http://nohost/plone/testfolder")
160+
# We used to expect 1 result. But in fact the Plone Site should also
161+
# be in the results. This happens since Products.ZCatalog 7.2.0.
162+
self.assertEqual(
163+
sorted([brain.getURL() for brain in results]),
164+
["http://nohost/plone", "http://nohost/plone/testfolder"],
165+
)
158166

159167
def testMakeQueryWithSubjectWithSpecialCharacters(self):
160168
self.testpage.setSubject(["Äüö"])

0 commit comments

Comments
 (0)