From d03886c6dfdbdfff8129af868cbd5e8418f4e48c Mon Sep 17 00:00:00 2001 From: Maurits van Rees Date: Fri, 21 Nov 2025 13:34:19 +0100 Subject: [PATCH 1/2] 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 https://github.com/zopefoundation/Products.ZCatalog/issues/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. --- news/+130d79d1.tests.rst | 1 + .../app/querystring/tests/testQueryBuilder.py | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 news/+130d79d1.tests.rst diff --git a/news/+130d79d1.tests.rst b/news/+130d79d1.tests.rst new file mode 100644 index 0000000..091c601 --- /dev/null +++ b/news/+130d79d1.tests.rst @@ -0,0 +1 @@ +Fix tests for ``not`` queries in ``Products.ZCatalog`` 7.2.0+. [maurits] diff --git a/src/plone/app/querystring/tests/testQueryBuilder.py b/src/plone/app/querystring/tests/testQueryBuilder.py index 6a79bf0..5bfcaaa 100644 --- a/src/plone/app/querystring/tests/testQueryBuilder.py +++ b/src/plone/app/querystring/tests/testQueryBuilder.py @@ -123,8 +123,12 @@ def testMakeQueryWithSubjectNot(self): } ] results = self.querybuilder._makequery(query=query) - self.assertEqual(len(results), 1) - self.assertEqual(results[0].getURL(), "http://nohost/plone/testfolder") + # We used to expect 1 result. But in fact the Plone Site should also + # be in the results. This happens since Products.ZCatalog 7.2.0. + self.assertEqual( + sorted([brain.getURL() for brain in results]), + ["http://nohost/plone", "http://nohost/plone/testfolder"], + ) def testMakeQueryWithMultipleSubject(self): self.testpage.setSubject(["Lorem"]) @@ -153,8 +157,12 @@ def testMakeQueryWithMultipleSubjectNot(self): } ] results = self.querybuilder._makequery(query=query) - self.assertEqual(len(results), 1) - self.assertEqual(results[0].getURL(), "http://nohost/plone/testfolder") + # We used to expect 1 result. But in fact the Plone Site should also + # be in the results. This happens since Products.ZCatalog 7.2.0. + self.assertEqual( + sorted([brain.getURL() for brain in results]), + ["http://nohost/plone", "http://nohost/plone/testfolder"], + ) def testMakeQueryWithSubjectWithSpecialCharacters(self): self.testpage.setSubject(["Äüö"]) From e82d5a95163aefdb2eda8df94e96ab2c12b5f02b Mon Sep 17 00:00:00 2001 From: wesleybl Date: Mon, 23 Feb 2026 22:22:30 -0300 Subject: [PATCH 2/2] Make test tolerant to Products.ZCatalog 7.2.0 behavior The tests testMakeQueryWithSubjectNot and testMakeQueryWithMultipleSubjectNot previously asserted exact result URLs. Products.ZCatalog >= 7.2.0 may include the Plone site in results; update the test to only assert that the page with subject Lorem (self.testpage) is not present in the results to keep compatibility across ZCatalog versions. --- .../app/querystring/tests/testQueryBuilder.py | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/plone/app/querystring/tests/testQueryBuilder.py b/src/plone/app/querystring/tests/testQueryBuilder.py index 5bfcaaa..6e41700 100644 --- a/src/plone/app/querystring/tests/testQueryBuilder.py +++ b/src/plone/app/querystring/tests/testQueryBuilder.py @@ -123,11 +123,13 @@ def testMakeQueryWithSubjectNot(self): } ] results = self.querybuilder._makequery(query=query) - # We used to expect 1 result. But in fact the Plone Site should also - # be in the results. This happens since Products.ZCatalog 7.2.0. - self.assertEqual( - sorted([brain.getURL() for brain in results]), - ["http://nohost/plone", "http://nohost/plone/testfolder"], + # Since Products.ZCatalog 7.2.0 the Plone Site is also returned. + # To keep the test compatible with both older and newer versions, + # only assert that the page with subject 'Lorem' is not part of the + # results (the presence of the Plone site itself may vary by ZCatalog + # version). + self.assertNotIn( + self.testpage.absolute_url(), [brain.getURL() for brain in results] ) def testMakeQueryWithMultipleSubject(self): @@ -157,11 +159,13 @@ def testMakeQueryWithMultipleSubjectNot(self): } ] results = self.querybuilder._makequery(query=query) - # We used to expect 1 result. But in fact the Plone Site should also - # be in the results. This happens since Products.ZCatalog 7.2.0. - self.assertEqual( - sorted([brain.getURL() for brain in results]), - ["http://nohost/plone", "http://nohost/plone/testfolder"], + # Since Products.ZCatalog 7.2.0 the Plone Site is also returned. + # To keep the test compatible with both older and newer versions, + # only assert that the page with subject 'Lorem' is not part of the + # results (the presence of the Plone site itself may vary by ZCatalog + # version). + self.assertNotIn( + self.testpage.absolute_url(), [brain.getURL() for brain in results] ) def testMakeQueryWithSubjectWithSpecialCharacters(self):