Ejemplo n.º 1
0
    def test_add(self):
        config = getConfig()
        config.atomic_updates = True
        add_request = getData('add_request.txt')
        add_response = getData('add_response.txt')

        c = SolrConnection(host='localhost:8983', persistent=True)

        # fake schema response - caches the schema
        fakehttp(c, getData('schema.xml'))
        c.get_schema()

        output = fakehttp(c, add_response)
        c.add(id='500', name='python test doc')
        res = c.flush()
        self.assertEqual(len(res), 1)   # one request was sent
        res = res[0]
        self.failUnlessEqual(str(output), add_request)
        # Status
        node = res.findall(".//int")[0]
        self.failUnlessEqual(node.attrib['name'], 'status')
        self.failUnlessEqual(node.text, '0')
        # QTime
        node = res.findall(".//int")[1]
        self.failUnlessEqual(node.attrib['name'], 'QTime')
        self.failUnlessEqual(node.text, '4')
        res.find('QTime')
Ejemplo n.º 2
0
 def testPartialIndexObject(self):
     foo = Foo(id='500', name='foo', price=42.0)
     # first index all attributes...
     response = getData('add_response.txt')
     output = fakehttp(self.mngr.getConnection(), response)
     self.proc.index(foo)
     self.assert_(str(output).find(
         '<field name="price">42.0</field>') > 0, '"price" data not found')
     # then only a subset...
     response = getData('add_response.txt')
     output = fakehttp(self.mngr.getConnection(), response)
     self.proc.index(foo, attributes=['id', 'name'])
     output = str(output)
     self.assert_(
         output.find('<field name="name">foo</field>') > 0,
         '"name" data not found'
     )
     # at this point we'd normally check for a partial update:
     #   self.assertEqual(output.find('price'), -1, '"price" data found?')
     #   self.assertEqual(output.find('42'), -1, '"price" data found?')
     # however, until SOLR-139 has been implemented (re)index operations
     # always need to provide data for all attributes in the schema...
     self.assert_(
         output.find('<field name="price">42.0</field>') > 0,
         '"price" data not found'
     )
Ejemplo n.º 3
0
 def setUp(self):
     self.mngr = SolrConnectionManager()
     self.mngr.setHost(active=True)
     conn = self.mngr.getConnection()
     fakehttp(conn, getData('schema.xml'))   # fake schema response
     self.mngr.getSchema()                   # read and cache the schema
     self.search = Search()
     self.search.manager = self.mngr
Ejemplo n.º 4
0
 def setUp(self):
     provideUtility(SolrConnectionConfig(), ISolrConnectionConfig)
     self.mngr = SolrConnectionManager()
     self.mngr.setHost(active=True)
     conn = self.mngr.getConnection()
     fakehttp(conn, getData('schema.xml'))       # fake schema response
     self.mngr.getSchema()                       # read and cache the schema
     self.proc = SolrIndexProcessor(self.mngr)
Ejemplo n.º 5
0
 def afterSetUp(self):
     schema = getData('plone_schema.xml')
     self.proc = queryUtility(ISolrConnectionManager)
     self.proc.setHost(active=True)
     conn = self.proc.getConnection()
     fakehttp(conn, schema)              # fake schema response
     self.proc.getSchema()               # read and cache the schema
     self.folder.unmarkCreationFlag()    # stop LinguaPlone from renaming
Ejemplo n.º 6
0
 def setUp(self):
     self.mngr = SolrConnectionManager()
     self.mngr.setHost(active=True)
     conn = self.mngr.getConnection()
     fakehttp(conn, getData('schema.xml'))       # fake schema response
     self.mngr.getSchema()                       # read and cache the schema
     self.proc = SolrIndexProcessor(self.mngr)
     config = getConfig()
     config.atomic_updates = True
Ejemplo n.º 7
0
 def testUnindexingWithUniqueKeyMissing(self):
     fakehttp(self.conn, getData('simple_schema.xml'))   # fake schema response
     self.mngr.getSchema()                               # read and cache the schema
     response = getData('delete_response.txt')
     output = fakehttp(self.conn, response)              # fake delete response
     foo = Foo(id='500', name='foo')
     self.proc.unindex(foo)                              # unindexing sends data
     self.assertEqual(len(output), 0)                    # nothing happened...
     self.assertEqual(self.log, [
         'schema is missing unique key, skipping unindexing of %r', foo])
