def testObservableName(self): sendData = [] observable = Observable() solrInterface1 = SolrInterface("localhost", 1234, core="index1") solrInterface2 = SolrInterface("localhost", 1234, core="index2") solrInterface1._send = lambda path, body: sendData.append(("1", path, body)) solrInterface2._send = lambda path, body: sendData.append(("2", path, body)) observable.addObserver(solrInterface1) observable.addObserver(solrInterface2) list(compose(observable.all['index1'].add(identifier="recordId", partname="partname", data="data"))) self.assertEquals([ ('1', '/solr/index1/update', '<add>data</add>'), ], sendData)
def testAddWithTimeOut(self): sent_data = [] iSolr = SolrInterface("localhost", "8889") iSolr._send = lambda path, body: sent_data.append((path, body)) r = iSolr.add(identifier="record1", partname="part0", data="<record><data>data here</data></record>") list(r) self.assertEquals('/solr/update', sent_data[0][0]) self.assertEquals(1, len(sent_data))
def testDeleteWithTimeOut(self): sent_data = [] iSolr = SolrInterface("localhost", "8889") iSolr._send = lambda path, body: sent_data.append((path, body)) r = iSolr.delete("record1") list(r) self.assertEquals('/solr/update', sent_data[0][0]) self.assertEquals(1, len(sent_data))
def testCoreSupport(self): sendData = [] interface = SolrInterface("localhost", "8888", core="THE_CORE") interface._send = lambda path, body: sendData.append((path, body)) list(interface.add(identifier="recordId", partname="ignored", data="<record><data>recordData</data></record>")) self.assertEquals(1, len(sendData)) self.assertEquals(('/solr/THE_CORE/update', '<add><record><data>recordData</data></record></add>'), sendData[0]) response, (path, body) = self.executeQueryResponse("meresco.exists:true", start=5, stop=10, sortKeys=[dict(sortBy="field", sortDescending=True)], response=JSON_RESPONSE % "", solrInterface=interface) self.assertEquals(path, "/solr/THE_CORE/select") self.assertQueryArguments("q=meresco.exists%3Atrue&start=5&rows=5&sort=field+desc&wt=json", body)
def testAddWithSolrServerFromObserver(self): solrInterface = SolrInterface() observer = CallTrace(returnValues={'solrServer': ('localhost', 1234)}) solrInterface.addObserver(observer) kwargs = [] def httppost(**_kwargs): kwargs.append(_kwargs) s = Suspend() yield s result = s.getResult() raise StopIteration(result) solrInterface._httppost = httppost g = compose(solrInterface.add(identifier="recordId", partname="ignored", data="<record><data>recordData</data></record>")) self._returnValueFromGenerator(g, ["SOME RESPONSE"]) self.assertEquals(['solrServer'], observer.calledMethodNames()) self.assertEquals('localhost', kwargs[0]['host']) self.assertEquals(1234, kwargs[0]['port']) self.assertEquals({'Content-Type': 'text/xml', 'Content-Length': len(kwargs[0]['body'])}, kwargs[0]['headers'])
def testExecuteQuerySolrHostFromObserver(self): solrInterface = SolrInterface() observer = CallTrace(returnValues={'solrServer': ('localhost', 1234)}) solrInterface.addObserver(observer) kwargs = [] def httppost(**_kwargs): kwargs.append(_kwargs) s = Suspend() yield s result = s.getResult() raise StopIteration(result) solrInterface._httppost = httppost g = compose(solrInterface.executeQuery("meresco.exists:true")) self._returnValueFromGenerator(g, [JSON_RESPONSE % ""]) self.assertEquals(['solrServer'], observer.calledMethodNames()) self.assertQueryArguments('q=meresco.exists%3Atrue&start=0&rows=10&wt=json', kwargs[0]['body']) self.assertEquals('localhost', kwargs[0]['host']) self.assertEquals('/solr/select', kwargs[0]['request']) self.assertEquals(1234, kwargs[0]['port']) self.assertEquals({'Content-Type': 'application/x-www-form-urlencoded', 'Content-Length': len(kwargs[0]['body'])}, kwargs[0]['headers'])
def setUp(self): SeecrTestCase.setUp(self) self._solrInterface = SolrInterface("localhost", 8888)