Ignore:
Timestamp:
18/02/09 11:33:18 (11 years ago)
Author:
cbyrom
Message:

Move generic 'httpify' method to utilities + adjust utilities method
to retrive default proxy to cope with standard formatting + set this
up on each call to urlopen - since different urls may use different
proxies + tidyup and extend test suite.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ndgCommon/trunk/ndg/common/unittests/clients/ws/testdiscoveryserviceclient.py

    r4941 r4991  
    66class TestCase(unittest.TestCase): 
    77     
     8    # NB, for the tests to work, this search term needs to return some results 
     9    VALID_TERM = 'temperature' 
     10    INVALID_TERM = 'xpabnl_________DFDSF' 
     11    def setUp(self): 
     12        ''' 
     13        set up data used in the tests. 
     14        ''' 
     15        self.client = DiscoveryServiceClient() 
     16     
    817    def testSearch(self): 
    918        ''' Test fundamental search capability - should return ten documents''' 
    1019        term='temperature' 
    11         s=DiscoveryServiceClient() 
    1220        howmany=10 
    13         docs=s.search(term,start=1,howmany=howmany) 
     21        docs = self.client.search(term,start=1,howmany=howmany) 
    1422        self.assertEqual(howmany,len(docs)) 
    1523         
     
    1725        ''' Test returning of labelled documents ''' 
    1826        term='dppp' 
    19         s=DiscoveryServiceClient() 
    20         r=s.search(term) 
    21         output=s.getLabelledDocs() 
     27        r=self.client.search(term) 
     28        output=self.client.getLabelledDocs() 
    2229        self.assertNotEqual(len(output), 0) 
    2330         
    2431    def testNoReturn(self): 
    2532        ''' Tests a search return with (hopefully nothing to be found)''' 
    26         term='xpabnl' 
    27         s=DiscoveryServiceClient() 
    28         r=s.search(term) 
    29         self.assertEqual(s.hits,0) 
    30          
     33        r=self.client.search(self.INVALID_TERM) 
     34        self.assertEqual(self.client.hits,0) 
     35     
    3136    def testGetDoc(self): 
    32         ''' Test obtaining a specific document which had better exist ''' 
    33         doc= tc.VALID_DISCOVERY_PROVIDER_ID + "__" + no.DIF_DOC_TYPE + \ 
    34             "__" + tc.VALID_DISCOVERY_DOC_ID + ".xml" 
    35         s=DiscoveryServiceClient() 
    36         r=s.getDoc(doc) 
     37        ''' Test obtaining a specific document ''' 
     38        docs = self.client.search(self.VALID_TERM,start = 1,howmany = 1) 
     39        r=self.client.getDoc(docs[0]) 
    3740        self.assertNotEqual(r.find('<DIF'), -1) 
     41     
     42    def testGetDocs(self): 
     43        ''' Test obtaining specific documents ''' 
     44        docs = self.client.search(self.VALID_TERM,start = 1,howmany = 10) 
     45        r=self.client.getDocs(docs) 
     46        for key, val in r.items(): 
     47            self.assertNotEqual(val.find('<DIF'), -1) 
     48             
     49        self.assertTrue(r.keys() > 1) 
     50        docs = r.values() 
     51        self.assertNotEquals(docs[0], docs[1]) 
     52         
    3853         
    3954    def testSequence(self): 
    4055        ''' Tests that repeated searches work and can support zero responses in the middle ''' 
    4156        # this was a bug we found and needed a test case for 
    42         s=DiscoveryServiceClient() 
    4357        term='CD97' # hopefully just get a couple of hits for now. 
    44         r=s.search(term) 
     58        r=self.client.search(term) 
    4559        #if we uncomment this it used to break, and not if uncommented, now it seems ok... 
    46         output1=s.getLabelledDocs()  
    47         term='xpabnl' 
    48         r=s.search(term) 
    49         self.assertEqual(s.hits,0) 
     60        output1=self.client.getLabelledDocs()  
     61        r=self.client.search(self.INVALID_TERM) 
     62        self.assertEqual(self.client.hits,0) 
    5063        term='CD97' 
    51         r=s.search(term) 
    52         self.assertEqual(s.getLabelledDocs(),output1) 
     64        r=self.client.search(term) 
     65        self.assertEqual(self.client.getLabelledDocs(),output1) 
    5366         
    5467    def testGet(self): 
    5568        ''' Tests getting via uri components ''' 
    56          
    57         (r,s,l)=tc.VALID_DISCOVERY_PROVIDER_ID, \ 
    58             no.DIF_DOC_TYPE, tc.VALID_DISCOVERY_DOC_ID 
    59         ss=DiscoveryServiceClient() 
    60         x=ss.getNDGDoc(r,s,l,format='DC') 
    61         self.assertNotEqual(x.find('<oai_dc'), -1) 
     69        docs = self.client.search(self.VALID_TERM,start = 1,howmany = 1) 
     70        doc = docs[0].split('.xml')[0] 
     71        n = no(doc) 
     72        x=self.client.getNDGDoc(n.repository, n.schema, n.localID,format='DC') 
     73        self.assertTrue(x.find('<oai_dc') > -1) 
    6274         
    6375    def testFailedGet(self): 
    6476        doc='abc' 
    65         s=DiscoveryServiceClient() 
    6677        try: 
    67             r=s.getDoc(doc) 
     78            r=self.client.getDoc(doc) 
    6879        except ValueError,e: 
    6980            self.assertEqual(str(e),\ 
Note: See TracChangeset for help on using the changeset viewer.