Ejemplo n.º 8
0
 def runner():
     fakehttp(mngr.getConnection(), schema)      # fake schema response
     mngr.getSchema()                            # read and cache the schema
     response = getData('add_response.txt')
     output = fakehttp(mngr.getConnection(), response)   # fake add response
     proc.index(Foo(id='500', name='python test doc'))   # indexing sends data
     mngr.closeConnection()
     log.append(str(output))
     log.append(proc)
     log.append(mngr.getConnection())
Ejemplo n.º 9
0
    def setUp(self):
        provideUtility(SolrConnectionConfig(), ISolrConnectionConfig)
        self.mngr = SolrConnectionManager()
        self.mngr.setHost(active=True)
        conn = self.mngr.getConnection()
        fakehttp(conn, getData('plone_schema.xml')) # fake schema response
        self.mngr.getSchema()                       # read and cache the schema
        self.search = Search()
        self.search.manager = self.mngr

        # Patch buildQuery method
        self.search.buildQuery = buildQuery.__get__(self.search,
                                                    self.search.__class__)
Ejemplo n.º 10
0
    def testLocalConnections(self):
        config = getConfig()
        config.atomic_updates = True
        mngr = SolrConnectionManager(active=True)
        proc = SolrIndexProcessor(mngr)
        mngr.setHost(active=True)
        schema = getData('schema.xml')
        log = []

        def runner():
            # fake schema response on solr connection - caches the schema
            fakehttp(mngr.getConnection(), getData('schema.xml'))
            mngr.getConnection().get_schema()

            fakehttp(mngr.getConnection(), schema)      # fake schema response
            # read and cache the schema
            mngr.getSchema()
            response = getData('add_response.txt')
            # fake add response
            output = fakehttp(mngr.getConnection(), response)
            # indexing sends data
            proc.index(Foo(id='500', name='python test doc'))
            mngr.closeConnection()
            log.append(str(output))
            log.append(proc)
            log.append(mngr.getConnection())
        # after the runner was set up, another thread can be created and
        # started;  its output should contain the proper indexing request,
        # whereas the main thread's connection remain idle;  the latter
        # cannot be checked directly, but the connection object would raise
        # an exception if it was used to send a request without setting up
        # a fake response beforehand...
        thread = Thread(target=runner)
        thread.start()
        thread.join()
        conn = mngr.getConnection()         # get this thread's connection
        fakehttp(conn, schema)              # fake schema response
        mngr.getSchema()                    # read and cache the schema
        mngr.closeConnection()
        mngr.setHost(active=False)
        self.assertEqual(len(log), 3)
        self.assertEqual(sortFields(log[0]), getData(
            'add_request.txt').rstrip('\n'))
        self.failUnless(isinstance(log[1], SolrIndexProcessor))
        self.failUnless(isinstance(log[2], SolrConnection))
        self.failUnless(isinstance(proc, SolrIndexProcessor))
        self.failUnless(isinstance(conn, SolrConnection))
        self.assertEqual(log[1], proc)      # processors should be the same...
        self.assertNotEqual(log[2], conn)   # but not the connections
Ejemplo n.º 11
0
 def setUp(self):
     replies = (getData('plone_schema.xml'), getData('add_response.txt'),
                getData('add_response.txt'),
                getData('add_response.txt'),
                getData('commit_response.txt'))
     self.proc = queryUtility(ISolrConnectionManager)
     self.proc.setHost(active=True)
     conn = self.proc.getConnection()
     fakehttp(conn, *replies)              # fake schema response
     self.proc.getSchema()               # read and cache the schema
     self.portal = self.layer['portal']
     setRoles(self.portal, TEST_USER_ID, ['Manager'])
     self.portal.invokeFactory('Folder', id='folder')
     self.folder = self.portal.folder
     commit()
Ejemplo n.º 12
0
 def testNoIndexingWithoutAllRequiredFields(self):
     response = getData('dummy_response.txt')
     # fake add response
     output = fakehttp(self.mngr.getConnection(), response)
     # indexing sends data
     self.proc.index(Foo(id='500'))
     self.assertEqual(str(output), '')
