本文整理汇总了Python中meresco.components.sru.SruHandler类的典型用法代码示例。如果您正苦于以下问题:Python SruHandler类的具体用法?Python SruHandler怎么用?Python SruHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SruHandler类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: testQueryTimeInExtraResponse
def testQueryTimeInExtraResponse(self):
handler = SruHandler(includeQueryTimes=True)
observer = CallTrace('observer', emptyGeneratorMethods=['echoedExtraRequestData', 'extraResponseData'])
times = [1, 2.5, 3.5]
def timeNow():
return times.pop(0)
handler._timeNow = timeNow
def executeQuery(**kwargs):
response = Response(total=0, hits=[])
response.queryTime=5
raise StopIteration(response)
yield
observer.methods['executeQuery'] = executeQuery
handler.addObserver(observer)
arguments = dict(startRecord=11, maximumRecords=15, query='query', recordPacking='string', recordSchema='schema')
result = "".join(compose(handler.searchRetrieve(sruArguments=arguments, **arguments)))
sruResponse = parse(StringIO(result))
extraResponseData = sruResponse.xpath('/srw:searchRetrieveResponse/srw:extraResponseData', namespaces={'srw':"http://www.loc.gov/zing/srw/"})[0]
self.assertEqualsWS("""<srw:extraResponseData %(xmlns_srw)s %(xmlns_diag)s %(xmlns_xcql)s %(xmlns_dc)s %(xmlns_meresco_srw)s>
<querytimes xmlns="http://meresco.org/namespace/timing">
<sruHandling>PT2.500S</sruHandling>
<sruQueryTime>PT1.500S</sruQueryTime>
<index>PT0.005S</index>
</querytimes>
</srw:extraResponseData>""" % namespaces, lxmltostring(extraResponseData))
queryTimes = lxmltostring(extraResponseData.xpath('//ti:querytimes', namespaces={'ti':"http://meresco.org/namespace/timing"})[0])
assertValid(queryTimes, join(schemasPath, 'timing-20120827.xsd'))
self.assertEquals(['executeQuery', 'echoedExtraRequestData', 'extraResponseData', 'handleQueryTimes'], observer.calledMethodNames())
self.assertEquals({'sru': Decimal("2.500"), 'queryTime': Decimal("1.500"), 'index': Decimal("0.005")}, observer.calledMethods[3].kwargs)
开发者ID:seecr,项目名称:meresco-components,代码行数:31,代码来源:sruhandlertest.py
示例2: testValidXml
def testValidXml(self):
component = SruParser()
sruHandler = SruHandler()
component.addObserver(sruHandler)
observer = CallTrace('observer')
sruHandler.addObserver(observer)
response = Response(total=2, hits=[Hit('id0'), Hit('id1')])
def executeQuery(**kwargs):
raise StopIteration(response)
yield
def retrieveData(**kwargs):
raise StopIteration('<bike/>')
yield
observer.methods['executeQuery'] = executeQuery
observer.returnValues['echoedExtraRequestData'] = (f for f in [])
observer.returnValues['extraResponseData'] = (f for f in [])
observer.methods['extraRecordData'] = lambda hit: (f for f in [])
observer.methods['retrieveData'] = retrieveData
result = ''.join(compose(component.handleRequest(arguments={'version':['1.1'], 'query': ['aQuery'], 'operation':['searchRetrieve']})))
header, body = result.split('\r\n'*2)
assertValid(body, join(schemasPath, 'srw-types1.2.xsd'))
self.assertTrue('<bike/>' in body, body)
result = ''.join(compose(component.handleRequest(arguments={'version':['1.1'], 'operation':['searchRetrieve']})))
header, body = result.split('\r\n'*2)
assertValid(body, join(schemasPath, 'srw-types1.2.xsd'))
self.assertTrue('diagnostic' in body, body)
开发者ID:seecr,项目名称:meresco-components,代码行数:28,代码来源:sruhandlertest.py
示例3: testCollectLog
def testCollectLog(self):
handler = SruHandler(enableCollectLog=True)
observer = CallTrace('observer', emptyGeneratorMethods=['echoedExtraRequestData', 'extraResponseData'])
__callstack_var_logCollector__ = dict()
times = [1, 2.5, 3.5]
def timeNow():
return times.pop(0)
handler._timeNow = timeNow
def executeQuery(**kwargs):
response = Response(total=0, hits=[])
response.queryTime=5
raise StopIteration(response)
yield
observer.methods['executeQuery'] = executeQuery
handler.addObserver(observer)
arguments = dict(startRecord=11, maximumRecords=15, query='query', recordPacking='string', recordSchema='schema')
consume(handler.searchRetrieve(sruArguments=arguments, **arguments))
self.assertEquals({
'sru': {
'handlingTime': [Decimal('2.500')],
'queryTime': [Decimal('1.500')],
'indexTime': [Decimal('0.005')],
'numberOfRecords': [0],
'arguments': [{
'startRecord': 11,
'query': 'query',
'recordPacking': 'string',
'maximumRecords': 15,
'recordSchema': 'schema',
}],
}
}, __callstack_var_logCollector__)
开发者ID:seecr,项目名称:meresco-components,代码行数:34,代码来源:sruhandlertest.py
示例4: testNextRecordPosition
def testNextRecordPosition(self):
observer = CallTrace(emptyGeneratorMethods=['additionalDiagnosticDetails'])
response = Response(total=100, hits=hitsRange(11, 26))
def executeQuery(**kwargs):
raise StopIteration(response)
yield
def retrieveData(**kwargs):
raise StopIteration('record')
yield
observer.methods['executeQuery'] = executeQuery
observer.methods['retrieveData'] = retrieveData
observer.methods['extraResponseData'] = lambda *a, **kw: (x for x in 'extraResponseData')
observer.methods['echoedExtraRequestData'] = lambda *a, **kw: (x for x in 'echoedExtraRequestData')
observer.methods['extraRecordData'] = lambda hit: (f for f in [])
component = SruHandler()
component.addObserver(observer)
arguments = dict(startRecord=11, maximumRecords=15, query='query', recordPacking='string', recordSchema='schema')
result = "".join(compose(component.searchRetrieve(sruArguments=arguments, **arguments)))
self.assertTrue("<srw:nextRecordPosition>26</srw:nextRecordPosition>" in result, result)
executeCqlCallKwargs = observer.calledMethods[0].kwargs
self.assertEquals(10, executeCqlCallKwargs['start']) # SRU is 1 based
self.assertEquals(25, executeCqlCallKwargs['stop'])
开发者ID:seecr,项目名称:meresco-components,代码行数:25,代码来源:sruhandlertest.py
示例5: testCollectLogWhenIndexRaisesError
def testCollectLogWhenIndexRaisesError(self):
handler = SruHandler(enableCollectLog=True)
observer = CallTrace('observer', emptyGeneratorMethods=['echoedExtraRequestData', 'extraResponseData', 'additionalDiagnosticDetails'])
__callstack_var_logCollector__ = dict()
times = [1]
def timeNow():
return times.pop(0)
handler._timeNow = timeNow
def executeQuery(**kwargs):
raise Exception('Sorry')
yield
observer.methods['executeQuery'] = executeQuery
handler.addObserver(observer)
arguments = dict(startRecord=11, maximumRecords=15, query='query', recordPacking='string', recordSchema='schema')
consume(handler.searchRetrieve(sruArguments=arguments, **arguments))
self.assertEquals({
'sru': {
'arguments': [{
'startRecord': 11,
'query': 'query',
'recordPacking': 'string',
'maximumRecords': 15,
'recordSchema': 'schema',
}],
}
}, __callstack_var_logCollector__)
开发者ID:seecr,项目名称:meresco-components,代码行数:28,代码来源:sruhandlertest.py
示例6: testExtraResponseDataHandlerNoData
def testExtraResponseDataHandlerNoData(self):
class TestHandler:
def extraResponseData(self, *args, **kwargs):
return (f for f in [])
component = SruHandler()
component.addObserver(TestHandler())
result = "".join(list(component._writeExtraResponseData(cqlAbstractSyntaxTree=None, **MOCKDATA)))
self.assertEquals('' , result)
开发者ID:seecr,项目名称:meresco-components,代码行数:9,代码来源:sruhandlertest.py
示例7: testExceptionInWriteExtraRecordData
def testExceptionInWriteExtraRecordData(self):
class RaisesException(object):
def extraResponseData(self, *args, **kwargs):
raise Exception("Test Exception")
component = SruHandler()
component.addObserver(RaisesException())
result = "".join(compose(component._writeExtraResponseData(cqlAbstractSyntaxTree=None, **MOCKDATA)))
self.assertTrue("<uri>info://srw/diagnostics/1/1</uri>" in result)
self.assertTrue("<message>General System Error</message>" in result)
self.assertTrue("<details>Test Exception</details>" in result)
开发者ID:seecr,项目名称:meresco-components,代码行数:10,代码来源:sruhandlertest.py
示例8: testEchoedSearchRetrieveRequest
def testEchoedSearchRetrieveRequest(self):
sruArguments = {'version':'1.1', 'operation':'searchRetrieve', 'query':'query >= 3', 'recordSchema':'schema', 'recordPacking':'string'}
component = SruHandler()
result = "".join(list(component._writeEchoedSearchRetrieveRequest(sruArguments=sruArguments)))
self.assertEqualsWS("""<srw:echoedSearchRetrieveRequest>
<srw:version>1.1</srw:version>
<srw:query>query >= 3</srw:query>
<srw:recordPacking>string</srw:recordPacking>
<srw:recordSchema>schema</srw:recordSchema>
</srw:echoedSearchRetrieveRequest>""", result)
开发者ID:seecr,项目名称:meresco-components,代码行数:11,代码来源:sruhandlertest.py
示例9: testExtraResponseDataWithTermDrilldown
def testExtraResponseDataWithTermDrilldown(self):
sruHandler = SruHandler()
sruTermDrilldown = SRUTermDrilldown()
drilldownData = [
{'fieldname': 'field0', 'terms': [{'term': 'value0_0', 'count': 14}]},
{'fieldname': 'field1', 'terms': [{'term': 'value1_0', 'count': 13}, {'term': 'value1_1', 'count': 11}]},
{'fieldname': 'field2', 'terms': [{'term': 'value2_0', 'count': 3}, {'term': 'value2_1', 'count': 2}, {'term': 'value2_2', 'count': 1}]}
]
sruHandler.addObserver(sruTermDrilldown)
result = "".join(sruHandler._writeExtraResponseData(drilldownData=drilldownData, sruArguments={}, **MOCKDATA))
self.assertEqualsWS("""<srw:extraResponseData><dd:drilldown\n xmlns:dd="http://meresco.org/namespace/drilldown"\n xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\n xsi:schemaLocation="http://meresco.org/namespace/drilldown http://meresco.org/files/xsd/drilldown-20070730.xsd"><dd:term-drilldown><dd:navigator name="field0"><dd:item count="14">value0_0</dd:item></dd:navigator><dd:navigator name="field1"><dd:item count="13">value1_0</dd:item><dd:item count="11">value1_1</dd:item></dd:navigator><dd:navigator name="field2"><dd:item count="3">value2_0</dd:item><dd:item count="2">value2_1</dd:item><dd:item count="1">value2_2</dd:item></dd:navigator></dd:term-drilldown></dd:drilldown></srw:extraResponseData>""" , result)
开发者ID:seecr,项目名称:meresco-components,代码行数:11,代码来源:sruhandlertest.py
示例10: testExceptionInWriteRecordData
def testExceptionInWriteRecordData(self):
observer = CallTrace(emptyGeneratorMethods=['additionalDiagnosticDetails'])
def retrieveData(**kwargs):
raise Exception("Test Exception")
yield
observer.methods["retrieveData"] = retrieveData
component = SruHandler()
component.addObserver(observer)
result = "".join(list(compose(component._writeRecordData(recordPacking="string", recordSchema="schema", recordId="ID"))))
self.assertTrue("<uri>info://srw/diagnostics/1/1</uri>" in result)
self.assertTrue("<message>General System Error</message>" in result)
self.assertTrue("<details>Test Exception</details>" in result)
开发者ID:seecr,项目名称:meresco-components,代码行数:12,代码来源:sruhandlertest.py
示例11: testDiagnosticOnExecuteCql
def testDiagnosticOnExecuteCql(self):
with stderr_replaced():
class RaisesException(object):
def executeQuery(self, *args, **kwargs):
raise Exception("Test Exception")
component = SruHandler()
component.addObserver(RaisesException())
arguments = dict(startRecord=11, maximumRecords=15, query='query', recordPacking='string', recordSchema='schema')
result = parse(StringIO("".join(compose(component.searchRetrieve(sruArguments=arguments, **arguments)))))
diagnostic = result.xpath("/srw:searchRetrieveResponse/srw:diagnostics/diag:diagnostic", namespaces=namespaces)
self.assertEquals(1, len(diagnostic))
self.assertEquals(["info://srw/diagnostics/1/48"], diagnostic[0].xpath("diag:uri/text()", namespaces=namespaces))
self.assertEquals(["Query Feature Unsupported"], diagnostic[0].xpath("diag:message/text()", namespaces=namespaces))
self.assertEquals(["Test Exception"], diagnostic[0].xpath("diag:details/text()", namespaces=namespaces))
开发者ID:seecr,项目名称:meresco-components,代码行数:14,代码来源:sruhandlertest.py
示例12: setUp
def setUp(self):
SeecrTestCase.setUp(self)
self.srw = Srw()
self.sruParser = SruParser()
self.sruHandler = SruHandler()
self.srw.addObserver(self.sruParser)
self.sruParser.addObserver(self.sruHandler)
self.response = StopIteration(Response(total=1, hits=[Hit('0')]))
def executeQuery(**kwargs):
raise self.response
yield
def retrieveData(**kwargs):
raise StopIteration('data')
yield
self.observer = CallTrace(
methods={
'executeQuery': executeQuery,
'retrieveData': retrieveData
},
emptyGeneratorMethods=[
'extraResponseData',
'echoedExtraRequestData',
'additionalDiagnosticDetails',
'extraRecordData'
])
self.sruHandler.addObserver(self.observer)
开发者ID:seecr,项目名称:meresco-components,代码行数:27,代码来源:srwtest.py
示例13: testDiagnosticWarning
def testDiagnosticWarning(self):
sruArguments = {'version':'1.2', 'operation':'searchRetrieve', 'recordSchema':'schema', 'recordPacking':'xml', 'query':'field=value', 'startRecord':1, 'maximumRecords':2, }
queryArguments = {'version':'1.2', 'operation':'searchRetrieve', 'recordSchema':'schema', 'recordPacking':'xml', 'query':'field=value', 'startRecord':1, 'maximumRecords':2}
observer = CallTrace(emptyGeneratorMethods=['additionalDiagnosticDetails'])
response = Response(total=100, hits=[Hit('<aap&noot>'), Hit('vuur')])
def executeQuery(**kwargs):
raise StopIteration(response)
yield
observer.methods['executeQuery'] = executeQuery
retrieveDataCalls = []
def retrieveData(identifier, name):
retrieveDataCalls.append(1)
raise StopIteration("<MOCKED_WRITTEN_DATA>%s-%s</MOCKED_WRITTEN_DATA>" % (xmlEscape(identifier), name))
yield
observer.retrieveData = retrieveData
observer.methods['extraResponseData'] = lambda *a, **kw: (x for x in 'extraResponseData')
observer.methods['echoedExtraRequestData'] = lambda *a, **kw: (x for x in 'echoedExtraRequestData')
observer.methods['extraRecordData'] = lambda hit: (f for f in [])
component = SruHandler()
component.addObserver(observer)
result = "".join(compose(component.searchRetrieve(sruArguments=sruArguments, diagnostics=[(998, 'Diagnostic 998', 'The <tag> message'), (999, 'Diagnostic 999', 'Some message')], **queryArguments)))
response = parse(StringIO(result))
self.assertEquals([t % namespaces for t in [
'{%(srw)s}version',
'{%(srw)s}numberOfRecords',
'{%(srw)s}records',
'{%(srw)s}nextRecordPosition',
'{%(srw)s}echoedSearchRetrieveRequest',
'{%(srw)s}diagnostics',
'{%(srw)s}extraResponseData',
]], [t.tag for t in xpath(response, '//srw:searchRetrieveResponse/*')])
diagnostics = [{'uri': xpath(d, 'diag:uri/text()')[0],
'details': xpath(d, 'diag:details/text()')[0],
'message': xpath(d, 'diag:message/text()')[0]} for d in
xpath(response, '/srw:searchRetrieveResponse/srw:diagnostics/diag:diagnostic')]
self.assertEquals([
{'uri': 'info://srw/diagnostics/1/998', 'message': 'Diagnostic 998', 'details': 'The <tag> message'},
{'uri': 'info://srw/diagnostics/1/999', 'message': 'Diagnostic 999', 'details': 'Some message'},
], diagnostics)
开发者ID:seecr,项目名称:meresco-components,代码行数:47,代码来源:sruhandlertest.py
示例14: testExtraResponseDataHandlerWithData
def testExtraResponseDataHandlerWithData(self):
argsUsed = []
kwargsUsed = {}
class TestHandler:
def extraResponseData(self, *args, **kwargs):
argsUsed.append(args)
kwargsUsed.update(kwargs)
return (f for f in ["<someD", "ata/>"])
component = SruHandler()
component.addObserver(TestHandler())
result = "".join(list(component._writeExtraResponseData(cqlAbstractSyntaxTree=None, **MOCKDATA)))
self.assertEquals('<srw:extraResponseData><someData/></srw:extraResponseData>' , result)
self.assertEquals([()], argsUsed)
self.assertEquals(None, kwargsUsed['cqlAbstractSyntaxTree'])
self.assertEquals(MOCKDATA['queryTime'], kwargsUsed['queryTime'])
self.assertEquals(MOCKDATA['response'], kwargsUsed['response'])
开发者ID:seecr,项目名称:meresco-components,代码行数:17,代码来源:sruhandlertest.py
示例15: testExtraRecordDataOldStyle
def testExtraRecordDataOldStyle(self):
queryArguments = {'version':'1.2', 'operation':'searchRetrieve', 'recordSchema':'schema', 'recordPacking':'xml', 'query':'field=value', 'startRecord':1, 'maximumRecords':2}
sruArguments = {'version':'1.2', 'operation':'searchRetrieve', 'recordSchema':'schema', 'recordPacking':'xml', 'query':'field=value', 'startRecord':1, 'maximumRecords':2, 'x-recordSchema':['extra', 'evenmore']}
observer = CallTrace()
response = Response(total=100, hits=[Hit('11')])
def executeQuery(**kwargs):
raise StopIteration(response)
yield
observer.methods['executeQuery'] = executeQuery
retrieveDataCalls = []
def retrieveData(identifier, name):
retrieveDataCalls.append(1)
raise StopIteration("<MOCKED_WRITTEN_DATA>%s-%s</MOCKED_WRITTEN_DATA>" % (identifier, name))
yield
observer.retrieveData = retrieveData
observer.methods['extraResponseData'] = lambda *a, **kw: (x for x in 'extraResponseData')
observer.methods['echoedExtraRequestData'] = lambda *a, **kw: (x for x in 'echoedExtraRequestData')
observer.methods['extraRecordData'] = lambda hit: (f for f in [])
component = SruHandler(extraRecordDataNewStyle=False)
component.addObserver(observer)
result = "".join(compose(component.searchRetrieve(sruArguments=sruArguments, **queryArguments)))
strippedResult = result[result.index('<srw:record>'):result.index('</srw:records>')]
self.assertEqualsWS("""<srw:record>
<srw:recordSchema>schema</srw:recordSchema>
<srw:recordPacking>xml</srw:recordPacking>
<srw:recordIdentifier>11</srw:recordIdentifier>
<srw:recordData>
<MOCKED_WRITTEN_DATA>11-schema</MOCKED_WRITTEN_DATA>
</srw:recordData>
<srw:extraRecordData>
<recordData recordSchema="extra">
<MOCKED_WRITTEN_DATA>11-extra</MOCKED_WRITTEN_DATA>
</recordData>
<recordData recordSchema="evenmore">
<MOCKED_WRITTEN_DATA>11-evenmore</MOCKED_WRITTEN_DATA>
</recordData>
</srw:extraRecordData>
</srw:record>""", strippedResult)
开发者ID:seecr,项目名称:meresco-components,代码行数:44,代码来源:sruhandlertest.py
示例16: testGetDataWithAdapter
def testGetDataWithAdapter(self):
observer = CallTrace(returnValues=dict(getData='<record/>'))
adapter = RetrieveToGetDataAdapter()
handler = SruHandler()
handler.addObserver(adapter)
adapter.addObserver(observer)
response = Response(total=100, hits=hitsRange(1, 3))
def executeQuery(**kwargs):
raise StopIteration(response)
yield
observer.methods['executeQuery'] = executeQuery
observer.methods['extraResponseData'] = lambda *a, **kw: (x for x in 'extraResponseData')
observer.methods['echoedExtraRequestData'] = lambda *a, **kw: (x for x in 'echoedExtraRequestData')
observer.methods['extraRecordData'] = lambda hit: (f for f in [])
response = asString(handler.searchRetrieve(query="word", recordSchema='schema', recordPacking='string', maximumRecords=2, sruArguments={}))
self.assertEquals(['getData', 'getData'], observer.calledMethodNames()[1:4:2])
self.assertTrue('<srw:recordData><record/></srw:recordData>' in response, response)
self.assertEquals({'identifier': '1', 'name': 'schema'}, observer.calledMethods[1].kwargs)
self.assertEquals({'identifier': '2', 'name': 'schema'}, observer.calledMethods[3].kwargs)
开发者ID:seecr,项目名称:meresco-components,代码行数:19,代码来源:sruhandlertest.py
示例17: testExecuteQueryGetsRecordSchemaAsOnOfTheKwargs
def testExecuteQueryGetsRecordSchemaAsOnOfTheKwargs(self):
sruArguments = {'version':'1.2', 'operation':'searchRetrieve', 'recordSchema':'schema', 'recordPacking':'xml', 'query':'field=value', 'startRecord':1, 'maximumRecords':2, 'x-recordSchema':['extra', 'evenmore'], 'x-extra-key': 'extraValue'}
queryArguments = {'version':'1.2', 'operation':'searchRetrieve', 'recordSchema':'schema', 'recordPacking':'xml', 'query':'field=value', 'startRecord':1, 'maximumRecords':2}
observer = CallTrace(emptyGeneratorMethods=['echoedExtraRequestData', 'extraResponseData'])
response = Response(total=0, hits=[])
def executeQuery(**kwargs):
raise StopIteration(response)
yield
observer.methods['executeQuery'] = executeQuery
component = SruHandler()
component.addObserver(observer)
consume(component.searchRetrieve(sruArguments=sruArguments, **queryArguments))
self.assertEqual(['executeQuery', 'echoedExtraRequestData', 'extraResponseData'], observer.calledMethodNames())
queryKwargs = observer.calledMethods[0].kwargs
self.assertEqual('schema', queryKwargs['recordSchema'])
self.assertEqual(['extra', 'evenmore'], queryKwargs['extraArguments']['x-recordSchema'])
开发者ID:seecr,项目名称:meresco-components,代码行数:20,代码来源:sruhandlertest.py
示例18: testNextRecordPositionNotShownIfAfterLimitBeyond
def testNextRecordPositionNotShownIfAfterLimitBeyond(self):
observer = CallTrace(emptyGeneratorMethods=['additionalDiagnosticDetails'])
response = Response(total=100, hits=hitsRange(10, 11))
def executeQuery(**kwargs):
raise StopIteration(response)
yield
def retrieveData(**kwargs):
raise StopIteration('record')
yield
observer.methods['executeQuery'] = executeQuery
observer.methods['retrieveData'] = retrieveData
observer.methods['extraResponseData'] = lambda *a, **kw: (x for x in 'extraResponseData')
observer.methods['echoedExtraRequestData'] = lambda *a, **kw: (x for x in 'echoedExtraRequestData')
observer.methods['extraRecordData'] = lambda hit: (f for f in [])
component = SruHandler()
component.addObserver(observer)
arguments = dict(startRecord=10, maximumRecords=2, query='query', recordPacking='string', recordSchema='schema', limitBeyond=10)
result = "".join(compose(component.searchRetrieve(sruArguments=arguments, **arguments)))
self.assertFalse("<srw:nextRecordPosition>" in result, result)
开发者ID:seecr,项目名称:meresco-components,代码行数:21,代码来源:sruhandlertest.py
示例19: testParseDrilldownArguments
def testParseDrilldownArguments(self):
handler = SruHandler(drilldownSortBy='count')
self.assertEquals(None, handler._parseDrilldownArgs([]))
self.assertEquals([], handler._parseDrilldownArgs(['']))
self.assertEquals([{'fieldname':'field', 'maxTerms':10, 'sortBy':'count'}], handler._parseDrilldownArgs(['field']))
self.assertEquals([{'fieldname':'field', 'maxTerms':10, 'sortBy':'count'}], handler._parseDrilldownArgs(['field,']))
self.assertEquals([{'fieldname':'field', 'maxTerms':20, 'sortBy':'count'}], handler._parseDrilldownArgs(['field:20']))
self.assertEquals([{'fieldname':'field', 'maxTerms':20, 'sortBy':'count'}, {'fieldname':'field2', 'maxTerms':10, 'sortBy':'count'}], handler._parseDrilldownArgs(['field:20,field2']))
self.assertEquals([{'fieldname':'field', 'maxTerms':20, 'sortBy':'count'}, {'fieldname':'field2', 'maxTerms':10, 'sortBy':'count'}], handler._parseDrilldownArgs(['field:20','field2']))
开发者ID:seecr,项目名称:meresco-components,代码行数:9,代码来源:sruhandlertest.py
示例20: testDrilldownResultInExecuteQuery
def testDrilldownResultInExecuteQuery(self):
observer = CallTrace()
response = Response(total=100, hits=hitsRange(11, 26))
drilldownData = iter([
('field0', iter([('value0_0', 14)])),
('field1', iter([('value1_0', 13), ('value1_1', 11)])),
('field2', iter([('value2_0', 3), ('value2_1', 2), ('value2_2', 1)]))])
response.drilldownData = drilldownData
def executeQuery(**kwargs):
raise StopIteration(response)
yield
def retrieveData(**kwargs):
raise StopIteration('record')
yield
observer.methods['executeQuery'] = executeQuery
observer.methods['retrieveData'] = retrieveData
observer.methods['extraResponseData'] = lambda *a, **kw: (x for x in 'extraResponseData')
observer.methods['echoedExtraRequestData'] = lambda *a, **kw: (x for x in 'echoedExtraRequestData')
observer.methods['extraRecordData'] = lambda hit: (f for f in [])
component = SruHandler(drilldownSortBy='somevalue')
component.addObserver(observer)
queryArguments = dict(startRecord=11, maximumRecords=15, query='query', recordPacking='string', recordSchema='schema')
sruArguments = queryArguments
sruArguments['x-term-drilldown'] = ["field0:1,fie:ld1:2,field2,fie:ld3"]
consume(component.searchRetrieve(sruArguments=sruArguments, **queryArguments))
self.assertEquals(['executeQuery'] + ['retrieveData', 'extraRecordData'] * 15 + ['echoedExtraRequestData', 'extraResponseData'], [m.name for m in observer.calledMethods])
self.assertEquals([
dict(fieldname='field0', maxTerms=1, sortBy='somevalue'),
dict(fieldname='fie:ld1', maxTerms=2, sortBy='somevalue'),
dict(fieldname='field2', maxTerms=DEFAULT_MAXIMUM_TERMS, sortBy='somevalue'),
dict(fieldname='fie:ld3', maxTerms=DEFAULT_MAXIMUM_TERMS, sortBy='somevalue')
], list(observer.calledMethods[0].kwargs['facets']))
extraResponseDataMethod = observer.calledMethods[-1]
self.assertEquals(response, extraResponseDataMethod.kwargs['response'])
开发者ID:seecr,项目名称:meresco-components,代码行数:36,代码来源:sruhandlertest.py
注:本文中的meresco.components.sru.SruHandler类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论