source: ndgCommon/trunk/ndg/common/unittests/clients/ws/testdiscoveryserviceclient.py @ 4991

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/ndgCommon/trunk/ndg/common/unittests/clients/ws/testdiscoveryserviceclient.py@4991
Revision 4991, 3.2 KB checked in by cbyrom, 11 years ago (diff)

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.

Line 
1import unittest, logging
2import ndg.common.unittests.testconstants as tc
3from ndg.common.src.models.ndgObject import ndgObject as no
4from ndg.common.src.clients.ws.discoveryserviceclient import DiscoveryServiceClient
5
6class TestCase(unittest.TestCase):
7   
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   
17    def testSearch(self):
18        ''' Test fundamental search capability - should return ten documents'''
19        term='temperature'
20        howmany=10
21        docs = self.client.search(term,start=1,howmany=howmany)
22        self.assertEqual(howmany,len(docs))
23       
24    def testgetLabelledDocs(self):
25        ''' Test returning of labelled documents '''
26        term='dppp'
27        r=self.client.search(term)
28        output=self.client.getLabelledDocs()
29        self.assertNotEqual(len(output), 0)
30       
31    def testNoReturn(self):
32        ''' Tests a search return with (hopefully nothing to be found)'''
33        r=self.client.search(self.INVALID_TERM)
34        self.assertEqual(self.client.hits,0)
35   
36    def testGetDoc(self):
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])
40        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       
53       
54    def testSequence(self):
55        ''' Tests that repeated searches work and can support zero responses in the middle '''
56        # this was a bug we found and needed a test case for
57        term='CD97' # hopefully just get a couple of hits for now.
58        r=self.client.search(term)
59        #if we uncomment this it used to break, and not if uncommented, now it seems ok...
60        output1=self.client.getLabelledDocs() 
61        r=self.client.search(self.INVALID_TERM)
62        self.assertEqual(self.client.hits,0)
63        term='CD97'
64        r=self.client.search(term)
65        self.assertEqual(self.client.getLabelledDocs(),output1)
66       
67    def testGet(self):
68        ''' Tests getting via uri components '''
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)
74       
75    def testFailedGet(self):
76        doc='abc'
77        try:
78            r=self.client.getDoc(doc)
79        except ValueError,e:
80            self.assertEqual(str(e),\
81                'Error during document retrieval: Document retrieval was successful but generated no results.')
82        except Exception,e:
83            self.fail(str(e))
84
85if __name__=="__main__":
86    unittest.main()
Note: See TracBrowser for help on using the repository browser.