Ejemplo n.º 13
0
 def testDateIndexingWithPythonDate(self):
     foo = Foo(id='brand', name='jan-carel', cat='nerd', timestamp=date(1982, 8, 05))
     response = getData('add_response.txt')
     output = fakehttp(self.mngr.getConnection(), response)   # fake add response
     self.proc.index(foo)
     required = '<field name="timestamp">1982-08-05T00:00:00.000Z</field>'
     self.assert_(str(output).find(required) > 0, '"date" data not found')
Ejemplo n.º 14
0
 def testIndexObject(self):
     response = getData('add_response.txt')
     # fake add response
     output = fakehttp(self.mngr.getConnection(), response)
     # indexing sends data
     self.proc.index(Foo(id='500', name='python test doc'))
     self.assertEqual(sortFields(str(output)), getData('add_request.txt'))
Ejemplo n.º 15
0
 def testDateIndexingWithPythonDateTime(self):
     foo = Foo(id='gerken', name='patrick', cat='nerd', timestamp=datetime(1980, 9, 29, 14, 02))
     response = getData('add_response.txt')
     output = fakehttp(self.mngr.getConnection(), response)   # fake add response
     self.proc.index(foo)
     required = '<field name="timestamp">1980-09-29T14:02:00.000Z</field>'
     self.assert_(str(output).find(required) > 0, '"date" data not found')
Ejemplo n.º 16
0
 def testDateIndexing(self):
     foo = Foo(id='zeidler', name='andi', cat='nerd', timestamp=DateTime('May 11 1972 03:45 GMT'))
     response = getData('add_response.txt')
     output = fakehttp(self.mngr.getConnection(), response)   # fake add response
     self.proc.index(foo)
     required = '<field name="timestamp">1972-05-11T03:45:00.000Z</field>'
     self.assert_(str(output).find(required) > 0, '"date" data not found')
Ejemplo n.º 17
0
 def test_optimize(self):
     commit_request = getData('optimize_request.txt')
     commit_response = getData('commit_response.txt')
     c = SolrConnection(host='localhost:8983', persistent=True)
     output = fakehttp(c, commit_response)
     c.commit(optimize=True)
     self.failUnlessEqual(str(output), commit_request)
Ejemplo n.º 18
0
 def test_commit_no_wait_flush(self):
     commit_request = getData('commit_request.txt').rstrip('\n')
     commit_response = getData('commit_response.txt')
     c = SolrConnection(host='localhost:8983', persistent=True)
     output = fakehttp(c, commit_response)
     c.commit()
     self.failUnlessEqual(str(output), commit_request)
Ejemplo n.º 19
0
 def test_commit_no_wait(self):
     commit_request = getData('commit_request_no_wait.txt')
     commit_response = getData('commit_response.txt')
     c = SolrConnection(host='localhost:8983', persistent=True)
     output = fakehttp(c, commit_response)
     c.commit(waitFlush=False, waitSearcher=False)
     self.failUnlessEqual(str(output), commit_request)
Ejemplo n.º 20
0
 def testUnindexObject(self):
     response = getData('delete_response.txt')
     # fake response
     output = fakehttp(self.mngr.getConnection(), response)
     # unindexing sends data
     self.proc.unindex(Foo(id='500', name='python test doc'))
     self.assertEqual(str(output), getData('delete_request.txt'))
Ejemplo n.º 21
0
 def testCommit(self):
     response = getData('commit_response.txt')
     # fake response
     output = fakehttp(self.mngr.getConnection(), response)
     # committing sends data
     self.proc.commit()
     self.assertEqual(str(output), getData('commit_request.txt'))
Ejemplo n.º 22
0
 def testCommit(self):
     response = getData('commit_response.txt')
     # fake response
     output = fakehttp(self.mngr.getConnection(), response)
     # committing sends data
     self.proc.commit()
     self.assertEqual(str(output),
                      getData('commit_request.txt').rstrip('\n'))
Ejemplo n.º 23
0
 def testUnindexObject(self):
     response = getData('delete_response.txt')
     # fake response
     output = fakehttp(self.mngr.getConnection(), response)
     # unindexing sends data
     self.proc.unindex(Foo(id='500', name='python test doc'))
     self.assertEqual(str(output),
                      getData('delete_request.txt').rstrip('\n'))
