def test_extended_path_index_depth_limiting(self): lvl1 = createContentInContainer(self.portal, u'Folder', id=u'lvl1') lvl2 = createContentInContainer(lvl1, u'Folder', id=u'lvl2') createContentInContainer(lvl2, u'Folder', id=u'lvl3') transaction.commit() path = '/plone/lvl1' # Depth 0 - only object identified by path query = {'path.query': path, 'path.depth': 0} response = self.api_session.get('/search', params=query) self.assertEqual( [u'/plone/lvl1'], result_paths(response.json())) # Depth 1 - immediate children query = {'path.query': path, 'path.depth': 1} response = self.api_session.get('/search', params=query) self.assertEqual( [u'/plone/lvl1/lvl2'], result_paths(response.json())) # No depth - object itself and all children query = {'path': path} response = self.api_session.get('/search', params=query) self.assertSetEqual( {u'/plone/lvl1', u'/plone/lvl1/lvl2', u'/plone/lvl1/lvl2/lvl3'}, set(result_paths(response.json())))
def test_extended_path_index_query_multiple(self): # path as a list query = { 'path': [ '/'.join(self.folder.getPhysicalPath()), '/'.join(self.folder2.getPhysicalPath()) ] } response = self.api_session.get('/@search', params=query) self.assertEqual([ u'/plone/folder', u'/plone/folder/doc', u'/plone/folder/other-document', u'/plone/folder2', u'/plone/folder2/doc' ], result_paths(response.json())) # path as a dict with a query list query = { 'path.query': [ '/'.join(self.folder.getPhysicalPath()), '/'.join(self.folder2.getPhysicalPath()) ] } response = self.api_session.get('/@search', params=query) self.assertEqual([ u'/plone/folder', u'/plone/folder/doc', u'/plone/folder/other-document', u'/plone/folder2', u'/plone/folder2/doc' ], result_paths(response.json()))
def test_search_in_vhm(self): # Install a Virtual Host Monster if "virtual_hosting" not in self.app.objectIds(): # If ZopeLite was imported, we have no default virtual # host monster from Products.SiteAccess.VirtualHostMonster import ( manage_addVirtualHostMonster, ) manage_addVirtualHostMonster(self.app, "virtual_hosting") transaction.commit() # we don't get a result if we do not provide the full physical path response = self.api_session.get("/@search?path=/folder") self.assertSetEqual(set(), set(result_paths(response.json()))) # If we go through the VHM will will get results if we only use # the part of the path inside the VHM vhm_url = "{}/VirtualHostBase/http/plone.org/plone/VirtualHostRoot/{}".format( self.app.absolute_url(), "@search?path=/folder", ) response = self.api_session.get(vhm_url) self.assertSetEqual( {"/folder", "/folder/doc", "/folder/other-document"}, set(result_paths(response.json())), )
def test_date_range_index_query(self): query = {"effectiveRange": date(1997, 1, 1).isoformat()} response = self.api_session.get("/folder/@search", params=query) self.assertEqual(2, len(result_paths(response.json()))) self.assertTrue(u"/plone/folder" in result_paths(response.json())) self.assertTrue(u"/plone/folder/doc" in result_paths(response.json()))
def test_extended_path_index_depth_limiting(self): lvl1 = createContentInContainer(self.portal, u"Folder", id=u"lvl1") lvl2 = createContentInContainer(lvl1, u"Folder", id=u"lvl2") createContentInContainer(lvl2, u"Folder", id=u"lvl3") transaction.commit() path = "/plone/lvl1" # Depth 0 - only object identified by path query = {"path.query": path, "path.depth": 0} response = self.api_session.get("/@search", params=query) self.assertEqual([u"/plone/lvl1"], result_paths(response.json())) # Depth 1 - immediate children query = {"path.query": path, "path.depth": 1} response = self.api_session.get("/@search", params=query) self.assertEqual([u"/plone/lvl1/lvl2"], result_paths(response.json())) # No depth - object itself and all children query = {"path": path} response = self.api_session.get("/@search", params=query) self.assertSetEqual( {u"/plone/lvl1", u"/plone/lvl1/lvl2", u"/plone/lvl1/lvl2/lvl3"}, set(result_paths(response.json())), )
def test_search_in_vhm(self): # Install a Virtual Host Monster if 'virtual_hosting' not in self.app.objectIds(): # If ZopeLite was imported, we have no default virtual # host monster from Products.SiteAccess.VirtualHostMonster \ import manage_addVirtualHostMonster manage_addVirtualHostMonster(self.app, 'virtual_hosting') transaction.commit() # we don't get a result if we do not provide the full physical path response = self.api_session.get('/@search?path=/folder',) self.assertSetEqual(set(), set(result_paths(response.json()))) # If we go through the VHM will will get results if we only use # the part of the path inside the VHM vhm_url = ( '%s/VirtualHostBase/http/plone.org/plone/VirtualHostRoot/%s' % (self.app.absolute_url(), '@search?path=/folder')) response = self.api_session.get(vhm_url) self.assertSetEqual( {u'/folder', u'/folder/doc', u'/folder/other-document'}, set(result_paths(response.json())))
def test_extended_path_index_depth_limiting(self): lvl1 = createContentInContainer(self.portal, u'Folder', id=u'lvl1') lvl2 = createContentInContainer(lvl1, u'Folder', id=u'lvl2') createContentInContainer(lvl2, u'Folder', id=u'lvl3') transaction.commit() path = '/plone/lvl1' # Depth 0 - only object identified by path query = {'path.query': path, 'path.depth': 0} response = self.api_session.get('/@search', params=query) self.assertEqual( [u'/plone/lvl1'], result_paths(response.json())) # Depth 1 - immediate children query = {'path.query': path, 'path.depth': 1} response = self.api_session.get('/@search', params=query) self.assertEqual( [u'/plone/lvl1/lvl2'], result_paths(response.json())) # No depth - object itself and all children query = {'path': path} response = self.api_session.get('/@search', params=query) self.assertSetEqual( {u'/plone/lvl1', u'/plone/lvl1/lvl2', u'/plone/lvl1/lvl2/lvl3'}, set(result_paths(response.json())))
def test_boolean_index_query(self): query = {"test_bool_field": True, "portal_type": "DXTestDocument"} response = self.api_session.get("/folder/@search", params=query) self.assertEqual([u"/plone/folder/doc"], result_paths(response.json())) query = {"test_bool_field": False, "portal_type": "DXTestDocument"} response = self.api_session.get("/folder/@search", params=query) self.assertEqual([u"/plone/folder/other-document"], result_paths(response.json()))
def test_boolean_index_query(self): query = {'test_bool_field': True, 'portal_type': 'DXTestDocument'} response = self.api_session.get('/folder/@search', params=query) self.assertEqual([u'/plone/folder/doc'], result_paths(response.json())) query = {'test_bool_field': False, 'portal_type': 'DXTestDocument'} response = self.api_session.get('/folder/@search', params=query) self.assertEqual([u'/plone/folder/other-document'], result_paths(response.json()))
def test_date_recurring_index_query(self): from datetime import datetime createContentInContainer( self.folder, u'Event', id=u'event', title=u'Event', start=datetime(2013, 1, 1, 0, 0), end=datetime(2013, 1, 1, 23, 59), whole_day=True, recurrence='FREQ=DAILY;COUNT=10;INTERVAL=2', timezone='UTC', ) import transaction transaction.commit() # First occurrence query = {'start': date(2013, 1, 1).isoformat()} response = self.api_session.get('/folder/@search', params=query) self.assertEqual( [u'/plone/folder/event'], result_paths(response.json()) ) # No event that day query = {'start': date(2013, 1, 2).isoformat()} response = self.api_session.get('/folder/@search', params=query) self.assertEqual( [], result_paths(response.json()) ) # Second occurrence query = {'start': date(2013, 1, 3).isoformat()} response = self.api_session.get('/folder/@search', params=query) self.assertEqual( [u'/plone/folder/event'], result_paths(response.json()) ) # Ranged query query = { 'start.query': [date(2013, 1, 1).isoformat(), date(2013, 1, 5).isoformat()], 'start.range': 'min:max', } response = self.api_session.get('/folder/@search', params=query) self.assertEqual( [u'/plone/folder/event'], result_paths(response.json()) )
def test_date_recurring_index_query(self): from datetime import datetime createContentInContainer( self.folder, u'Event', id=u'event', title=u'Event', start=datetime(2013, 1, 1, 0, 0), end=datetime(2013, 1, 1, 23, 59), whole_day=True, recurrence='FREQ=DAILY;COUNT=10;INTERVAL=2', timezone='UTC', ) import transaction transaction.commit() # First occurrence query = {'start': date(2013, 1, 1).isoformat()} response = self.api_session.get('/folder/search', params=query) self.assertEqual( [u'/plone/folder/event'], result_paths(response.json()) ) # No event that day query = {'start': date(2013, 1, 2).isoformat()} response = self.api_session.get('/folder/search', params=query) self.assertEqual( [], result_paths(response.json()) ) # Second occurrence query = {'start': date(2013, 1, 3).isoformat()} response = self.api_session.get('/folder/search', params=query) self.assertEqual( [u'/plone/folder/event'], result_paths(response.json()) ) # Ranged query query = { 'start.query': [date(2013, 1, 1).isoformat(), date(2013, 1, 5).isoformat()], 'start.range': 'min:max', } response = self.api_session.get('/folder/search', params=query) self.assertEqual( [u'/plone/folder/event'], result_paths(response.json()) )
def test_search_in_vhm_multiple_paths(self): # Install a Virtual Host Monster if "virtual_hosting" not in self.app.objectIds(): # If ZopeLite was imported, we have no default virtual # host monster from Products.SiteAccess.VirtualHostMonster import ( manage_addVirtualHostMonster, ) manage_addVirtualHostMonster(self.app, "virtual_hosting") transaction.commit() # path as a list query = {"path": ["/folder", "/folder2"]} # If we go through the VHM we will get results for multiple paths # if we only use the part of the path inside the VHM vhm_url = "%s/VirtualHostBase/http/plone.org/plone/VirtualHostRoot/%s" % ( self.app.absolute_url(), "@search", ) response = self.api_session.get(vhm_url, params=query) self.assertSetEqual( { u"/folder", u"/folder/doc", u"/folder/other-document", u"/folder2", u"/folder2/doc", }, set(result_paths(response.json())), ) # path as a dict with a query list query = {"path.query": ["/folder", "/folder2"]} # If we go through the VHM we will get results for multiple paths # if we only use the part of the path inside the VHM vhm_url = "%s/VirtualHostBase/http/plone.org/plone/VirtualHostRoot/%s" % ( self.app.absolute_url(), "@search", ) response = self.api_session.get(vhm_url, params=query) self.assertSetEqual( { u"/folder", u"/folder/doc", u"/folder/other-document", u"/folder2", u"/folder2/doc", }, set(result_paths(response.json())), )
def test_boolean_index_query(self): query = {'test_bool_field': True, 'portal_type': 'DXTestDocument'} response = self.api_session.get('/folder/search', params=query) self.assertEqual( [u'/plone/folder/doc'], result_paths(response.json()) ) query = {'test_bool_field': False, 'portal_type': 'DXTestDocument'} response = self.api_session.get('/folder/search', params=query) self.assertEqual( [u'/plone/folder/other-document'], result_paths(response.json()) )
def test_date_recurring_index_query(self): from datetime import datetime createContentInContainer( self.folder, u"Event", id=u"event", title=u"Event", start=datetime(2013, 1, 1, 0, 0), end=datetime(2013, 1, 1, 23, 59), whole_day=True, recurrence="FREQ=DAILY;COUNT=10;INTERVAL=2", timezone="UTC", ) import transaction transaction.commit() # First occurrence query = {"start": date(2013, 1, 1).isoformat()} response = self.api_session.get("/folder/@search", params=query) self.assertEqual([u"/plone/folder/event"], result_paths(response.json())) # No event that day query = {"start": date(2013, 1, 2).isoformat()} response = self.api_session.get("/folder/@search", params=query) self.assertEqual([], result_paths(response.json())) # Second occurrence query = {"start": date(2013, 1, 3).isoformat()} response = self.api_session.get("/folder/@search", params=query) self.assertEqual([u"/plone/folder/event"], result_paths(response.json())) # Ranged query query = { "start.query": [date(2013, 1, 1).isoformat(), date(2013, 1, 5).isoformat()], "start.range": "min:max", } response = self.api_session.get("/folder/@search", params=query) self.assertEqual([u"/plone/folder/event"], result_paths(response.json()))
def test_search_on_context_constrains_query_by_path(self): response = self.api_session.get('/folder/@search') self.assertSetEqual( {u'/plone/folder', u'/plone/folder/doc', u'/plone/folder/other-document'}, set(result_paths(response.json())))
def test_contains_correct_batch_of_items(self): # Fetch the second page of the batch response = self.api_session.get('/folder?b_start=2&b_size=2') # Response should contain second batch of items self.assertEquals([u'/plone/folder/doc-3', u'/plone/folder/doc-4'], result_paths(response.json()))
def test_contains_correct_batch_of_items(self): # Fetch the second page of the batch response = self.api_session.get("/?b_start=2&b_size=2") # Response should contain second batch of items self.assertEqual([u"/plone/doc-3", u"/plone/doc-4"], result_paths(response.json()))
def test_fulltext_search_with_non_ascii_characters(self): query = {"SearchableText": u"\xfcbersicht"} response = self.api_session.get("/@search", params=query) self.assertEqual( [u"/plone/folder/other-document"], result_paths(response.json()) )
def test_path_gets_prefilled_if_missing_from_path_query_dict(self): response = self.api_session.get('/@search?path.depth=1') self.assertSetEqual( { u'/plone/folder', u'/plone/folder2', u'/plone/doc-outside-folder' }, set(result_paths(response.json())))
def test_keyword_index_str_query_or(self): query = {'test_list_field': ['Keyword2', 'Keyword3']} response = self.api_session.get('/@search', params=query) self.assertEqual( [u'/plone/folder/doc', u'/plone/folder/other-document'], result_paths(response.json()))
def test_fulltext_search(self): query = {'SearchableText': 'lorem'} response = self.api_session.get('/search', params=query) self.assertEqual( [u'/plone/folder/doc'], result_paths(response.json()) )
def test_keyword_index_str_query(self): query = {'test_list_field': 'Keyword1'} response = self.api_session.get('/@search', params=query) self.assertEqual( [u'/plone/folder/doc'], result_paths(response.json()) )
def test_field_index_int_query(self): query = {'test_int_field:int': 42} response = self.api_session.get('/@search', params=query) self.assertEqual( [u'/plone/folder/doc'], result_paths(response.json()) )
def test_fulltext_search_with_non_ascii_characters(self): query = {'SearchableText': u'\xfcbersicht'} response = self.api_session.get('/@search', params=query) self.assertEqual( [u'/plone/folder/other-document'], result_paths(response.json()) )
def test_field_index_int_query(self): query = {'test_int_field:int': 42} response = self.api_session.get('/search', params=query) self.assertEqual( [u'/plone/folder/doc'], result_paths(response.json()) )
def test_keyword_index_str_query_and(self): query = { "test_list_field.query": ["Keyword1", "Keyword2"], "test_list_field.operator": "and", } response = self.api_session.get("/@search", params=query) self.assertEqual([u"/plone/folder/doc"], result_paths(response.json()))
def test_keyword_index_str_query_or(self): query = {"test_list_field": ["Keyword2", "Keyword3"]} response = self.api_session.get("/@search", params=query) self.assertEqual( [u"/plone/folder/doc", u"/plone/folder/other-document"], result_paths(response.json()), )
def test_uuid_index_query(self): IMutableUUID(self.doc).set("7777a074cb4240d08c9a129e3a837777") self.doc.reindexObject() transaction.commit() query = {"UID": "7777a074cb4240d08c9a129e3a837777"} response = self.api_session.get("/@search", params=query) self.assertEqual([u"/plone/folder/doc"], result_paths(response.json()))
def test_date_index_query(self): query = {'created': date(1950, 1, 1).isoformat()} response = self.api_session.get('/@search', params=query) self.assertEqual( [u'/plone/folder/doc'], result_paths(response.json()) )
def test_search_on_context_constrains_query_by_path(self): response = self.api_session.get('/folder/search') self.assertSetEqual( {u'/plone/folder', u'/plone/folder/doc', u'/plone/folder/other-document'}, set(result_paths(response.json())))
def test_date_index_ranged_query(self): query = { "start.query": [date(1949, 1, 1).isoformat(), date(1951, 1, 1).isoformat()], "start.range": "min:max", } response = self.api_session.get("/@search", params=query) self.assertEqual([u"/plone/folder/doc"], result_paths(response.json()))
def test_date_index_query(self): query = {'created': date(1950, 1, 1).isoformat()} response = self.api_session.get('/search', params=query) self.assertEqual( [u'/plone/folder/doc'], result_paths(response.json()) )
def test_fulltext_search(self): query = {'SearchableText': 'lorem'} response = self.api_session.get('/@search', params=query) self.assertEqual( [u'/plone/folder/doc'], result_paths(response.json()) )
def test_field_index_int_range_query(self): query = { "test_int_field.query:int": [41, 43], "test_int_field.range": "min:max", } response = self.api_session.get("/@search", params=query) self.assertEqual([u"/plone/folder/doc"], result_paths(response.json()))
def test_uuid_index_query(self): IMutableUUID(self.doc).set('7777a074cb4240d08c9a129e3a837777') self.doc.reindexObject() transaction.commit() query = {'UID': '7777a074cb4240d08c9a129e3a837777'} response = self.api_session.get('/@search', params=query) self.assertEqual([u'/plone/folder/doc'], result_paths(response.json()))
def test_fulltext_search_with_non_ascii_characters(self): query = {'SearchableText': u'\xfcbersicht'} response = self.api_session.get('/search', params=query) self.assertEqual( [u'/plone/folder/other-document'], result_paths(response.json()) )
def test_field_index_int_range_query(self): query = { 'test_int_field.query:int': [41, 43], 'test_int_field.range': 'min:max', } response = self.api_session.get('/@search', params=query) self.assertEqual([u'/plone/folder/doc'], result_paths(response.json()))
def test_keyword_index_str_query(self): query = {'test_list_field': 'Keyword1'} response = self.api_session.get('/search', params=query) self.assertEqual( [u'/plone/folder/doc'], result_paths(response.json()) )
def test_keyword_index_str_query_and(self): query = { 'test_list_field.query': ['Keyword1', 'Keyword2'], 'test_list_field.operator': 'and', } response = self.api_session.get('/@search', params=query) self.assertEqual([u'/plone/folder/doc'], result_paths(response.json()))
def test_contains_correct_batch_of_items(self): # Fetch the second page of the batch response = self.api_session.get('/folder/@search?b_start=2&b_size=2') # Response should contain second batch of items self.assertEquals([ u'/plone/folder/doc-2', u'/plone/folder/doc-3'], result_paths(response.json()))
def test_date_range_index_query(self): query = {'effectiveRange': date(1997, 1, 1).isoformat()} response = self.api_session.get('/folder/search', params=query) self.assertEqual( [u'/plone/folder', u'/plone/folder/doc'], result_paths(response.json()) )
def test_keyword_index_str_query_or(self): query = {'test_list_field': ['Keyword2', 'Keyword3']} response = self.api_session.get('/search', params=query) self.assertEqual( [u'/plone/folder/doc', u'/plone/folder/other-document'], result_paths(response.json()) )
def test_uuid_index_query(self): IMutableUUID(self.doc).set('7777a074cb4240d08c9a129e3a837777') self.doc.reindexObject() transaction.commit() query = {'UID': '7777a074cb4240d08c9a129e3a837777'} response = self.api_session.get('/search', params=query) self.assertEqual( [u'/plone/folder/doc'], result_paths(response.json()) )
def test_extended_path_index_query(self): query = {'path': '/'.join(self.folder.getPhysicalPath())} response = self.api_session.get('/search', params=query) self.assertEqual( [u'/plone/folder', u'/plone/folder/doc', u'/plone/folder/other-document'], result_paths(response.json()) )
def test_field_index_int_range_query(self): query = { 'test_int_field.query:int': [41, 43], 'test_int_field.range': 'min:max', } response = self.api_session.get('/search', params=query) self.assertEqual( [u'/plone/folder/doc'], result_paths(response.json()) )
def test_keyword_index_str_query_and(self): query = { 'test_list_field.query': ['Keyword1', 'Keyword2'], 'test_list_field.operator': 'and', } response = self.api_session.get('/search', params=query) self.assertEqual( [u'/plone/folder/doc'], result_paths(response.json()) )
def test_date_index_ranged_query(self): query = { 'created.query': [date(1949, 1, 1).isoformat(), date(1951, 1, 1).isoformat()], 'created.range': 'min:max', } response = self.api_session.get('/search', params=query) self.assertEqual( [u'/plone/folder/doc'], result_paths(response.json()) )
def test_keyword_index_int_query(self): self.doc.test_list_field = [42, 23] self.doc.reindexObject() transaction.commit() query = {'test_list_field:int': 42} response = self.api_session.get('/search', params=query) self.assertEqual( [u'/plone/folder/doc'], result_paths(response.json()) )