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'])