Ejemplo n.º 24
0
        def runner():
            # fake schema response on solr connection - caches the schema
            fakehttp(mngr.getConnection(), getData('schema.xml'))
            mngr.getConnection().get_schema()

            fakehttp(mngr.getConnection(), schema)  # fake schema response
            # read and cache the schema
            mngr.getSchema()
            response = getData('add_response.txt')
            # fake add response
            output = fakehttp(mngr.getConnection(), response)
            # indexing sends data
            proc.index(Foo(id='500', name='python test doc'))
            mngr.closeConnection()
            log.append(str(output))
            log.append(proc)
            log.append(mngr.getConnection())
Ejemplo n.º 25
0
 def testIndexObject(self):
     response = getData('add_response.txt')
     # fake add response
     output = fakehttp(self.mngr.getConnection(), response)
     # indexing sends data
     self.proc.index(Foo(id='500', name='python test doc'))
     self.assertEqual(sortFields(str(output)),
                      getData('add_request.txt').rstrip('\n'))
Ejemplo n.º 26
0
 def test_commit_no_wait_searcher(self):
     commit_request = getData(
         'commit_request_no_wait_searcher.txt').rstrip('\n')
     commit_response = getData('commit_response.txt')
     c = SolrConnection(host='localhost:8983', persistent=True)
     output = fakehttp(c, commit_response)
     c.commit(waitSearcher=False)
     self.failUnlessEqual(str(output), commit_request)
Ejemplo n.º 27
0
 def test_commit_no_wait_searcher(self):
     commit_request = getData("commit_request_no_wait_searcher.txt").rstrip(
         b"\n")
     commit_response = getData("commit_response.txt")
     c = SolrConnection(host="localhost:8983", persistent=True)
     output = fakehttp(c, commit_response)
     c.commit(waitSearcher=False)
     self.failUnlessEqual(str(output), commit_request.decode("utf-8"))
Ejemplo n.º 28
0
 def testIndexAccessorRaises(self):
     response = getData('add_response.txt')
     output = fakehttp(self.mngr.getConnection(), response)   # fake add response
     def brokenfunc():
         raise ValueError
     self.proc.index(Foo(id='500', name='python test doc',
                         text=brokenfunc))   # indexing sends data
     self.assertEqual(sortFields(str(output)), getData('add_request.txt'))
Ejemplo n.º 29
0
        def runner():
            # fake schema response on solr connection - caches the schema
            fakehttp(mngr.getConnection(), getData('schema.xml'))
            mngr.getConnection().get_schema()

            fakehttp(mngr.getConnection(), schema)      # fake schema response
            # read and cache the schema
            mngr.getSchema()
            response = getData('add_response.txt')
            # fake add response
            output = fakehttp(mngr.getConnection(), response)
            # indexing sends data
            proc.index(Foo(id='500', name='python test doc'))
            mngr.closeConnection()
            log.append(str(output))
            log.append(proc)
            log.append(mngr.getConnection())
Ejemplo n.º 30
0
 def test_search(self):
     search_request = getData('search_request.txt')
     search_response = getData('search_response.txt')
     c = SolrConnection(host='localhost:8983', persistent=True)
     output = fakehttp(c, search_response)
     res = c.search(q='+id:[* TO *]', wt='xml', rows='10', indent='on')
     res = fromstring(res.read())
     self.failUnlessEqual(str(output), search_request)
     self.failUnless(res.find(('.//doc')))
Ejemplo n.º 31
0
 def testUnindexObject(self):
     response = getData("delete_response.txt")
     # fake response
     output = fakehttp(self.mngr.getConnection(), response)
     # unindexing sends data
     self.proc.unindex(Foo(id="500", name="python test doc"))
     self.assertEqual(
         str(output), getData("delete_request.txt").decode("utf-8").rstrip("\n")
     )
Ejemplo n.º 32
0
 def setUp(self):
     replies = (
         getData("plone_schema.xml"),
         getData("add_response.txt"),
         getData("add_response.txt"),
         getData("add_response.txt"),
         getData("commit_response.txt"),
     )
     self.proc = queryUtility(ISolrConnectionManager)
     self.proc.setHost(active=True)
     conn = self.proc.getConnection()
     fakehttp(conn, *replies)  # fake schema response
     self.proc.getSchema()  # read and cache the schema
     self.portal = self.layer["portal"]
     setRoles(self.portal, TEST_USER_ID, ["Manager"])
     self.portal.invokeFactory("Folder", id="folder")
     self.folder = self.portal.folder
     commit()
