Changeset 2089 for TI07-MOLES/trunk


Ignore:
Timestamp:
31/01/07 21:33:05 (13 years ago)
Author:
lawrence
Message:

This version of ndgSearch.py includes a test case for ticket:641 (which
is still not fixed).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TI07-MOLES/trunk/PythonCode/wsgi/ndgSearch.py

    r2045 r2089  
    3333        #self.server=loc.getDiscovery(readerclass=ExpatReaderClass, 
    3434        self.server=loc.getDiscoveryServicePortType(readerclass=ExpatReaderClass,tracefile=tracefile) 
     35        self.serverSessionID=None 
     36        self.logger=logger 
     37        self.__reset() 
     38         
     39    def __reset(self): 
     40        ''' Initialise and/or making sure we have no hangovers from a previous call ''' 
    3541        self.documents=None 
    3642        self.hits=None 
    37         self.serverSessionID=None 
    38         self.logger=logger 
    3943        self.error=None 
    40  
     44        self.response=None 
     45        self.status=None 
    4146     
    4247    def search(self,term,start=1,howmany=20,target='All',scope=None,bbox=None,dateRange=None,): 
    4348        ''' Get a list of documents for a specific term using a free text search''' 
    4449         
    45          
     50        self.__reset() 
    4651        #if target=='Authors': 
    4752        #    request=doAuthorSearchRequest() 
     
    7479        if self.logger: itime=time.time() 
    7580        response=self.server.doSearch(request) 
    76         #try: 
    77         #if target=='All': 
    78         #    response=self.server.doFullTextSearch(request) 
    79         #elif target=='Authors': 
    80         #    response=self.server.doAuthorSearch(request) 
    81         #elif target=='Params': 
    82         #    response=self.server.doParameterSearch(request) 
    83         #else: 
    84         #    self.error=('Unknown search target type (%s)'%target,'programming error in backend') 
    85         #    return  
    86         #except Exception,e: 
    87         #   raise Exception,e 
    88            #self.error='Error: Unable to Carry Out Search','Internal error was (%s)'%e 
    89         #   return 
    9081             
    9182        if self.logger: 
     
    139130            etime=time.time()-itime 
    140131            self.logger.info('Document Load [n=%s] took [%ss]'%(len(self.documents._document),etime)) 
    141         self.docs=docs 
    142         return self.docs 
     132        #self.docs=docs 
     133        #return self.docs 
     134        #removed self.docs reference Jan 31st, can't see why we had it ... 
     135        #nb returning a complete copy of the list didn't fix the problems with repeated calls 
     136        return docs 
    143137             
    144138             
     
    178172        ''' Returns all the documents in sequence in a labelled list of strings''' 
    179173        if self.hits==0: return [] 
    180         filenames=self.documents.Document 
     174        #filenames=self.documents.Document 
     175        #so we know that the following call is the problem ... 
    181176        responses=self.getAllDocs(format) 
    182177        filenames=self.documents.Document 
     
    221216        output=s.getLabelledDocs() 
    222217        self.assertEqual(len(output),0) 
     218         
     219    def testSequence(self): 
     220        ''' Tests that repeated searches work and can support zero responses in the middle ''' 
     221        # this was a bug we found and needed a test case for 
     222        s=ndgSearch(tracefile=sys.stdout) 
     223        term='neodc' 
     224        r=s.search(term) 
     225        print s.hits 
     226        #if we uncomment this it breaks, if not it doesn't ... 
     227        #output=s.getLabelledDocs()  
     228        #this fails as well, and we've isolated the dependency in the previous call to 
     229        #be on this one: 
     230        res=s.getAllDocs() 
     231        #del(output) doesn't work ... 
     232        term='xpabnl' 
     233        r=s.search(term) 
     234        print s.hits 
     235        print 'Hopefully this is also zero: if not, expect the Sequence test to fail:',s.hits 
     236        #output=s.getLabelledDocs() 
     237        #self.assertEqual(len(output),0) 
     238         
    223239 
    224240if __name__=="__main__": 
Note: See TracChangeset for help on using the changeset viewer.