예제 #1
0
    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())))
예제 #2
0
    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()))
예제 #3
0
    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())),
        )
예제 #4
0
    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()))
예제 #5
0
    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())),
        )
예제 #6
0
    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())))
예제 #7
0
    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())))
예제 #8
0
    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()))
예제 #9
0
    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()))
예제 #10
0
    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())
        )
예제 #11
0
    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())
        )
예제 #12
0
    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())),
        )
예제 #13
0
    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())
        )
예제 #14
0
    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()))
예제 #15
0
 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())))
예제 #16
0
    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()))
예제 #17
0
    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()))
예제 #18
0
    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())
        )
예제 #19
0
 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())))
예제 #20
0
    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()))
예제 #21
0
    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())
        )
예제 #22
0
    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())
        )
예제 #23
0
    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())
        )
예제 #24
0
    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())
        )
예제 #25
0
    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())
        )
예제 #26
0
    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()))
예제 #27
0
    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()),
        )
예제 #28
0
    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()))
예제 #29
0
    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())
        )
예제 #30
0
    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())))
예제 #31
0
    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()))
예제 #32
0
    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())
        )
예제 #33
0
    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())
        )
예제 #34
0
    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()))
예제 #35
0
    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()))
예제 #36
0
    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())
        )
예제 #37
0
    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()))
예제 #38
0
    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())
        )
예제 #39
0
    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()))
예제 #40
0
    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()))
예제 #41
0
    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())
        )
예제 #42
0
    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())
        )
예제 #43
0
    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())
        )
예제 #44
0
    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())
        )
예제 #45
0
    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())
        )
예제 #46
0
    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())
        )
예제 #47
0
    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())
        )
예제 #48
0
    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())
        )