Ejemplo n.º 33
0
    def test_no_suggest(self):
        portal = self.layer['portal']
        request = self.layer['request']

        # Setup browser layers
        notify(BeforeTraverseEvent(portal, request))

        # Setup solr suggest response
        response = getData('nosuggest_response.txt')
        proc = queryUtility(ISolrConnectionManager)
        proc.setHost(active=True)
        conn = proc.getConnection()
        fakehttp(conn, response)

        request.form.update({'term': 'abx'})
        view = getMultiAdapter((portal, request), name=u'suggest-terms')
        suggestions = json.loads(view())
        self.assertEquals(len(suggestions), 0)
Ejemplo n.º 34
0
 def test_search(self):
     search_request = getData('search_request.txt')
     search_response = getData('search_response.txt')
     c = SolrConnection(host='localhost:8983', persistent=True)
     output = fakehttp(c, search_response)
     res = c.search(q='+id:[* TO *]', wt='xml', rows='10', indent='on')
     res = fromstring(res.read())
     self.failUnlessEqual(str(output), search_request)
     self.failUnless(res.find(('.//doc')))
Ejemplo n.º 35
0
 def testCommit(self):
     response = getData("commit_response.txt")
     # fake response
     output = fakehttp(self.mngr.getConnection(), response)
     # committing sends data
     self.proc.commit()
     self.assertEqual(
         str(output), getData("commit_request.txt").decode("utf-8").rstrip("\n")
     )
Ejemplo n.º 36
0
    def testLocalConnections(self):
        provideUtility(SolrConnectionConfig(), ISolrConnectionConfig)
        mngr = SolrConnectionManager(active=True)
        proc = SolrIndexProcessor(mngr)
        mngr.setHost(active=True)
        schema = getData('schema.xml')
        log = []

        def runner():
            fakehttp(mngr.getConnection(), schema)  # fake schema response
            # read and cache the schema
            mngr.getSchema()
            response = getData('add_response.txt')
            # fake add response
            output = fakehttp(mngr.getConnection(), response)
            # indexing sends data
            proc.index(Foo(id='500', name='python test doc'))
            mngr.closeConnection()
            log.append(str(output))
            log.append(proc)
            log.append(mngr.getConnection())

        # after the runner was set up, another thread can be created and
        # started;  its output should contain the proper indexing request,
        # whereas the main thread's connection remain idle;  the latter
        # cannot be checked directly, but the connection object would raise
        # an exception if it was used to send a request without setting up
        # a fake response beforehand...
        thread = Thread(target=runner)
        thread.start()
        thread.join()
        conn = mngr.getConnection()  # get this thread's connection
        fakehttp(conn, schema)  # fake schema response
        mngr.getSchema()  # read and cache the schema
        mngr.closeConnection()
        mngr.setHost(active=False)
        self.assertEqual(len(log), 3)
        self.assertEqual(sortFields(log[0]), getData('add_request.txt'))
        self.failUnless(isinstance(log[1], SolrIndexProcessor))
        self.failUnless(isinstance(log[2], SolrConnection))
        self.failUnless(isinstance(proc, SolrIndexProcessor))
        self.failUnless(isinstance(conn, SolrConnection))
        self.assertEqual(log[1], proc)  # processors should be the same...
        self.assertNotEqual(log[2], conn)  # but not the connections
Ejemplo n.º 37
0
 def testPartialIndexObject(self):
     foo = Foo(id='500', name='foo', price=42.0)
     # first index all attributes...
     response = getData('add_response.txt')
     output = fakehttp(self.mngr.getConnection(), response)
     self.proc.index(foo)
     self.assert_(str(output).find('<field name="price">42.0</field>') > 0, '"price" data not found')
     # then only a subset...
     response = getData('add_response.txt')
     output = fakehttp(self.mngr.getConnection(), response)
     self.proc.index(foo, attributes=['id', 'name'])
     output = str(output)
     self.assert_(output.find('<field name="name">foo</field>') > 0, '"name" data not found')
     # at this point we'd normally check for a partial update:
     #   self.assertEqual(output.find('price'), -1, '"price" data found?')
     #   self.assertEqual(output.find('42'), -1, '"price" data found?')
     # however, until SOLR-139 has been implemented (re)index operations
     # always need to provide data for all attributes in the schema...
     self.assert_(output.find('<field name="price">42.0</field>') > 0, '"price" data not found')
Ejemplo n.º 38
0
 def testTwoRequests(self):
     mngr = SolrConnectionManager(active=True)
     proc = SolrIndexProcessor(mngr)
     output = fakehttp(mngr.getConnection(), getData('schema.xml'),
         getData('add_response.txt'))
     proc.index(self.foo)
     mngr.closeConnection()
     self.assertEqual(len(output), 2)
     self.failUnless(output.get().startswith(self.schema_request))
     self.assertEqual(sortFields(output.get()), getData('add_request.txt'))
Ejemplo n.º 39
0
 def testTwoRequests(self):
     mngr = SolrConnectionManager(active=True)
     proc = SolrIndexProcessor(mngr)
     output = fakehttp(mngr.getConnection(), getData('schema.xml'),
                       getData('add_response.txt'))
     proc.index(self.foo)
     mngr.closeConnection()
     self.assertEqual(len(output), 2)
     self.failUnless(output.get().startswith(self.schema_request))
     self.assertEqual(sortFields(output.get()), getData('add_request.txt'))
Ejemplo n.º 40
0
 def test_search(self):
     search_request = getData('search_request.txt')
     search_response = getData('search_response.txt')
     c = SolrConnection(host='localhost:8983', persistent=True)
     output = fakehttp(c, search_response)
     res = c.search(q='+id:[* TO *]', fl='* score', wt='xml', rows='10', indent='on')
     res = fromstring(res.read())
     normalize = lambda x: sorted(x.split('&'))      # sort request params
     self.assertEqual(normalize(output.get()), normalize(search_request))
     self.failUnless(res.find(('.//doc')))
Ejemplo n.º 41
0
 def testIndexCatalogAwareObject(self):
     """Check that not only CMFCatalogAware objects are indexed but also
     CatalogAware ones (i.e comments).
     """
     response = getData('add_response.txt')
     # fake add response
     output = fakehttp(self.mngr.getConnection(), response)
     # indexing sends data
     self.proc.index(Comentish(id='500', name='python test doc'))
     self.assertEqual(sortFields(str(output)), getData('add_request.txt'))
Ejemplo n.º 42
0
 def testIndexObject(self):
     response = getData("add_response.txt")
     # fake add response
     output = fakehttp(self.mngr.getConnection(), response)
     # indexing sends data
     self.proc.index(Foo(id="500", name="python test doc"))
     self.assertEqual(
         sortFields(str(output).encode("utf-8")),
         getData("add_request.txt").rstrip(b"\n"),
     )
Ejemplo n.º 43
0
 def test_add_with_boost_values(self):
     add_request = getData('add_request_with_boost_values.txt')
     add_response = getData('add_response.txt')
     c = SolrConnection(host='localhost:8983', persistent=True)
     output = fakehttp(c, add_response)
     boost = {'': 2, 'id': 0.5, 'name': 5}
     c.add(boost_values=boost, id='500', name='python test doc')
     res = c.flush()
     self.assertEqual(len(res), 1)   # one request was sent
     res = res[0]
     self.failUnlessEqual(str(output), add_request)
Ejemplo n.º 44
0
 def testPartialIndexObject(self):
     foo = Foo(id='500', name='foo', price=42.0)
     # first index all attributes...
     response = getData('add_response.txt')
     output = fakehttp(self.mngr.getConnection(), response)
     self.proc.index(foo)
     self.assert_(
         str(output).find('<field name="price" update="set">42.0</field>') >
         0, '"price" data not found')
     # then only a subset...
     response = getData('add_response.txt')
     output = fakehttp(self.mngr.getConnection(), response)
     self.proc.index(foo, attributes=['id', 'name'])
     output = str(output)
     self.assert_(
         output.find('<field name="name" update="set">foo</field>') > 0,
         '"name" data not found')
     # at this point we'd normally check for a partial update:
     self.assertEqual(output.find('price'), -1, '"price" data found?')
     self.assertEqual(output.find('42'), -1, '"price" data found?')
Ejemplo n.º 45
0
    def testIndexAccessorRaises(self):
        response = getData('add_response.txt')
        output = fakehttp(self.mngr.getConnection(),
                          response)  # fake add response

        def brokenfunc():
            raise ValueError

        self.proc.index(Foo(id='500', name='python test doc',
                            text=brokenfunc))  # indexing sends data
        self.assertEqual(sortFields(str(output)), getData('add_request.txt'))
Ejemplo n.º 46
0
 def testNoIndexingForNonCatalogAwareContent(self):
     output = []
     connection = self.proc.getConnection()
     responses = [getData("dummy_response.txt")] * 42  # set up enough...
     output = fakehttp(connection, *responses)  # fake responses
     notify(ObjectModifiedEvent(self.folder))
     self.portal.invokeFactory("Folder", id="myfolder", title="Foo")
     commit()  # indexing happens on commit
     self.assertNotEqual(repr(output).find("Foo"), -1, "title not found")
     self.assertEqual(
         repr(output).find("at_references"), -1, "`at_references` found?")
Ejemplo n.º 47
0
 def testDateIndexingWithPythonDate(self):
     foo = Foo(id='brand',
               name='jan-carel',
               cat='nerd',
               timestamp=date(1982, 8, 05))
     response = getData('add_response.txt')
     output = fakehttp(self.mngr.getConnection(),
                       response)  # fake add response
     self.proc.index(foo)
     required = '<field name="timestamp">1982-08-05T00:00:00.000Z</field>'
     self.assert_(str(output).find(required) > 0, '"date" data not found')
Ejemplo n.º 48
0
 def testDateIndexingWithPythonDateTime(self):
     foo = Foo(id='gerken',
               name='patrick',
               cat='nerd',
               timestamp=datetime(1980, 9, 29, 14, 02))
     response = getData('add_response.txt')
     output = fakehttp(self.mngr.getConnection(),
                       response)  # fake add response
     self.proc.index(foo)
     required = '<field name="timestamp">1980-09-29T14:02:00.000Z</field>'
     self.assert_(str(output).find(required) > 0, '"date" data not found')
Ejemplo n.º 49
0
 def testDateIndexing(self):
     foo = Foo(id='zeidler',
               name='andi',
               cat='nerd',
               timestamp=DateTime('May 11 1972 03:45 GMT'))
     response = getData('add_response.txt')
     output = fakehttp(self.mngr.getConnection(),
                       response)  # fake add response
     self.proc.index(foo)
     required = '<field name="timestamp">1972-05-11T03:45:00.000Z</field>'
     self.assert_(str(output).find(required) > 0, '"date" data not found')
Ejemplo n.º 50
0
 def test_add_with_boost_values(self):
     add_request = getData('add_request_with_boost_values.txt')
     add_response = getData('add_response.txt')
     c = SolrConnection(host='localhost:8983', persistent=True)
     output = fakehttp(c, add_response)
     boost = {'': 2, 'id': 0.5, 'name': 5}
     c.add(boost_values=boost, id='500', name='python test doc')
     res = c.flush()
     self.assertEqual(len(res), 1)   # one request was sent
     res = res[0]
     self.failUnlessEqual(str(output), add_request)
Ejemplo n.º 51
0
 def test_search(self):
     search_request = getData('search_request.txt')
     search_response = getData('search_response.txt')
     c = SolrConnection(host='localhost:8983', persistent=True)
     output = fakehttp(c, search_response)
     res = c.search(
         q='+id:[* TO *]', fl='* score', wt='xml', rows='10', indent='on')
     res = fromstring(res.read())
     normalize = lambda x: sorted(x.split('&'))      # sort request params
     self.assertEqual(normalize(output.get()), normalize(search_request))
     self.failUnless(res.find(('.//doc')))
Ejemplo n.º 52
0
 def testNoIndexingForNonCatalogAwareContent(self):
     output = []
     connection = self.proc.getConnection()
     responses = [getData('dummy_response.txt')] * 42    # set up enough...
     output = fakehttp(connection, *responses)           # fake responses
     notify(ObjectModifiedEvent(self.folder))
     self.portal.invokeFactory('Folder', id='myfolder', title='Foo')
     commit()                        # indexing happens on commit
     self.assertNotEqual(repr(output).find('Foo'), -1, 'title not found')
     self.assertEqual(repr(output).find('at_references'), -1,
                      '`at_references` found?')
Ejemplo n.º 53
0
 def testIndexObject(self):
     output = []
     connection = self.proc.getConnection()
     responses = getData('add_response.txt'), getData('commit_response.txt')
     output = fakehttp(connection, *responses)           # fake responses
     self.folder.processForm(values={'title': 'Foo'})    # updating sends
     self.assertEqual(self.folder.Title(), 'Foo')
     self.assertEqual(str(output), '', 'reindexed unqueued!')
     commit()                        # indexing happens on commit
     required = '<field name="Title">Foo</field>'
     self.assert_(str(output).find(required) > 0, '"title" data not found')
Ejemplo n.º 54
0
 def testIndexObject(self):
     output = []
     connection = self.proc.getConnection()
     responses = getData('add_response.txt'), getData('commit_response.txt')
     output = fakehttp(connection, *responses)  # fake responses
     self.folder.processForm(values={'title': 'Foo'})  # updating sends
     self.assertEqual(self.folder.Title(), 'Foo')
     self.assertEqual(str(output), '', 'reindexed unqueued!')
     commit()  # indexing happens on commit
     required = '<field name="Title">Foo</field>'
     self.assert_(str(output).find(required) > 0, '"title" data not found')
 def testNoIndexingForNonCatalogAwareContent(self):
     output = []
     connection = self.proc.getConnection()
     responses = [getData('dummy_response.txt')] * 42  # set up enough...
     output = fakehttp(connection, *responses)  # fake responses
     ref = self.folder.addReference(self.portal.news, 'referencing')
     self.folder.processForm(values={'title': 'Foo'})
     commit()  # indexing happens on commit
     self.assertNotEqual(repr(output).find('Foo'), -1, 'title not found')
     self.assertEqual(repr(output).find(ref.UID()), -1, 'reference found?')
     self.assertEqual(
         repr(output).find('at_references'), -1, '`at_references` found?')
Ejemplo n.º 56
0
 def testDateIndexingWithPythonDate(self):
     foo = Foo(
         id="brand", name="jan-carel", cat="nerd", timestamp=date(1982, 8, 0o5)
     )
     response = getData("add_response.txt")
     # fake add response
     output = fakehttp(self.mngr.getConnection(), response)
     self.proc.index(foo)
     required = (
         '<field name="timestamp" update="set">' "1982-08-05T00:00:00.000Z</field>"
     )
     self.assert_(str(output).find(required) > 0, '"date" data not found')
Ejemplo n.º 57
0
    def test_add_with_boost_values(self):
        config = getConfig()
        config.atomic_updates = False
        add_request = getData('add_request_with_boost_values.txt').rstrip('\n')
        add_response = getData('add_response.txt')
        c = SolrConnection(host='localhost:8983', persistent=True)

        # fake schema response - caches the schema
        fakehttp(c, getData('schema.xml'))
        c.get_schema()

        output = fakehttp(c, add_response)
        boost = {'': 2, 'id': 0.5, 'name': 5}
        c.add(boost_values=boost,
              atomic_updates=False,  # Force disabling atomic updates
              id='500',
              name='python test doc')

        res = c.flush()
        self.assertEqual(len(res), 1)   # one request was sent
        self.failUnlessEqual(str(output), add_request)
Ejemplo n.º 58
0
 def testIndexerMethods(self):
     class Bar(Foo):
         def cat(self):
             return 'nerd'
         def price(self):
             raise AttributeError('price')
     foo = Bar(id='500', name='foo')
     # raising the exception should keep the attribute from being indexed
     response = getData('add_response.txt')
     output = fakehttp(self.mngr.getConnection(), response)
     self.proc.index(foo)
     output = str(output)
     self.assertTrue(output.find('<field name="cat">nerd</field>') > 0, '"cat" data not found')
     self.assertEqual(output.find('price'), -1, '"price" data found?')
Ejemplo n.º 59
0
    def test_add_with_boost_values(self):
        config = getConfig()
        config.atomic_updates = False
        add_request = getData("add_request_with_boost_values.txt").rstrip(
            b"\n")
        add_response = getData("add_response.txt")
        c = SolrConnection(host="localhost:8983", persistent=True)

        # fake schema response - caches the schema
        fakehttp(c, getData("schema.xml"))
        c.get_schema()

        output = fakehttp(c, add_response)
        boost = {"": 2, "id": 0.5, "name": 5}
        c.add(
            boost_values=boost,
            atomic_updates=False,  # Force disabling atomic updates
            id="500",
            name="python test doc",
        )

        res = c.flush()
        self.assertEqual(len(res), 1)  # one request was sent
        self.failUnlessEqual(str(output), add_request.decode("utf-8"))